Linux nftables使用示例
#!/usr/sbin/nft -f
define localaddr = {
0.0.0.0/8,
10.0.0.0/8,
127.0.0.0/8,
192.168.0.0/16,
169.254.0.0/16,
}
table ip nat {
chain prerouting {
type nat hook prerouting priority 0; policy accept;
ip daddr $localaddr return
ip protocol tcp redirect to :7892
}
}
iptables:
iptables -t nat -N proxy
iptables -t nat -A proxy -d 0.0.0.0/8 -j RETURN
iptables -t nat -A proxy -d 10.0.0.0/8 -j RETURN
iptables -t nat -A proxy -d 127.0.0.0/8 -j RETURN
iptables -t nat -A proxy -d 169.254.0.0/16 -j RETURN
iptables -t nat -A proxy -d 172.16.0.0/12 -j RETURN
iptables -t nat -A proxy -d 192.168.0.0/16 -j RETURN
iptables -t nat -A proxy -d 224.0.0.0/4 -j RETURN
iptables -t nat -A proxy -d 240.0.0.0/4 -j RETURN
iptables -t nat -A proxy -p tcp -j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p tcp -j proxy