DHCP connection does not set default gateway automatically

20,604

Solution 1

I'm experiencing the same issue on Ubuntu Server 16.04. After troubleshooting, my issue stems from my DHCP server also providing a Classless Static Route (DHCP option 121, rfc3442-classless-static-routes in ISC DHCP), from a Microsoft DHCP server (Windows Server 2008 R2).

Looking at /sbin/dhclient-script, if at least one classless static route is provided to the DHCP client, it disregards the router setting, hence no default route set.

# if we have $new_rfc3442_classless_static_routes then we have to
# ignore $new_routers entirely

My "fix" is to add another classless static route to the Windows DHCP server. So:

  • Destination: 0.0.0.0
  • Network Mask: 0.0.0.0
  • Router: 192.168.1.1

(once added, the Network Mask is automagically changed to 255.255.255.255)

I do have short DHCP lease expiry (15 minutes) and have not had any complaints from other Linux or Windows users on the network since adding the new route, so I figure the change should not cause major issues.

As I'm too new to comment:

  • @t11z My lease file is /var/lib/dhcp/dhclient.ens32.leases, option routers is present and valid.
  • @Jos Although a workaround, your suggestion defeats the purpose of utilizing DHCP to provision network settings. If the default gateway IP address changes in the future, affected machines will need to be updated manually.

Solution 2

I am configuring a Raspberry Pi as a router and ran into the same problem. I fixed it by editing the file /etc/dhcpcd.conf.

Open the file and look for the line:

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes

I simply commented out "option classless_static_routes"

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
# option classless_static_routes

I am now getting an automatic default route set by the DHCP server.

A similar thing could be attempted with dhclient by editing the file /etc/dhcp/dhclient.conf and looking for this line:

request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        dhcp6.name-servers, dhcp6.domain-search,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;

and removing the request for rfc3442-classless-static-routes.

Share:
20,604

Related videos on Youtube

Jon Smark
Author by

Jon Smark

Updated on September 18, 2022

Comments

  • Jon Smark
    Jon Smark over 1 year

    I just did a fresh install of Ubuntu 16.04 (Xenial). I've configured /etc/network/interfaces to bring up the wlan interface automatically using DHCP:

    auto lo
    iface lo inet loopback
    
    auto wlp2s0
    iface wlp2s0 inet dhcp
      wpa-ssid SSID
      wpa-psk "password"
    

    This sort of works: the IP is configured normally, but the default gateway is not set. After boot I always have to run route add default gw 192.168.1.1 manually. Any idea of what can possibly be wrong? I could swear this setup used to work fine on older versions...

    • t11z
      t11z about 8 years
      Are you sure that you're receiving default gateway configuration from your DHCP server? Could you please post the output of ifconfig -a and grep "option routers" /var/lib/NetworkManager/*? Thank you
    • Jos
      Jos about 8 years
      Why not add simply add "gateway 192.168.1.1" ?
  • PLN
    PLN almost 6 years
    I had the same issue with specific static routes. I just commented out the if statement in the script that made it ignore the router setting, and now it's all working fine, both the router and the routes.
  • ivanivan
    ivanivan over 5 years
    Unless of course, you need the classless-static-routes too...
  • konairius
    konairius over 4 years
    I had the same problem, adding the "default" route via "0.0.0.0" works. Does anyone know why this is neccecary?
  • Luc VdV
    Luc VdV over 4 years
    Fixed for me, here a Raspberry image too, but one that is used in several networks including some where I have no access to the DHCP settings. Too bad I can't have the classless static routes anymore, but that's less of a problem than losing all external access.