25

I'd like to make some changes to my networking configuration by editing my /etc/network/interfaces file. What's the cleanest way to make changes to this file and have them take effect, without having to reboot? Typically, I've been doing:

  1. Edit the file
  2. service networking restart

But I have the impression that this isn't the "right" way to make these kinds of changes.

  • service networking restart almost= /etc/init.d/networking restart. – shantanu Feb 10 '12 at 21:00
11

Shut the network interface down using

sudo ifdown eth0

(replace eth0 with the interface you want to change) and bring it up again using

sudo ifup eth0
| improve this answer | |
  • 4
    This didn't work for me. It just gave me an error "eth0 not configured". I had to reboot the system for change to take effect on 12.04. – JohnMerlino Jul 11 '14 at 18:34
  • Careful, this won't work if you're connected over SSH (for obvious reasons). – Ajedi32 Oct 15 at 15:51
9

In Ubuntu Server 16.04 you must use the ip command to flush the address before restarting networking, otherwise any address changes in the interfaces file will not take effect:

$ sudo ip addr flush interface-name
$ sudo systemctl restart networking

I got this answer from this helpful article

| improve this answer | |
  • Perfect, this should be the answer to the question. – Drew Jan 2 '19 at 21:52
2

Stop all interfaces using

sudo /etc/init.d/networking stop

Configure (edit) your interfaces as you wish, then

Start them again

sudo /etc/init.d/networking start

There is no need to reboot.

| improve this answer | |
  • 3
    This didn't work either in Ubuntu 12.04. Only rebooting system worked. – JohnMerlino Jul 11 '14 at 18:37
1

Why don't you think it is the right way. Think, what can ubuntu do extra during booting? Ubuntu has a list of services that need to run during booting, each service has a list of consecutive command to start itself. Ubuntu just run networking service through /etc/init.d/networking script which contains some command that need to run network service. So if any change need to apply to your network then you have to restart your service and the way is recall your service's consecutive commands.

| improve this answer | |
  • Because rebooting is guaranteed to clear all of the interfaces that I have set up, and I'm concerned that if I remove an interface from my interfaces file, then restarting the networking script won't get rid of it. – Lorin Hochstein Feb 10 '12 at 21:11
  • are you sure? any change in network is worked for me with sudo /etc/init.d/networking restart. – shantanu Feb 11 '12 at 19:41
  • For example, if I create a tagged vlan (e.g., eth0.123) it doesn't seem to be automatically destroyed when I restart networking – Lorin Hochstein Feb 13 '12 at 17:56
  • sudo eth0 down --- sudo eth0 up – shantanu Feb 16 '12 at 17:38
  • /etc/init.d/networking re-read all network configuration file and update all settings, why should it destroy created interface? if you change your ip or dns or these kind of information then /etc/... is enough, if you create a virtual lan then you have to restart your ethernet interface(sudo eth0 down then sudo eth0 up). – shantanu Feb 16 '12 at 17:41
1

/etc/network/interfaces controls the ifupdown tools.

So after making changes, you can just say eg sudo ifup eth0.

| improve this answer | |
0

Actually none of these work. Tested on Ubuntu 16.10. these had no effect.

  • ifdown ens3 and ifup ens3
  • service network stop and start
  • service network reload
  • systemctl stop networking.service and then start again.

Through all these the old dhcp ip came back and not the static. i wonder if this is intentional?

| improve this answer | |
0

Try a flush between ifup and ifdown. This worked on Mendel (Google Coral), which is a Debian based.

sudo ifdown eth0 && sudo ip addr flush eth0 && sudo ifup eth0

Without the flush, the interface would restart without reading the config file.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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