LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 865|回复: 1

iptables 配置共享上网问题

[复制链接]
发表于 2010-2-17 01:14:38 | 显示全部楼层 |阅读模式
家里有两台电脑组成的局域网,PC1通过adsl上网,另一台(PC2)想通过PC1共享其adsl,具体设置如下

PC1: eth1 的ip为172.16.20.19/24,通过eth1建立ADSL拨号后有ppp0为动态外网IP

PC2 的ip 172.16.20.13/24,网关设为172.16.20.19,DNS:202.106.0.20

已加载的iptables模块有
$ lsmod |grep -i ip
ipt_MASQUERADE          1098  0
iptable_nat             2734  0
nf_nat                 10359  2 ipt_MASQUERADE,iptable_nat
nf_conntrack_ipv4       7323  3 iptable_nat,nf_nat
nf_defrag_ipv4           791  1 nf_conntrack_ipv4
iptable_filter          1002  0
ipt_addrtype            1349  0
xt_multiport            1799  0
ip_tables               7273  2 iptable_nat,iptable_filter
ipv6                  178229  16
ipw2100                53030  0
libipw                 18539  1 ipw2100



$ cat /proc/sys/net/ipv4/ip_forward
1
$ cat /proc/sys/net/ipv4/ip_dynaddr
1


我想将所有PC2的网络请求全通过PC1的ppp0实现:

iptables -t nat -A POSTROUTING -s 172.16.20.13/24 -o ppp0 -j SNAT --to 172.16.20.19

此命令试了不行,是不是我写的不对?
 楼主| 发表于 2010-2-17 03:40:43 | 显示全部楼层
google了,终于搞定了
iptables -t nat -A POSTROUTING -o ppp0 -s 172.16.20.13/24 -j MASQUERADE

这个不错:
http://www.linux.gov.cn/netweb/iptables.htm
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表