1. 程式人生 > >iptables nat-讓linux做為路由器,實現區域網訪問外網

iptables nat-讓linux做為路由器,實現區域網訪問外網

這個東西必須學會,真他媽的搞死我了
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_forward
iptables -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