7

I have ubuntu 12.04 and I have configured /etc/network/interfaces like this

auto eth2
iface eth2 inet dhcp

I also have

auto eth1
iface eth1 inet static
        address 60.60.60.1 
        netmask 255.255.255.0
        network 60.60.60.0
        broadcast 60.60.60.255 

and eth0 is similarly configured.

When I do sudo route I don't see default gw. I just see 60.60.60.0 * 255.255.255.0 eth1 and similarly

10.0.0.0  *   255.255.255.0   U     0      0        0 eth2

Since the default gw is not present, I have got a proper 10.x.x.x IP address but no way to connect outside . How do I get the default gw automatically setup. I can add it using route add default gw and that works. But when I move locations, then I will have to keep on setting route add at every place manually

roadmr
  • 34,862
  • 9
  • 84
  • 94
doon
  • 221
  • 1
    Look at /var/lib/dhcp/dhclient.eth2.leases, check that there's an option routers setting there. This is what the dhclient received from the DHCP server. If there's no option routers, it means the DHCP server is not sending the default gateway or router setting. – roadmr Sep 10 '14 at 15:33

2 Answers2

5

I found the answer from this link https://serverfault.com/questions/527383/change-default-route-to-dhcp-interface-without-a-route-push I essentially set "post-up route del default dev eth2" and for any other interface on which I did not want the default gw (these were all addresses with static configuration). after doing /etc/init.d/networking restart , ubuntu will automatically pick up the default gw to the dhcp server and that worked. It took me 3+ hours of searching to find this :-)

doon
  • 221
2

Basically dhclient appears to only set the default gateway when routers are provided by the server and when a current default gateway is not set. so, as doon mentioned, you can add a "route del default gw" to your network configuration or you can do this manually (or in your own script) before dhclient is called.

gesell
  • 131