Modifying DHCP Settings on Debian and Ubuntu

Unix

09 Feb 2015

Modifying DHCP Settings on Debian and Ubuntu

Preston Garrison 0 Comments

There are times where I would like to DHCP interfaces but not have the default route set.  This is important if you are doing your own custom routing for IPs and don’t wish it to be overwritten.  To set Ubuntu and Debian to do this is pretty simple, add a file to /etc/dhcp/dhclient-enter-hooks.d/no-default-route with the following contents

case $reason in
  BOUND|RENEW|REBIND|REBOOT)
    export default_route=$new_routers
    unset new_routers

    ;;
esac

 

You can then place custom commands in the file /etc/dhcp/dhclient-exit-hooks.d/setup-routes

echo Setting up routes
#/sbin/route delete default

/bin/mount -o rw,remount /


echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf


/bin/mount -o ro,remount /


/sbin/ip route add 8.8.8.8 dev eth0 via ${default_route}
/sbin/ip route add 8.8.4.4 dev eth0 via ${default_route}
/sbin/ip route add 129.6.15.30 dev eth0 via ${default_route}
/sbin/ip route add 129.129.129.129 dev eth0 via ${default_route}

/usr/bin/rdate 129.6.15.30

 

 

 

 

Basically what I am doing is exporting the default route to a variable, and then using that variable to do my own custom routing.    In this case I am setting it so traffic to Google’s DNS servers are routed through the local network only.  I am then using a 3g modem for normal internet access.  I am also routing the ip 129.129.129.129 through the default internet connection, which could be my VPN network.

 

 

Preston Garrison