As system administrators, we’ll invariably encounter issues with the network connectivity or interface configuration of our devices. At times, these problems can lead to slow or unresponsive connections, network congestion due to packet retransmissions, data corruption, and other undesirable scenarios. However, resetting the interface is a fairly easy process that can assist in resolving many common networking troubles and restoring connectivity quickly.
In this tutorial, we’ll elucidate the different steps involved in restarting the interfaces on Linux devices.
Without any further ado, let’s get into the nitty-gritty of it.
2. What Is a Network Interface?
A network interface is the hardware or software component that manages the network connections of a system. Also, it enables a computer to communicate with other devices across a network. Furthermore, these interfaces are responsible for handling network errors, transmitting and receiving data across the network, and configuring the network (including IP addresses, gateways, and netmasks).
Restarting the interface is a relatively straightforward technique that can help solve many typical networking problems. Nevertheless, an improper interface restart may cause a network outage and possible data loss.
3. Identify Your Network Interface
A single device can have several network interfaces communicating with different network spheres. It’s always good to understand the network and its binding interface before we restart any interface. We can use the ifconfig command to get a comprehensive view of the interface configuration. The -a option will help us list all the available interfaces of the device:
$ ifconfig -a ens160: flags=4163 mtu 1500 inet 22.214.171.124 netmask 255.255.255.248 broadcast 126.96.36.199 inet6 fe80::fc7f:d8da:a969:1c1d prefixlen 64 scopeid 0x20 ether 00:0c:29:23:6f:30 txqueuelen 1000 (Ethernet) RX packets 2124585 bytes 373345569 (373.3 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1149022 bytes 181756632 (181.7 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 ... ... output truncated ... ...
Alternatively, we can also use the nmcli command to get the current status of all network connections across wired, wireless, and other logical bridged interfaces:
$ nmcli device show GENERAL.DEVICE: ens160 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:23:6F:30 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) IP4.ADDRESS: 10.87.34.99/29 ... ... output truncated ... ... GENERAL.DEVICE: ens256 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:23:6F:4E GENERAL.MTU: 1500 GENERAL.STATE: 30 (disconnected) ... ... output truncated ... ...
3. Restart the Network Interface
There are numerous ways to restart the interface in Linux. Here, let’s use the basic ip link command to perform the restart. Also, we need root privileges to perform these activities:
$ sudo ip link set ens224 down $ ip link show ens224 4: ens224: mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000 link/ether 00:0c:29:23:6f:44 brd ff:ff:ff:ff:ff:ff $ sudo ip link set ens224 up $ ip link show ens224 4: ens224: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether 00:0c:29:23:6f:44 brd ff:ff:ff:ff:ff:ff
On the other hand, we can also use other commands like ifconfig, nmcli, ifup, ifdown, and others:
$ sudo ifdown ens224 $ sudo ifup ens224 $ ip link show ens224 4: ens224: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether 00:0c:29:23:6f:44 brd ff:ff:ff:ff:ff:ff $ sudo ifconfig ens224 down $ sudo ifconfig ens224 up $ ip link show ens224 4: ens224: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether 00:0c:29:23:6f:44 brd ff:ff:ff:ff:ff:ff $ sudo nmcli connection down ens224 $ sudo nmcli connection up ens224 $ ip link show ens224 4: ens224: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether 00:0c:29:23:6f:44 brd ff:ff:ff:ff:ff:ff
Lastly, we can use network-manger restart. The former interface commands will interrupt the services of that specific interface.
However, the latter will interrupt services across all the interfaces in that device:
$ sudo service network-manager restart $ sudo service network-manager status ● NetworkManager.service - Network Manager Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2023-03-16 12:48:31 IST; 2s ago Docs: man:NetworkManager(8) Main PID: 20988 (NetworkManager) ... ... output truncated ... ...
4. Test Your Network Connection
After restarting the interface, it is always recommended to verify the operational state of our connection. We can test the network layer through an ICMP test on the configured IP interface and its gateway.
Alternatively, we can try accessing a website deployed on the server to test the application layer:
$ ping -c 1 10.133.14.57 PING 10.133.14.57 (10.133.14.57) 56(84) bytes of data. 64 bytes from 10.133.14.57: icmp_seq=1 ttl=64 time=0.048 ms --- 10.133.14.57 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.048/0.048/0.048/0.000 ms
In this quick article, we’ve started with the basics of network interfaces in a system and the steps to identify them. Further, we’ve elaborately focused on managing the interface through the restart mechanism. Lastly, we also touched upon the testing of the interface once it’s back online.
Overall, understanding the basic management of network interfaces is an essential skill for system administrators and users alike. Even more, it will also help with smoother operation and maintaining the reliability of the secure network.