Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How does ifconfig determine which network interface to use as the default when DHCP assigns a default route for each NIC? It seems like it's in a race-condition and I need to have a more reliable solution. Is there a setting in /etc/network/interfaces that could define the preferred gateway? I read about "metric" but that did not seem to function.

10.04 LTS Server with two NICs on a managed network. IP addresses are assigned via DHCP which I do not manage.

eth0 is assigned a private NAT address; eth1 is assigned a public IP.

share|improve this question

When you are setting up the subnet, use the routers option in dhcpd.conf

option routers;


subnet netmask {
  default-lease-time 600 max-lease-time 7200;
  option subnet-mask;
  option broadcast-address;
  option routers;
  option domain-name-servers,;
  option domain-name "";

If you don't have access to the DHCP server, you might be able to do this in the /etc/network/interfaces file. This is similar to how it would be set up statically, only using DHCP and specifying the gateway.

iface eth0 inet dhcp
share|improve this answer
I don't have access to the DHCP server. There's got to be a way to define the default route within the interfaces file. – DrumEater Jun 22 '12 at 21:40
Please update your question that you don't have access to the DHCP server. Also, try my addition to my answer, as I believe it will work but haven't tested it in a DHCP configuration. – tgm4883 Jun 22 '12 at 22:31
Thanks. I'll try that. – DrumEater Jun 23 '12 at 15:31
That seems to have worked. I left in one other line just to be sure there wasn't a competition between the two and intentionally switched the order of the primary and secondary NICs so that the one as default triggers last: # The secondary network interface auto eth1 iface eth1 inet dhcp up route del default gw ..**.254 # The primary network interface auto eth0 iface eth0 inet dhcp gateway 10.**.**.254 – DrumEater Jun 25 '12 at 16:17
Not sure why it's not indenting - I added four spaces... – DrumEater Jun 25 '12 at 16:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.