您的位置:首页 > 其它

iptables端口转发

2017-03-29 15:29 169 查看
一.启用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

#将[b]192.168.2.10数据返回时,将源ip改为[b]192.168.2.19[/b][/b]

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: