iptables端口转发

一.启用iptables端口转发
#vi /etc/sysctl.conf
net.ipv4.ip_forward = 1

立即生效

#sysctl -p

二.配置
1.将ip 192.168.2.10的访问192.168.2.19 的 80端口时,重定向到192.168.2.10的9000端口
iptables -t nat -I PREROUTING -p tcp -d 192.168.2.19 --dport 80 -s 192.168.2.10 -j DNAT --to-destination 192.168.2.10:9000

#如果是是不同主机还需要增加

iptables -t nat -A POSTROUTING -j MASQUERADE

 

#将192.168.2.10数据返回时,将源ip改为192.168.2.19

iptables -t nat -A POSTROUTING -d 192.168.2.10 -p tcp --dport 80 -j SNAT --to-source 192.168.2.19

2.查看nat配置
iptables -t nat -vnL --line-number

3.删除nat规则
iptables -t nat -D POSTROUTING 1
iptables -t nat -D PREROUTING 1

posted @ 2017-03-29 15:29  rorshach  阅读(294)  评论(0编辑  收藏  举报