10

I am using Ubuntu server 16.04 and setting up some network interfaces, I wish to reload a static IP after changing its address at /etc/network/interfaces without reboot:

auto ens6
iface ens6 inet static
        address 192.168.0.41
        netmask 255.255.255.0
        broadcast 192.168.0.255

I tried the following:

sudo systemctl restart networking
sudo ifconfig ens6 down (and afterwards up)
sudo ifdown ens6 (and afterwards up)

and tried some combinations of these commands,

Yet if i change my 'address' at the /etc/network/interfaces it will get updated (at ifconfig) only after i reboot my machine

What is the correct way to do this action without a reboot?

EDIT - tried this also due to comments

sudo /etc/init.d/networking restart
Matan Levy
  • 101
  • 1
  • 1
  • 6
  • 1
    Have you tried `sudo /etc/init.d/networking restart` for network restart? – Terrance Sep 26 '16 at 06:14
  • tried now, seems like it's doing the same as 'systemctl restart networking', i still get the same IP address when checking ifconfig – Matan Levy Sep 26 '16 at 06:16
  • OK, thanks for trying. Unfortunately at the moment my system is not in a state that I could do some testing for you. I can do some more research and see if I can duplicate the issue and help you resolve it. – Terrance Sep 26 '16 at 06:18
  • thank you, ill keep an eye on the post, right now the servers are at setup and dev so I can manage with the reboots but i might need to change the static IP sometime at production and I can't afford rebooting for this type of action – Matan Levy Sep 26 '16 at 06:23
  • One other thing you could try, and I just did this, when you run the `sudo ifdown ens6` try running `sudo ifup -a` to bring it back up and see if your IP address changes. It just did for me. – Terrance Sep 26 '16 at 06:41
  • sudo ip addr flush ens6 && sudo systemctl restart networking.service according to http://www.configserverfirewall.com/ubuntu-linux/ubuntu-set-static-ip-address/ – Nour Feb 25 '18 at 19:53

3 Answers3

10

If the ifdown+ifup approach isn't working, try:

sudo ifdown <network interface> && sudo ip addr flush <network interface> && sudo ifup <network interface>
Ed Bordin
  • 201
  • 2
  • 4
3
ip addr flush enp0s3 && systemctl restart networking.service   

Where enp0s3 is your netcard name.

abu_bua
  • 10,473
  • 10
  • 45
  • 62
2

To get your IP addresses to change without rebooting the system, run the following lines to perform the task. Make sure that you have completed your changes to your /etc/network/interfaces file before you run these steps:

EDIT:

You can try turning off predictive network naming by adding the following to /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0"

Then run the grub update:

sudo update-grub

Reboot the system:

sudo reboot

Turn off the interface first:

sudo ifdown <network interface>

Then bring back up all interfaces:

sudo ifup -a

Hope this helps!

Terrance
  • 39,774
  • 7
  • 116
  • 176
  • this did not work for me i still get the same results at ifconfig (i am using ubuntu 16.04 lts) – Matan Levy Sep 26 '16 at 07:40
  • @MatanLevy You know, I am wondering if it is the fact that I am not running predictive names for the network. Unfortunately, I am not 100% sure if the Server edition uses predictive naming or not. I am running 16.04.1 LTS. – Terrance Sep 26 '16 at 13:40
  • tried to change the GRUB_CMDLINE_LINUX_DEFAULT and still no good – Matan Levy Sep 26 '16 at 14:03
  • @MatanLevy Sorry, I forgot to mention that you have to reboot after changing that line and updating grub. Did you reboot? – Terrance Sep 26 '16 at 14:04
  • @MatanLevy Well, I did more testing, and mine is working fine. I am going to have to install server edition then to fully test this out. – Terrance Sep 26 '16 at 14:08
  • well i did not reboot, i will check this soon and let you know – Matan Levy Sep 26 '16 at 14:53
  • @Terrance All Ubuntu 16.04 use predictive names unless explicitly disabled after installing. – Thomas Ward Sep 26 '16 at 16:49
  • @ThomasWard I wasn't quite certain because my Dell tower I use at work, I did a clean install of 16.04 on it, and it never setup predictive names on it. Either way I tried, it still showed `em1` as my ethernet. Just thought that one was interesting. – Terrance Sep 26 '16 at 16:54
  • well i dont know why but that still ain't working – Matan Levy Sep 27 '16 at 06:07
  • OK so it seems like this is working on my ubuntu servers (was trying on my ubuntu desktop) but not on my ubuntu desktop – Matan Levy Sep 27 '16 at 06:31