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
6
  • 1
    Have you tried sudo /etc/init.d/networking restart for network restart?
    – Terrance
    Sep 26, 2016 at 6: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, 2016 at 6: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, 2016 at 6: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, 2016 at 6: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, 2016 at 6:41

3 Answers 3

10

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

sudo ifdown <network interface> && sudo ip addr flush <network interface> && sudo ifup <network interface>
3
ip addr flush enp0s3 && systemctl restart networking.service   

Where enp0s3 is your netcard name.

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!

10
  • 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, 2016 at 7: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, 2016 at 13:40
  • tried to change the GRUB_CMDLINE_LINUX_DEFAULT and still no good
    – Matan Levy
    Sep 26, 2016 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, 2016 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, 2016 at 14:08

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