How to Specify Default Device on Node with Multiple Interfaces


#1

Synopsis:

How to specify default gateway device if multiple interfaces are configured.

On Centos:

  • In order to set any specific device to be the default gateway device in the system, add following option in /etc/sysconfig/network: file: GATEWAYDEV=ethX

Note:

  • If a system has more than one interface, then the last interface which is being brought up will become the default gateway device. This is a designed behavior in RHEL initscripts.

On Ubuntu:

Modify metric value dynamically:

route add default dev eth0 metric 20

Increasing metric value of to say 20 will make it the least favorable interface to use by default.

Change can be made persistent by modifying /etc/network/interfaces

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
network xxx.xxx.xxx.xxx
broadcast xxx.xxx.xxx.xxx
metric XXX

a less friendly option is to modify default gateways

Point default gateway to interface:

ip route add -net 0.0.0.0/0 gw Gateway_IP dev eth0:1