1.添加一个端口映射
将80端口映射到8088端口命令如下:
iptables -t nat -I PREROUTING -p tcp --dport 80-j REDIRECT --to-port 8088
这个不行,用下面的
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8082
2.查询规则命令
[root@mylinux~]# iptables -t nat -L -nv --line-numbers
Chain PREROUTING (policy ACCEPT 1 packets, 40 bytes)
num pkts bytes target prot opt in out source destination
1 6 312 REDIRECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 redir ports 8082
Chain INPUT (policy ACCEPT 7 packets, 352 bytes)
num pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 9 packets, 540 bytes)
num pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 9 packets, 540 bytes)
num pkts bytes target prot opt in out source destination
3.如何删除规则
首先读出num,这里为1(参考2)
iptables -t nat -D PREROUTING 1
参考网址:http://blog.csdn.net/readiay/article/details/45460055