网站服务端:
iptables –F
iptables –F –t nat //清空filter表和nat表
service httpd start
网关:
vim /etc/sysctl.conf

Kernel sysctl configuration file for Red Hat Linux

#

For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and

sysctl.conf(5) for more details.

Controls IP packet forwarding

net.ipv4.ip_forward = 1 //开启路由转发功能

Controls source route verification

net.ipv4.conf.default.rp_filter = 1
SNAT和DNAT的配置_第1张图片
iptables –F
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -j SNAT --to-source 12.0.0.1
//将内部局域网IP地址段转换为全局IP地址
SNAT配置完成
服务端验证转换是否生效
cd /etc/httpd/logs
cat access_log
SNAT和DNAT的配置
网关服务器做DNAT:
iptables -t nat -A PREROUTING -d 12.0.0.1 -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.100.10
//允许公网服务器通过网关12.0.0.1访问内部网络192.168.100.10的网站
SNAT和DNAT的配置_第2张图片