Linux:三个默认的网关?

我的服务器有三个默认的网关,那怎么可能? 不应该有一个默认的gw?

我有三个NIC,每个连接到一个单独的子网:

server1:~# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.5.0.0 * 255.255.255.224 U 0 0 0 eth3 localnet * 255.255.255.224 U 0 0 0 eth0 192.168.8.0 * 255.255.255.192 U 0 0 0 eth1 default 10.5.0.1 0.0.0.0 UG 0 0 0 eth3 default 192.168.8.1 0.0.0.0 UG 0 0 0 eth1 default 10.1.0.1 0.0.0.0 UG 0 0 0 eth0 

有时候,我无法在互联网上ping主机,有时候我可以。 我想要的是通过特定的NIC路由到Internet(0.0.0.0)的stream量。 我可以只添加0.0.0.0的路由和默认的gw到eth0-3接口之一吗? 它会打破我的联系?

我使用的是Debian,这里是我的/ etc / network / interfaces:

 # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 iface eth0 inet static address 10.1.0.4 netmask 255.255.255.224 network 10.1.0.0 broadcast 10.1.0.31 gateway 10.1.0.1 allow-hotplug eth1 iface eth1 inet static address 192.168.8.4 netmask 255.255.255.192 network 192.168.8.0 broadcast 192.168.8.63 gateway 192.168.8.1 allow-hotplug eth3 iface eth3 inet static address 10.5.0.4 netmask 255.255.255.224 network 10.5.0.0 broadcast 10.5.0.31 gateway 10.5.0.1 

从技术上讲,你可以拥有尽可能多的默认网关,但是默认情况下它没有什么意义,因为你的stream量的方式会有些不可预测。 如果使用策略路由,有多个网关是有意义的; 例如,如果连接到两个不同的提供程序,并且希望服务器在与该主机使用的相同接口上答复每个远程主机,则可以使用iproute2软件包以multi-default-网关环境。

如果你想拥有一个默认的网关,只需从/ etc / network / interfaces中的所有接口中删除“gateway”语句,除了你的默认网关所在的一个接口。 当然,重启。

您在接口文件上configuration了所有网关。 只留下你真正需要的网关。

Linux支持多个网关,但取决于你想要做什么。

  1. 您可以select在每个gw上configuration不同的度量标准,它将像故障转移一样工作
  2. 您可以使用基于iproute2和内核策略路由的源路由
  3. 您可以使用BGP来平衡您的stream量。

这是你的select,但是如果你只需要1 gw,那么从你的interfaces文件中删除其他2(删除网关xxx.yyy.zzzz.wwww开始的行,只留下你需要的网关)。

取决于有多less这些网关实际连接到互联网,你可能需要2个甚至更多的“默认”网关。

select优先级的关键是“度量”参数。

Eli Rosencruft on unix.SE描述了这个过程以及如何将它包含在接口文件中。

重要部分:

 iface eth0 inet static ... post-up route add default gw 192.168.1.1 metric 1 pre-down route del default gw 192.168.1.1 iface eth1 inet static ... post-up route add default gw 192.168.2.1 metric 2 pre-down route del default gw 192.168.2.1 

所以一旦你的网关连接下降(无论什么原因),它将切换到另一个。

显然你可以改变至less一些stream量,通过你select的界面进行路由,即使没有设置一个指标,你应该检查程序的手册页,你是如何做到这一点。