How to Restart Network in Ubuntu Server 16.04

In this tutorial we are going to learn how to restart network in Ubuntu Server 16.04. Latest release of Ubuntu Server seems to have some issues when restarting network interfaces, So let's how we can do it properly.

Problem with Ubuntu 16.04 is that when you configure new IP Address on a Network interface, it does not remove the old IP Address from the interface after network restart.

Restart Network Interface in Ubuntu 16.04

So before restart networking, flush the interface you want to restart using ip addr command.

ip addr flush interface-name

Then restart the Ubuntu networking service using systemctl command.

systemctl restart networking.service

Be Careful, You should not flush IP Address through a SSH connection, Because you will lose the connection to the server immediately after you flushed the network interface.

If you really need to restart network in Ubuntu 16 through a SSH connection, then execute the ip addr flush command and systemctl command as a sequence of commands using bash &&.

ip addr flush interface-name && systemctl restart networking.service

This will make sure that both commands will be executed.

Example

For example, if the name of the interface you want restart is enp0s3, then flush the enp0s3 network interface and restart the networking service.

ip addr flush enp0s3 && systemctl restart networking.service

As per the above example, ip addr flush command will remove the existing IP Address from the enp0s3 interface, Then apply the new configuration through the ubuntu network restart.

Restart Network in Ubuntu Server 16.04

Restart Network Ubuntu Server 14.04

In Ubuntu Server 14.04 you need to use ifdown and ifup command to Apply new configuration to a network interface.

ifdown ifname && ifup ifname

For example, if the interface name is eth0, then you should run.

ifdown eth0 && ifup eth0

If you are using Ubuntu 12.04 or earlier version, you can simply restart networking using service command.

service networking restart

Summary

In this tutorial we learned how to restart network interface in Ubuntu server 16.04 using ip addr flush command and systemctl command.

submit to reddit