1、添加nat策略
此处将8080转到80端口,9000转到90
sudo iptables -t nat -I PREROUTING -p udp –dport 80 -j REDIRECT –to-ports 8080
sudo iptables -t nat -I PREROUTING -p udp –dport 90 -j REDIRECT –to-ports 9000
2、查看端口规则情况
sudo iptables -L -n -t nat –line-number
Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
1 REDIRECT 17 — 0.0.0.0/0 0.0.0.0/0 udp dpt:90 redir ports 9000
2 REDIRECT 17 — 0.0.0.0/0 0.0.0.0/0 udp dpt:80 redir ports 8080
Chain INPUT (policy ACCEPT)
num target prot opt source destination
3、删除策略
#删除PREROUTING的第二条已添加规则,这里2代表第几行规则
#PREROUTING 对应 Chain类型,上面2标黄部分
sudo iptables -D PREROUTING 2