Ubuntu服务器,2个以太网设备,相同的网关 – 想通过1台设备强制上网stream量(或者至less让它工作!)

我有一个Ubuntu 10.04服务器与2个以太网设备,eth0和eth1。

  • eth0的静态IP为192.168.1.210
  • 如果192.168.1.211,eth1有一个静态IP

DHCP服务器(也作为Internet网关)位于192.168.1.1。

我现在遇到的问题是当我同时插入时,我可以通过SSH在内部连接到两个IP,但无法从服务器连接到Internet。 如果我拔掉其中一个设备(例如eth1),那么它工作,没问题。 (另外,当我运行sudo ifconfig eth1 down时,获得相同的结果)。

问题是如何configuration它,以使eth0和eth1都可以在同一个networking上运行,同时也允许上网? (我愿意通过单一设备强制执行所有的inetstream量,或者通过两者来实现,我很灵活)。

从我的谷歌search,似乎我可以有一个独特的(或不stream行)的问题,所以一直没能find解决办法。 这是人们通常不会做的事吗? 我想要使​​用两个以太网设备的原因是因为我想运行不同的本地stream量服务来分裂负载,可以这么说…

提前致谢。

UPDATE

/ etc / network / interfaces的内容:

 # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp # The secondary network interface #auto eth1 #iface eth1 inet dhcp 

(注意:上面,我注释了最后2行,因为我认为这是造成问题…但它没有解决)

netstat -rn

 Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.1.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 

更新2

我按照Kevin的build议对/ etc / network / interfaces文件进行了修改。 在显示文件内容和路由表之前,当我通过SSHlogin服务器时,我无法ping通外部服务器,所以这是我遇到的同样的问题,导致我发布这个问题。

更改文件后,我运行了/etc/init.d/networking restart。

/ etc / network / interfaces的内容:

 # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp address 192.168.1.210 netmask 255.255.255.0 gateway 192.168.1.1 # The secondary network interface auto eth1 iface eth1 inet dhcp address 192.168.1.211 netmask 255.255.255.0 

ifconfig输出

 eth0 Link encap:Ethernet HWaddr 78:2b:cb:4c:02:7f inet addr:192.168.1.210 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::7a2b:cbff:fe4c:27f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:6397 errors:0 dropped:0 overruns:0 frame:0 TX packets:683 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:538881 (538.8 KB) TX bytes:85597 (85.5 KB) Interrupt:36 Memory:da000000-da012800 eth1 Link encap:Ethernet HWaddr 78:2b:cb:4c:02:80 inet addr:192.168.1.211 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::7a2b:cbff:fe4c:280/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5799 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:484436 (484.4 KB) TX bytes:1184 (1.1 KB) Interrupt:48 Memory:dc000000-dc012800 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:635 errors:0 dropped:0 overruns:0 frame:0 TX packets:635 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:38154 (38.1 KB) TX bytes:38154 (38.1 KB) 

netstat -rn

 Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth1 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 

如果只有一个接口的所有stream量都可以使用,则只需在一个接口上设置默认网关设置…例如:

假设你想让stream量通过“eth0”:

 auto eth0 iface eth0 inet static address 192.168.1.210 netmask 255.255.255.0 gateway 192.168.1.1 auto eth1 iface eth1 inet static address 192.168.1.211 netmask 255.255.255.0 

注意在第二个接口上省略“网关”字段?

如果你不需要把这两个接口视为不同的话,那么更好的解决scheme就是将两个接口绑定在一起,然后拆分它们之间的负载: https : //help.ubuntu.com/community/UbuntuBonding

如果你需要保持目前的情况,请看这篇旧文章 – http://www.linuxjournal.com/article/7291

现在的命令可能会有所不同,但想法是一样的,基于源IP进行基于策略的路由。

我还不能评论,但我相信凯文的build议应该工作,但根据您的路由表,你仍然有两个条目,所以看来你没有重新启动后的networking更改。

这个问题不是唯一的。这是一个路由问题。

运行: route -n来显示你的路由表。

我的路由表是这样的:

 Destination Gateway Genmask Flags MSS Window irtt Iface 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0 

这是可以的,因为我只有一个默认网关(这是最后一行)但是你的路由表有两个默认网关是这样的:

 Destination Gateway Genmask Flags MSS Window irtt Iface 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0 0.0.0.0 10.0.2.1 0.0.0.0 UG 0 0 0 eth1 

所以,当你的服务器连接到互联网时,它使用这两个网关(两个互联网线)旋转。 这导致SSH服务器在/ var / log / secure中引发exception

 ssh_exchange_identification: read: Connection reset by peer 

解决方法是:删除1个默认网关。

 /sbin/route del default /sbin/route add default gw 192.168.1.1 dev eth0 

(更改IP匹配你的系统)祝你好运

这可能是网关的问题。 尝试添加一个新的网关:

路由添加默认gw 192.168.xx

并在静态networking上注释掉“网关”。