|
1 2 3 4 5 |
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53 iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53 iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE |
openwrt 从22.03后,防火墙更新到FW4,luci界面没有了自定义规则的地方,经过参考官方文档,找到了自定义规则的方法,具体如下:(高手可以直接路过了)
1.用工具远程登录路由,修改防火墙配置文件:/etc/config/firewall
在最后一行加上:
|
1 2 3 4 5 |
config include option enabled 1 option type 'script' option path '/etc/firewall.user' option fw4_compatible 1 |
2.在etc目录下新建文件:firewall.user,这个文件里就是保存自定义规则的,但是需要注意的是,fw4使用的是nfttables命令,比如下面的命令是强制劫持局域网内客户机的dns到路由:
|
1 2 3 4 5 6 |
# IPv4 和 IPv6 DNS 端口 53 TCP/UDP 重定向(PREROUTING) nft add rule inet fw4 dstnat udp dport 53 counter redirect to :53 nft add rule inet fw4 dstnat tcp dport 53 counter redirect to :53 # 出口接口 eth0 的 POSTROUTING MASQUERADE nft add rule inet fw4 postrouting oifname "eth0" counter masquerade |
执行:
|
1 |
/etc/init.d/firewall restart |
文章评论