<p>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 <a href="http://projects.tuxx-home.at/?id=cisco_vpn_client" rel="nofollow noreferrer">patches to update the client to compile on kernels released in the last two years</a>.) 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.</p>

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

[{'answer_id': 48130, 'author': 'Sean', 'author_id': 4919, 'author_profile': 'https://Stackoverflow.com/users/4919', 'pm_score': 3, 'selected': False, 'text': '<p>If you are running without NetworkManager handling the connections, use the resolvconf package to act as an intermediary to programs tweaking /etc/resolv.conf: <strong><code>sudo apt-get install resolvconf</code></strong></p>\n\n<p>If you are using NetworkManager it will handle this for you, so get rid of the resolvconf package: <strong><code>sudo apt-get remove resolvconf</code></strong></p>\n\n<p>I found out about this when setting up vpnc on Ubuntu last week. A search for <strong><code>vpn resolv.conf</code></strong> on ubuntuforums.org has 250 results, many of which are very related!</p>\n'}, {'answer_id': 48707, 'author': 'Douglas Leeder', 'author_id': 3978, 'author_profile': 'https://Stackoverflow.com/users/3978', 'pm_score': 1, 'selected': False, 'text': '<p>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</p>\n'}, {'answer_id': 87238, 'author': 'JBB', 'author_id': 12332, 'author_profile': 'https://Stackoverflow.com/users/12332', 'pm_score': 0, 'selected': False, 'text': "<p>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.</p>\n"}, {'answer_id': 87822, 'author': 'Bash', 'author_id': 16051, 'author_profile': 'https://Stackoverflow.com/users/16051', 'pm_score': 1, 'selected': False, 'text': '<p>chattr +i /etc/resolv.conf  should work. ( -i to undo )</p>\n\n<p>But the better thing is to configure your dhclient.conf:\n<a href="https://calomel.org/dhclient.html" rel="nofollow noreferrer">https://calomel.org/dhclient.html</a>\nLook at superceding domain-name-servers, and domain-name.</p>\n\n<p>Also look at "send hostname;"\nIf it works at your work place, you will have a cool hostname for your PC and not some weird name that DHCP servers assign.</p>\n'}, {'answer_id': 88316, 'author': 'TobiX', 'author_id': 13258, 'author_profile': 'https://Stackoverflow.com/users/13258', 'pm_score': 3, 'selected': True, 'text': '<p>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.</p>\n'}, {'answer_id': 131240, 'author': 'davenpcj', 'author_id': 4777, 'author_profile': 'https://Stackoverflow.com/users/4777', 'pm_score': 0, 'selected': False, 'text': "<p>The DHCPclient daemon can be told not to update resolv.conf with a command line switch. (-r I think, depending on the client)</p>\n\n<p>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. </p>\n\n<p>Alternatively, you could run the dhcpclient from within a cron job, adding the appropriate process checks.</p>\n"}, {'answer_id': 202040, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>This problem is much more noticeable on networks with low DHCP lease ages. There is a bug filed in Ubuntu\'s dhcp3 package launchpad:</p>\n\n<p><a href="https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/90681" rel="nofollow noreferrer">https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/90681</a></p>\n\n<p>Which includes this patch in the description:</p>\n\n<pre><code>--- /sbin/dhclient-script.orig 2007-03-08 19:19:56.000000000 +0000\n+++ /sbin/dhclient-script 2007-03-08 19:19:46.000000000 +0000\n@@ -13,6 +13,10 @@\n # The alias handling in here probably still sucks. -mdz\n\n make_resolv_conf() {\n+ # don\'t overwrite resolv.conf at RENEW time, since a VPN/PPTP tunnel may\n+ # have updated it with remote DNS servers\n+ [ "$reason" = "RENEW" ] &amp;&amp; return\n+\n     if [ -n "$new_domain_name" -o -n "$new_domain_name_servers" ]; then\n         # Find out whether we are going to mount / rw\n         exec 9&gt;&amp;0 &lt;/etc/fstab\n</code></pre>\n\n<p>This change to <code>/sbin/dhcp-script</code> stops DHCP client from overwriting <code>/etc/resolv.conf</code> when it renews its lease.</p>\n'}]
['https://Stackoverflow.com/questions/48115', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4659/']