29

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.

1
  • service networking restart almost= /etc/init.d/networking restart.
    – shantanu
    Feb 10, 2012 at 21:00

8 Answers 8

14

In Ubuntu Server 16.04 and above you must use the ip command (man page) 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

1
  • Perfect, this should be the answer to the question.
    – Drew
    Jan 2, 2019 at 21:52
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
3
  • 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. Jul 11, 2014 at 18:34
  • 1
    Careful, this won't work if you're connected over SSH (for obvious reasons).
    – Ajedi32
    Oct 15, 2020 at 15:51
  • 1
    @Ajedi32 just join them with && in a single line. Feb 3, 2021 at 14:00
3

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.

3
  • 3
    This didn't work either in Ubuntu 12.04. Only rebooting system worked. Jul 11, 2014 at 18:37
  • will ssh connection be drop during this operation?
    – alper
    Feb 6, 2021 at 15:58
  • 1
    @alper Yes. But the convenient way to restart network interface over ssh is by doing service network stop; sleep 5; service network start However, Please be careful, If you mess up your interface configuration, you might not gain back your ssh season, so be very careful.
    – Achu
    Feb 15, 2021 at 12:50
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.

5
  • 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. Feb 10, 2012 at 21:11
  • are you sure? any change in network is worked for me with sudo /etc/init.d/networking restart.
    – shantanu
    Feb 11, 2012 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 Feb 13, 2012 at 17:56
  • sudo eth0 down --- sudo eth0 up
    – shantanu
    Feb 16, 2012 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, 2012 at 17:41
1

/etc/network/interfaces controls the ifupdown tools.

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

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?

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.

0

Another alternative that worked for me:

  1. Edit the /etc/network/interfaces file
  2. Execute the following:
ifdown --all --allow auto
ifdown --all --allow hotplug
ifup --all --allow auto
ifup --all --allow hotplug

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .