Ubuntu apply DNS, IP, and other networking changes without restart

NetworkingNo RebootUbuntu

 

 

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.

 

Creds:  http://askubuntu.com/questions/203261/editing-dns-nameservers-in-etc-network-interfaces-without-a-restart

Leave a Reply