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

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
3
ip addr flush enp0s3 && systemctl restart networking.service   

Where enp0s3 is your netcard name.

abu_bua
  • 11,313
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
  • 43,712