Linux 下用 Iptables 实现共享 ADSL 上网

服务器端,Debian Lenny,两张网卡,eth0 连接 ADSL,eth1 连接 客户端;客户端,Ubuntu 10.04。

服务器端设置:
1、sudo pppoeconf 设置 ADSL 连接
2、/etc/rc.local 添加:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o ppp0 -j MASQUERADE  
3、在 /etc/network/interfaces 中添加 eth1 设置后,此文件的整个内容像这样:
<code>
auto lo
iface lo inet loopback

auto dsl-provider
iface dsl-provider inet ppp
pre-up /sbin/ifconfig eth0 up # line maintained by pppoeconf
provider dsl-provider

auto eth0
iface eth0 inet manual

auto eth1
iface eth1 inet static
address 192.168.1.1
netmask 255.255.255.0
</code>

与: 标题: RedHat 8.0提供ADSL共享上网的解决办法[抄袭篇] http://www.linuxsir.org/bbs/showthread.php?s=&threadid=12515 上讲的不同,帖中的方法试过不行。主要区别是我这里第一块接 ADSL 的网卡不设IP,客户端的网关设为第二块不接 ADSL 的那块网卡。客户端的设置都类似。

4、重启服务器端
5、客户端设置
如:IP 设为 192.168.1.2
网关为: 192.168.1.1,是服务器端第二张网卡的 IP
DNS 设为当地 ISP 的 DNS 服务器
如我们这里的铁通,/etc/resolv.conf 的内容为:
nameserver 61.236.159.99
nameserver 211.98.112.168

todo:
有必要时弄懂 iptables 的详细用法