9

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.

Danatela
  • 13,243
  • 11
  • 45
  • 72
DrumEater
  • 191

1 Answers1

3

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

option routers 239.252.197.1;

From http://linux.die.net/man/8/dhcpd

subnet 239.252.197.0 netmask 255.255.255.0 {
  range 239.252.197.10 239.252.197.250;
  default-lease-time 600 max-lease-time 7200;
  option subnet-mask 255.255.255.0;
  option broadcast-address 239.252.197.255;
  option routers 239.252.197.1;
  option domain-name-servers 239.252.197.2, 239.252.197.3;
  option domain-name "isc.org";
}

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
    gateway 10.21.8.1
tgm4883
  • 7,912
  • 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
  • 1
    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