Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
| docs:guide-user:firewall:fw3_configurations:dns_ipset [2022/10/27 19:25] – [Introduction] fw3>fw4 update vgaetera | docs:guide-user:firewall:fw3_configurations:dns_ipset [2023/10/15 06:58] – update vgaetera | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Filtering traffic with IP sets by DNS ====== | ====== Filtering traffic with IP sets by DNS ====== | ||
| - | {{section> | + | {{section> |
| ===== Introduction ===== | ===== Introduction ===== | ||
| Line 31: | Line 31: | ||
| for IPV in 4 6 | for IPV in 4 6 | ||
| do | do | ||
| - | uci -q delete firewall.filter${IPV/4}_fwd | + | uci -q delete firewall.fwd_filter${IPV%4} |
| - | uci set firewall.filter${IPV/4}_fwd=" | + | uci set firewall.fwd_filter${IPV%4}=" |
| - | uci set firewall.filter${IPV/4}_fwd.name=" | + | uci set firewall.fwd_filter${IPV%4}.name=" |
| - | uci set firewall.filter${IPV/4}_fwd.src=" | + | uci set firewall.fwd_filter${IPV%4}.src=" |
| - | uci set firewall.filter${IPV/4}_fwd.dest=" | + | uci set firewall.fwd_filter${IPV%4}.dest=" |
| - | uci set firewall.filter${IPV/4}_fwd.proto=" | + | uci set firewall.fwd_filter${IPV%4}.proto=" |
| - | uci set firewall.filter${IPV/4}_fwd.family=" | + | uci set firewall.fwd_filter${IPV%4}.family=" |
| - | uci set firewall.filter${IPV/4}_fwd.ipset=" | + | uci set firewall.fwd_filter${IPV%4}.ipset=" |
| - | uci set firewall.filter${IPV/4}_fwd.target=" | + | uci set firewall.fwd_filter${IPV%4}.target=" |
| done | done | ||
| uci commit firewall | uci commit firewall | ||
| - | / | ||
| # Populate IP sets | # Populate IP sets | ||
| Line 57: | Line 56: | ||
| <code bash> | <code bash> | ||
| # Restart services | # Restart services | ||
| - | / | + | service |
| - | / | + | |
| - | + | ||
| - | # Log and status | + | |
| - | logread -e dnsmasq; netstat -l -n -p | grep -e dnsmasq | + | |
| # Runtime configuration | # Runtime configuration | ||
| - | pgrep -f -a dnsmasq | ||
| nft list ruleset | nft list ruleset | ||
| # Persistent configuration | # Persistent configuration | ||
| - | uci show firewall; | + | uci show firewall; |
| </ | </ | ||
| Line 76: | Line 70: | ||
| * Navigate to **LuCI -> Network -> Firewall -> Traffic Rules -> Filter-IPset-DNS-Forward** to manage firewall rules. | * Navigate to **LuCI -> Network -> Firewall -> Traffic Rules -> Filter-IPset-DNS-Forward** to manage firewall rules. | ||
| * Navigate to **LuCI -> Network -> DHCP and DNS -> IP sets** to manage domains. | * Navigate to **LuCI -> Network -> DHCP and DNS -> IP sets** to manage domains. | ||
| + | Reboot the router to apply the changes. | ||
| - | ==== Examples | + | ==== Manage domains |
| Add/remove domains to/from the filtering list. | Add/remove domains to/from the filtering list. | ||
| <code bash> | <code bash> | ||
| # Add domains | # Add domains | ||
| - | uci add_list dhcp.filter.domain=" | + | uci add_list dhcp.filter.domain=" |
| - | uci commit | + | uci add_list |
| # Remove domains | # Remove domains | ||
| - | uci del_list dhcp.filter.domain=" | + | uci del_list dhcp.filter.domain=" |
| + | uci del_list dhcp.filter.domain=" | ||
| + | |||
| + | # Save and apply | ||
| uci commit dhcp | uci commit dhcp | ||
| - | |||
| - | # Populate IP sets | ||
| ipset setup | ipset setup | ||
| </ | </ | ||
| Line 100: | Line 96: | ||
| for IPV in 4 6 | for IPV in 4 6 | ||
| do | do | ||
| - | uci add_list firewall.filter${IPV/4}_fwd.src_mac=" | + | uci add_list firewall.fwd_filter${IPV%4}.src_mac=" |
| - | uci add_list firewall.filter${IPV/4}_fwd.src_mac=" | + | uci add_list firewall.fwd_filter${IPV%4}.src_mac=" |
| done | done | ||
| uci commit firewall | uci commit firewall | ||
| - | / | + | service |
| </ | </ | ||
| Line 115: | Line 111: | ||
| for IPV in 4 6 | for IPV in 4 6 | ||
| do | do | ||
| - | uci set firewall.filter${IPV/4}_fwd.start_time=" | + | uci set firewall.fwd_filter${IPV%4}.start_time=" |
| - | uci set firewall.filter${IPV/4}_fwd.stop_time=" | + | uci set firewall.fwd_filter${IPV%4}.stop_time=" |
| - | uci set firewall.filter${IPV/4}_fwd.weekdays=" | + | uci set firewall.fwd_filter${IPV%4}.weekdays=" |
| done | done | ||
| uci commit firewall | uci commit firewall | ||
| - | / | + | service |
| </ | </ | ||
| Line 128: | Line 124: | ||
| <code bash> | <code bash> | ||
| # Reorder firewall rules | # Reorder firewall rules | ||
| - | cat << " | + | cat << " |
| - | nft list chain inet fw4 forward \ | + | ER_RULE=" |
| - | | sed -e "/ | + | | sed -n -e "/ |
| - | 1i flush chain inet fw4 forward | + | RJ_RULE=" |
| - | / | + | | sed -n -e "/\shandle_reject\s/ |
| - | $(nft list chain inet fw4 forward \ | + | nft delete rule inet fw4 forward handle ${ER_RULE## |
| - | | sed -n -e "/\sestablished, | + | nft insert rule inet fw4 forward position ${RJ_RULE## |
| - | | nft -f - | + | |
| - | EOF | + | |
| - | cat << " | + | |
| - | / | + | |
| EOF | EOF | ||
| uci -q delete firewall.estab | uci -q delete firewall.estab | ||
| uci set firewall.estab=" | uci set firewall.estab=" | ||
| - | uci set firewall.estab.path="/ | + | uci set firewall.estab.path="/ |
| uci commit firewall | uci commit firewall | ||
| - | / | + | service |
| </ | </ | ||