LinuxSir.cn,穿越时空的Linuxsir!

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

(郁闷死 )双网卡共享上网问题

[复制链接]
发表于 2006-4-23 22:57:57 | 显示全部楼层 |阅读模式
一台式机装 debian,  在一局域网内,我的笔记本通过这台式机上网(没有 hub)。
台式机装双网卡,eth1与局域网内其它pc通信以及上 internet.
                        eth0 与我的笔记本相连。
台式机interfaces
auto lo eth0 eth1

iface lo inet loopback

iface eth0 inet static
        address 192.168.0.1
        netmask 255.255.255.0
        broadcast 192.168.0.255

iface eth1 inet static
        address 192.168.221.6
        netmask 255.255.255.0
        broadcast 192.168.221.255
        gateway 192.168.xxx.xxx
笔记本interfaces
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.3
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1

台式机的 route table
debian:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0
192.168.221.0   *               255.255.255.0   U     0      0        0 eth1
default         192.168.221.47  0.0.0.0         UG    0      0        0 eth1

笔记本的 route table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth0

台式机打开ip转发功能
/etc/network/options
ip_forward=yes
spoofprotect=yes
syncookies=yes

台式机NAT
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE


现在的情况是 笔记本可以与台式机的两个网卡相互ping通。台式机可以上网,但是笔记本却不能上网。我为这个问题花了两天的时间还是没搞定,郁闷死!!!!!!
台式机的 iptables
debian:~# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
发表于 2006-4-24 00:09:28 | 显示全部楼层
你应该在台机上做封包伪装吧,应该加几条iptable的规则
/sbin/iptables -t nat -P PREROUTING  ACCEPT
/sbin/iptables -t nat -P POSTROUTING ACCEPT
/sbin/iptables -t nat -P OUTPUT      ACCEPT
/sbin/iptables -t nat -A POSTROUTING -o eth1 -s 192.168.0.0/24 -j MASQUERADE
我想是这样。你试试吧
回复 支持 反对

使用道具 举报

发表于 2006-4-24 00:21:51 | 显示全部楼层
on notebook:
ping (your desktop's gateway)

maybe you should check your notebook's DNS(/etc/resolv.conf)

and you must check your desktop's /proc/sys/net/ipv4/ip_forward(use cat)
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-4-24 11:25:32 | 显示全部楼层
感谢两位高人相助,我试试看
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-4-24 17:28:39 | 显示全部楼层
wanglu624: with your method, I still can not connect to the internet.

springwind426: my notebook dns: 192.168.0.1 I can ping the desktop's gateway and the two interfaces(eth0, eth1) and then the name servers.

I still can not connetct to the internet.  Anyone can help me?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-4-24 17:41:23 | 显示全部楼层
using IP instead of the web site name
#wget 218.75.110.195
Connetcing to  218.75.110.195:80...connected.
HTTP request sent, awaiting response... 403 Forbidden.

What's the matter?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-4-24 19:42:15 | 显示全部楼层
刚才在 debian下没有装中文字体,用windowxp作gateway是可以上网的。在debian下怎么这么麻烦?笔记本 ping 主机的gateway也是ping通的。
主机的/proc/sys/net/ipv4/ip_forward 为1
回复 支持 反对

使用道具 举报

发表于 2006-4-24 23:11:15 | 显示全部楼层
lsmod一下,看看你下面几个module有没有加载?
ip_tables主模块
ip_conntrack
iptable_nat实现nat功能
ipt_MASQUERADE实现ip伪装
没加载的话,加载!再设置iptables的规则,应该没有问题的!
回复 支持 反对

使用道具 举报

发表于 2006-4-25 13:25:25 | 显示全部楼层
应该是DNS的问题,
用winxp的ICS的话可以把网内机子的DNS设为网关IP,好像windows会自动的代理DNS。
你根据台式机的DNS把笔记本的DNS设一下试试。

在笔记本上先
nslookup
ping www.baidu.com
traceroute www.baidu.com
慢慢确定一下原因。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-4-25 14:39:08 | 显示全部楼层
已经搞定!
感谢guoke,正是DNS的问题。我将笔记本的DNS设置成台式机DNS就可以了,可能是IP转发只是改了 source ip。数据包里没有dns nameserver 的信息?
也感谢wanglu624。
回复 支持 反对

使用道具 举报

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

本版积分规则

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