现在的位置: 首页 > 综合 > 正文

[Linux]CentOS下iptables设备双网卡的端口转发规则

2013年02月27日 ⁄ 综合 ⁄ 共 542字 ⁄ 字号 评论关闭

1. 两张网卡:

eth0 =》内网172.18.1.240

eth1=》外网211.139.169.X

目标机IP:172.18.1.X

2. 原理,外网IP的端口有连接进来=》转发到目标机上=》      回路:目标机=》转发到内网IP上

3. 在命令行下执行:

iptables -t nat -A PREROUTING -d 211.139.169.X -p tcp --dport 443 -j DNAT --to-destination 172.18.1.X:443
iptables -t nat -A POSTROUTING -d 172.18.1.X -p tcp --dport 443 -j SNAT --to 172.18.1.240

service iptables save
service iptables restart

4. 查看设置: iptables -t nat -L

5. 查看是否保存:vi /etc/sysconfig/iptables   .....OK了这里有,重启机器也会自动生效了!

注:如果有开防火墙的,要加:

iptables -A FORWARD -o eth0 -d 172.18.1.X -p tcp --dport 443 -j ACCEPT
iptables -A FORWARD -i eth0 -s 172.18.1.X -p tcp --sport 443 -j ACCEPT

抱歉!评论已关闭.