需求外网访问内网的WEB服务器
我的测试环境:VMware workstation + 2台 Ubuntu 12.04.5 LTS 版本的。
转发外网服务器2个网卡一个192.168.31.206,一个10.10.100.52 )
内网服务器:10.10.100.51
转发服务器配置
iptables -t nat -A PREROUTING -d 192.168.31.206 -p tcp --dport 80 -j DNAT --to-destination 10.10.100.51:80
iptables -t nat -A OUTPUT -d 192.168.31.206 -p tcp --dport 80 -j DNAT --to-destination 10.10.100.51:80//本机访问需要添加OUTPUT
iptables -t nat -A POSTROUTING -j MASQUERADE
//查看规则
root@ubuntu:/home/hu# iptables -t nat --list --lin
Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
1 DNAT tcp -- anywhere 192.168.31.206 tcp dpt:http to:10.10.100.51:80
Chain INPUT (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
1 DNAT tcp -- anywhere 192.168.31.206 tcp dpt:http to:10.10.100.51:80
Chain POSTROUTING (policy ACCEPT)
num target prot opt source destination
1 MASQUERADE all -- anywhere anywhere
//删除规则
iptables -t nat -D PREROUTING 1 //序号从1 开始,后边以此+1.