tags:

views:

1823

answers:

7

I'm using an Ubuntu 8.04 (x86_64) machine to connect to my employer's Cisco VPN. (The client didn't compile out of the box, but I found patches to update the client to compile on kernels released in the last two years.) This all works great, until my DHCP client decides to renew its lease and updates /etc/resolv.conf, replacing the VPN-specific name servers with my general network servers.

Is there a good way to prevent my DHCP client from updating /etc/resolv.conf while my VPN is active?

+5  A: 

If you are running without NetworkManager handling the connections, use the resolvconf package to act as an intermediary to programs tweaking /etc/resolv.conf: sudo apt-get install resolvconf

If you are using NetworkManager it will handle this for you, so get rid of the resolvconf package: sudo apt-get remove resolvconf

I found out about this when setting up vpnc on Ubuntu last week. A search for vpn resolv.conf on ubuntuforums.org has 250 results, many of which are very related!

Sean
A: 

I would advice following the advice from @Sean, but if that fails for whatever reason, it should be possible to configure dhclient to not request DNS servers in /etc/dhcp3/dhclient.conf

Douglas Leeder
A: 

vpnc seems to be doing the right thing for my employer's cisco concentrator. I jump on and off the vpn, and it seems to update everything smoothly.

JBB
+1  A: 

chattr +i /etc/resolv.conf should work. ( -i to undo )

But the better thing is to configure your dhclient.conf: https://calomel.org/dhclient.html Look at superceding domain-name-servers, and domain-name.

Also look at "send hostname;" If it works at your work place, you will have a cool hostname for your PC and not some weird name that DHCP servers assign.

Bash
+1  A: 

If you are using the Ubuntu default with NetworkManager, try removing the CiscoVPN client and use the NetworkManager vpnc plugin to connect to the Cisco VPN. This should avoid all problems, since NetworkManager then knows about your VPN connection.

TobiX
A: 

The DHCPclient daemon can be told not to update resolv.conf with a command line switch. (-r I think, depending on the client)

That's less dynamic, because you'd have to restart/reconfigure DHCP when you connect, but not too hard. Similarly, you could just stop the service, but you might lose your IP in the meantime, so I wouldn't really recommend that.

Alternatively, you could run the dhcpclient from within a cron job, adding the appropriate process checks.

davenpcj
A: 

This problem is much more noticeable on networks with low DHCP lease ages. There is a bug filed in Ubuntu's dhcp3 package launchpad:

https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/90681

Which includes this patch in the description:

--- /sbin/dhclient-script.orig 2007-03-08 19:19:56.000000000 +0000
+++ /sbin/dhclient-script 2007-03-08 19:19:46.000000000 +0000
@@ -13,6 +13,10 @@
 # The alias handling in here probably still sucks. -mdz

 make_resolv_conf() {
+ # don't overwrite resolv.conf at RENEW time, since a VPN/PPTP tunnel may
+ # have updated it with remote DNS servers
+ [ "$reason" = "RENEW" ] && return
+
     if [ -n "$new_domain_name" -o -n "$new_domain_name_servers" ]; then
         # Find out whether we are going to mount / rw
         exec 9>&0 </etc/fstab

This change to /sbin/dhcp-script stops DHCP client from overwriting /etc/resolv.conf when it renews its lease.