多 Gateway 設定

首先假設我們目前的網路配置如下: /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 192.168.0.10
  netmask 255.255.255.0
  gateway 192.168.0.1

# The secondary network interface
allow-hotplug eth1
iface eth1 inet static
  address 10.10.0.10
  netmask 255.255.255.0

修改  /etc/iproute2/rt_tables

#
# reserved values
#
255     local
254     main
253     default
0       unspec
#
# local
#
#1      inr.ruhep
1 rt2 #此為新增的 route table 2

手動加入路由表:

ip route add 10.10.0.0/24 dev eth1 src 10.10.0.10 table rt2
ip route add default via 10.10.0.1 dev eth1 table rt2

加入路由規則:

ip rule add from 10.10.0.10/32 table rt2
ip rule add to 10.10.0.10/32 table rt2

修改 /etc/network/interfaces 中的 eth1 設定(開機可自動設定)

[...]
iface eth1 inet static
  address 10.10.0.10
  netmask 255.255.255.0
  post-up ip route add 10.10.0.0/24 dev eth1 src 10.10.0.10 table rt2
  post-up ip route add default via 10.10.0.1 dev eth1 table rt2
  post-up ip rule add from 10.10.0.10/32 table rt2
  post-up ip rule add to 10.10.0.10/32 table rt2
[...]

查看設定結果

ip route list table rt2
ip rule show

參考來源:

https://www.thomas-krenn.com/en/wiki/Two_Default_Gateways_on_One_System