我可以使用两个以太网卡同时连接到两个网络吗?


8

我的大楼中有一个使用10.10.19。* IP范围的LAN。另外,我在家中有一个ADSL连接,内部使用192.168.1。* IP范围。我也有两个以太网卡。

有什么方法可以同时访问两个网络?我需要一条规则,将所有10.10.19。*流量通过eth0路由,并将所有其他路由通过eth1。这可能吗?

我需要在Ubuntu 9.10和Windows 7上执行此操作。

Answers:


10

绝对有可能。您需要正确配置路由才能执行此操作。您希望默认路由通过eth1,因此路由表应如下所示:

$ /sbin/route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.10.19.0      *               255.255.255.0   U     0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth1
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth1

使用该route print命令,Windows看上去会有些相似(当然还有格式的变化)。

您可以route在任一平台上使用命令动态设置路由。我不确定您需要将哪个配置选项设置为默认配置(显然将另一个配置为非默认配置)...将使用该信息进行编辑。

编辑:如果您正在使用GNOME或KDE GUI网络管理器,请在eth1设备配置中查找“将此接口设置为默认值”选项。

如果您是/etc/network/interfaces手工配置的,请查看本HOWTO的示例。特别是,该up选项允许您在界面出现后运行命令。在您的情况下,您可能需要使用该命令在额外的默认路由上运行route-delete命令,或者如果两个接口都未将其自身设置为默认路由,则要运行route-add:

# example /etc/network/interfaces
# replace the IP addresses in the route-del and route-add commands below
# with those appropriate to your network

auto eth0
iface eth0 inet dhcp
    up route del default gw 10.10.19.1
    # runs a route-delete if dhcp adds a default gateway for this interface

auto eth1
iface eth1 inet dhcp
    up route add default gw 192.168.1.1
    # runs a route-add if dhcp neglects to add a default gateway for this interface

2

是的你可以。

如果为两个NIC都设置了正确的IP地址,则它们将负责通过正确的接口路由数据包。

您唯一需要做的就是为不直接进入10.10.19。*和192.168.1。*网络的数据包设置默认路由(可能是192.168.1。* ADS网络上的路由器)。

在Linux中:

$ sudo route add default gw 192.168.1.1

在Windows中:

使用控制面板设置默认路由。


1

只要两个网络都使用DHCP分发IP地址,并且其中只有一个尝试成为您的默认网关,这应该是JustWork(tm)。

如果两者都尝试作为默认网关并且都允许路由到整个Internet,则它也可能会起作用,尽管我猜测ADSL线路的重点是您希望外部Internet流量通过该网关而不是通过其余局域网共享的任何连接?

在您打算使用连接的网卡的情况下,可以在Ubuntu中运行以下命令并让我们知道输出:
sudo ifconfig
sudo route
这将告诉使用在您当前的安排中自动设置的地址和路由。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.