How to Set Default Route Interface when there are multiple Interfaces in CentOS

Consider the following situation, you have two interfaces in your system, eth0, and eth1 (or more). Both the interfaces have a default gateway. But how can you choose which interface to follow as the default outbound requests by the server? This could be a situation like adding secondary alias IP addresses to an interface (Like eth0, eth0:0, eth0:1, eth0:2, etc).

In these cases, Linux can decide based on its own algorithm. The problem with this is in the case of Licensing. In most licensing systems these days, you need to provide an outbound IP address to your server. If this IP changes over time, you would have trouble managing the license. For these cases, you need to define your default interface to Linux.

You may set this configuration under /etc/sysconfig/network file. The ‘key’ for the settings is ‘GATEWAYDEV’.

So for example if your gatewaydev would be eth0:1, the file would look like something following:

NETWORKING=yes
HOSTNAME=hemonto.ethii.com
DOMAINNAME=ethii.com
GATEWAYDEV=eth0:1

or if it is eth1, the following:

NETWORKING=yes
HOSTNAME=hemonto.ethii.com
DOMAINNAME=ethii.com
GATEWAYDEV=eth1

I Hope, this helps somebody. Good luck

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.