If you have more than one network interface, you have to designate one network interface as the default route. In order to set a default route persistently in Linux, you can do the following. I assume that there are two interfaces: eth0 & eth1, and that you wish to use eth0 as the default route. I also assume that you are not using Network Manager on your Linux.
Set a Default Route Permanently on CentOS, Fedora or RHEL
On a RedHat-based system, you can explicitly declare the default route using "DEFROUTE: yes". In addition, you should add "DEFROUTE: no" to all network interfaces, NOT used as the default route.
Set a Default Route Permanently on Ubuntu, Debian or Linux Mint
On a Debian-based system, you can set a permanent default route by leveraging post-up command in /etc/network/interfaces as follows.
auto eth0 iface eth1 inet dhcp post-up route add default via [gateway-ip-address] dev eth0 auto eth1 iface eth1 inet dhcp post-up route del default dev eth1
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!