Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

After editing dns-nameservers in /etc/network/interfaces, how do I tell resolvconf(8) to read the new value without restarting networking? (causing a service interruption)

The -u option doesn't seem to work, it just updates back to the same values.

share|improve this question

marked as duplicate by Luis Alvarado Apr 10 '13 at 16:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
not sure this is possible. restarting network only takes 3 seconds anyway. –  jmartin2279 Oct 19 '12 at 23:07
add comment

3 Answers 3

You are right, "resolvconf -u" does not suffice to activate the change you made. That command only updates resolv.conf from resolvconf's database whereas you need to update the database.

Assume the interface in question is eth0. Assume that in /etc/network/interfaces you have a stanza that looks like this.

iface eth0 inet static
    [...]
    dns-nameservers 1.1.1.1 2.2.2.2

Now you change the "dns-nameservers" line. To activate this change do

ifdown eth0
ifup eth0

or reboot.

share|improve this answer
1  
As the OP says, this will cause a service interruption. What's more, issuing ifdown eth0 will probably kill your ssh connection, so the ifup will never get the chance to run, cutting you off from your server and preventing you getting back in! –  Synchro Nov 14 '12 at 8:44
    
You are right, although the OP didn't say that he was logged in via ssh and only asked how to avoid restarting networking. I will shortly provide another answer which addresses the case you describe. –  jdthood Nov 14 '12 at 19:47
    
I posted the answer here: askubuntu.com/questions/224966/… –  jdthood Dec 13 '12 at 9:43
add comment

I bumped into this twice recently.

The first time, I did sudo ifdown eth0 which of course killed my ssh connection and left the machine ignoring its NIC. Ouch. I had to go in through the IPMI interface on the server to get control again.

The second time, I learned from my earlier mistakes and did sudo ifdown etho ; sudo ifup eth0. The ssh window died, of course, but the machine quickly responded to a new ssh connection and my DNS modifications were in effect. I did the same thing on a second server but this time I waited before typing anything into the ssh window. The window stayed up and the DNS changes had been applied. Awesome.

The critical thing was to use the shell's semicolon operator so that both commands would be on one line. This way, the command to restore the interface has already been entered by the time the interface goes down. I suppose I could have written a script and executed that, but this seemed easier.

UPDATE: There is another way to do this. You can also restart the Ubuntu networking service in one step: sudo /etc/init.d/networking restart or sudo service network-interface restart INTERFACE=eth0. Thanks JFA for the inspiration.

share|improve this answer
    
Why wouldn't you want to restart the connection though? –  JFA Jun 6 at 1:47
    
There was nothing wrong with the SSH connection to the server in question. That server just needed its DNS settings adjusted. –  Randall Cook Jun 6 at 3:41
1  
@RandalCook I mean why is shutting down and bringing eth0 back up better than restarting the service? They both terminate the connection anyway. –  JFA Jun 6 at 14:54
1  
Networking is so fundamental I didn't know there was a service to restart. It seems like a good alternative. Thanks for cluing me into that approach, @JFA. I added it to my answer. –  Randall Cook Jun 6 at 17:42
    
No worries, you can also use service networking restart, which is a little easier to remember. This wasn't a criticism though, OP asks how do do this 'without restarting networking', and you had an answer, so I was asking about the premise of the question. Don't both of these close your ssh connection? –  JFA Jun 6 at 19:58
show 1 more comment

Just went through this same issue; even a reboot would be lose the change on manually invoking the libc hook.

So the most stable way I've found is, after putting the desired content into /etc/network/interfaces, to edit /etc/resolvconf/resolv.conf.d/original to include the lines wanted, make sure tail (in that directory) is not present, cd /etc/resolvconf/resolv.conf.d and then invoke /etc/resolvconf/update.d/libc.

Note that if tail is present (by default, pointed to original then the contents derived from /etc/network/interfaces will be followed by the original setup too.

That these changes can most safely be applied by a reboot is, frankly, insane. The current system takes what used to be "edit this file, perhaps deploying from a configuration management system" and hides it behind multiple layers of abstraction and no clean way to invoke for maintenance outside the normal boot framework.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.