iptables nat-让linux做为路由器,实现局域网访问外网

来源:互联网 发布:c windows syswow32 编辑:程序博客网 时间:2024/05/16 16:06
这个东西必须学会,真他妈的搞死我了
2013.5.15
1. 环境:
ubuntu pc一台,两个网卡:
eth0:
   ip 10.3.1.100
   gateway 10.3.1.12
  dns 10.3.1.2
eth1:
  ip 192.168.1.3


windows pc一台,
ip 192.168.1.4
 
2. ubuntu pc的eth0可以访问外网,eth1与windows pc相连。
可以设置ubuntu pc:
  

echo 1 > /proc/sys/net/ipv4/ip_forwardiptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 10.3.1.100

设置windows pc:
  ip 192.168.1.4
  gateway 192.168.1.3
  dns 10.3.1.2
这样,windows就可以上外网了
2013.5.15