Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 03-22-2017, 10:20 AM   #1
LQ Newbie
Registered: Mar 2012
Posts: 6

Rep: Reputation: Disabled
Configure default route in interfaces file

Hi, as a relative newbie to Linux I am still getting to grips with configuring network. One question I have is how to force a specific interface on my server to always be the default route.

I am working with Ubuntu 12.04.2 (Precise). My server has 2 x on-board dual-port NICs. For arguments sake, call these eth0, eth1, eth2 and eth3.

I want my system to use device eth0 as the default route, always. I have noticed that on server reboot the default route will be different, i.e. on eth1, eth2 or eth3.

I can change this by manually adding new default route on eth0, then removing the other default route (on whichever interface).

For management purposes the default route needs to be on interface eth0 (network configuration).

My question is do I set this in the /etc/network/interfaces file at the end of the file, or at end of the stanza for eth0?

If I specify at end of the file, how do I know which of the other interfaces possibly has been allocated default route?

I presume the command to add at end of interfaces file would be:

up route add default via <gw_addr> dev eth0

A side question: why is it that Ubuntu (Linux) picks a different interface as the default route rather than going just for eth0?

Thanks, again apologies if, as a newbie, I am asking something that is obvious.


Old 03-22-2017, 04:00 PM   #2
Senior Member
Registered: Apr 2009
Posts: 1,838

Rep: Reputation: 160Reputation: 160
In /etc/network/interfaces, you can add a gateway statement to make default gateway permanent.

iface eth0 inet static
Old 03-24-2017, 07:11 PM   #3
LQ Newbie
Registered: Mar 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
I have solved this.

In the /etc/network;/interfaces file the three interfaces used, eth0, eth1 & eth2, all had GW defined, since each interface is on a different subnet. I did not realise that in effect what makes a route "default" is assigning it a GW, there should therefore only be the one GW defined.

My interface eth0 is the main management interface, so I left this with a GW defined. For the other two interfaces I added 'up route add ...' lines to add specific routes, thus no need for defining a GW for these interfaces.

Now all is OK, my eth0 is always the default route.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
DNS request route towards non default route HOW>???? netguy2000 Linux - Networking 3 06-01-2014 04:47 PM
Quagga default route not showing in kernel default route (netstat -nr) Valkyr1e Linux - Networking 3 08-03-2008 10:20 PM
iproute2 (ip route), pppoe and default route lorddoskias Linux - Networking 0 05-09-2007 12:04 PM
configure default route true_atlantis Fedora 1 11-07-2006 10:17 AM
Default route took 20s to display with 'route' command Akhran Linux - Newbie 3 11-04-2006 05:59 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:33 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration