LAN桥下接入的客户端只能访问白名单中的地址。
dig 可根据域名或url查询出对应的多个IP地址。
make menuconfig
xxxxxxxxxx
Network --->
IP Addresses and Names --->
<*> bind-dig........................................ bind DNS excavation tool
关闭lan的转发功能,这样LAN下的客户端不能访问外网。
xxxxxxxxxx
uci set firewall.@forwarding[0].enabled='0'
uci commit firewall
service firewall restart
将url白名单存放到文件中
xxxxxxxxxx
root@OpenWrt:/tmp# cat /etc/allowlist.conf
www.baidu.com
baidu.com
执行如下命令将白名单加入到 blackhole set 中
xxxxxxxxxx
nft add set inet fw4 blackhole { type ipv4_addr \;}
for address in $(dig a -f /etc/allowlist.conf +short | grep -v '\.$'); do
nft add element inet fw4 blackhole {$address}
done
将该set 插入到 默认的fw4 下的 lan转发下
这样保证只有blackhole中的ip是允许从LAN转发到WAN的
xxxxxxxxxx
nft insert rule inet fw4 forward_lan ip daddr @blackhole accept
xxxxxxxxxx
nft list ruleset
该命令用于查看openwrt 设备下的所有防火墙配置规则
恢复lan的转发功能即可。
xxxxxxxxxx
uci set firewall.@forwarding[0].enabled='1'
uci commit firewall
service firewall restart