内网环境:
PC-A: 192.168.56.101
iptables主机:
eth0 : 10.0.86.100 (外网网卡)
eth1 ; 192.168.56.100 (内网网卡)
net.ipv4.ip_forward 更改为 1
方法1(重启失效):sysctl -w net.ipv4.ip_forward=1
方法2:修改/etc/sysctl.conf文件中的对应项
然后sysctl -p生效
2.
iptables设定:
iptables -t nat -A POSTROUTING -s 192.168.56.0/24 -j SNAT --to-source 10.0.86.100
iptables -A FORWARD -s 192.168.56.0/24 -j ACCEPT
iptables -A FORWARD -d 192.168.56.0/24 -j ACCEPT
3. 此时即可使用PC-A访问外网的IP地址了,若是访问域名,需要在内网机器指定DNS
本文出自 “三十男人学运维” 博客,请务必保留此出处http://loyfee.blog.51cto.com/754862/1707805
原文:http://loyfee.blog.51cto.com/754862/1707805