Excerpt

Networking is an essential part of any Linux system. Proper networking allows communication between devices and the internet. Understanding the network interface is vital when setting up servers, solving connectivity issues, and managing device traffic flow.
A common problem faced in networking is losing connectivity after modifying the network settings, which leads to an inability to access the system. This usually happens due to a misconfigured IP address, incorrect settings, and a poor understanding of network interface configurations.
In this article, we’ll guide you through understanding these network interface configurations, setting up and managing network interfaces on Linux, checking available interfaces, configuring static and dynamic IP addresses, and best practices to consider when setting up network interfaces. At the end of this article, you’ll have a solid f

Networking is an essential part of any Linux system. Proper networking allows communication between devices and the internet. Understanding the network interface is vital when setting up servers, solving connectivity issues, and managing device traffic flow.
A common problem faced in networking is losing connectivity after modifying the network settings, which leads to an inability to access the system. This usually happens due to a misconfigured IP address, incorrect settings, and a poor understanding of network interface configurations.
In this article, we’ll guide you through understanding these network interface configurations, setting up and managing network interfaces on Linux, checking available interfaces, configuring static and dynamic IP addresses, and best practices to consider when setting up network interfaces. At the end of this article, you’ll have a solid foundation in network interfaces.
## Table of Contents
## What are Network Interfaces?
A network interface is a connection point within the Linux system that allows communication with other devices within the network. It is how the Linux kernel links the software side of the network with the hardware side. Linux systems provide many network interfaces that help to facilitate communication between the system and other external networks.
Linux network interfaces are essential for troubleshooting, configuration, management, and optimization of networking tasks. Understanding what they are and how they work allows you to optimize your server networking and security.
## Types of Network Interfaces in Linux
Network interfaces can be classified into two main categories: physical and virtual network interfaces.
Physical network adapters are the hardware components of the network interface that connect the system to a physical network. These physical networks include Wi-Fi and Ethernet. These adapters, commonly called Network Interface Cards (NIC), can be identified by their device names, such as wlan0 and eth0. They include the following:
1. Ethernet Interface (eth0, eth1, and so on)
Ethernet interface is used for wired connections via an Ethernet card and helps configure high-speed networking. It can be used in data centres and servers.
2. Wi-Fi interface (wlan0, wlan1, and so on)
This represents a wireless network adapter, and it enables wireless connectivity via Wi-Fi networks to the servers.
Virtual network interfaces are software-based interfaces managed by the Linux operating system. They integrate network virtualization technologies like Docker or KVM. There are several virtual network interfaces, and the most common ones include:
- Loopback interface: This is a special interface that allows a system to communicate internally. It is permanently assigned the IP address 127.0.0.1, referred to as the localhost.
- Bridge Interface: They are used to connect multiple network interfaces. It is useful for virtualization environments (for example, Linux KVM, Docker networking).
- Tunnel Interface: This is used for VPNs and networking tunnels. It helps to facilitate the passage of encrypted network traffic.
## Why Network Interfaces Matter
Network interfaces form an essential component of a Linux system. It enables communication between devices and the internet, and properly configuring these interfaces provides the following benefits:
Seamless connectivity: Network interfaces allow devices to communicate over local networks and the internet, enabling proper data exchange between servers and networks.
Proper network management: Administrators can configure network interfaces by creating, managing, and assigning static or dynamic IPs and optimizing traffic flow.
Improved security: Administrators can configure network interfaces with firewalls and VPNs to secure data and prevent unauthorized access.
It provides support for virtualization and containerization: Virtual network interfaces provide proper communication between virtual machines, Docker containers, and other physical servers. This makes them essential for creating and managing DevOps environments.
## How to List Network Interfaces in Linux
You can check the available network interfaces within the Linux environment using the following commands.
1. Using the ip command:
To list all network interfaces and their status, you can use the ip link show command. It displays details about the network interfaces, like the name, status, and MAC address.
2. Using the ifconfig command
To list all network interfaces, use this command: ifconfig -a. The command also displays details about the network interfaces and their current state.
3.
To check the status of all network interfaces managed by NetworkManager, run:
nmcli device status.
4. Using the /sys/class/net/ directory
To list all network interfaces, run ls /sys/class/net/ This command is useful for scripting and automation because it provides a reliable way to check available interfaces programmatically.
## How to Configure Network Interfaces in Linux
Network interface configuration is essential for managing Linux servers and workstations. Understanding this configuration will help ensure smooth connectivity within your systems. This section will give you the correct information on configuring network interfaces.
### Assign a Static IP Address
A static IP address ensures the device maintains the same IP after each reboot. This is particularly useful for servers and devices that need consistent addressing. To assign a static IP address, the NetworkManager Command Line Interface (nmcli) provides a command-line utility to configure the network interface as shown below.
```plain text
nmcli connection modify eth0 ipv4.addresses .1.100/24
nmcli connection modify eth0 ipv4.gateway .1.1
nmcli connection modify eth0 ipv4.dns
nmcli connection modify eth0 ipv4.method manual
nmcli connection up eth0
```
These commands set a fixed IP, gateway, and DNS on eth0, switch the interface to manual mode, and restart it so the new settings take effect. The settings persist across reboots because they are stored by NetworkManager
### Assign a Temporary IP Address
The ip command lets you configure interfaces dynamically (not persistent across reboots):
These two commands give eth0 the IP 192.168.1.100/24 and point all outbound traffic to the gateway 192.168.1.1. The settings last only until the next reboot or interface reset.
### Assign an IP Address with ifconfig (deprecated)
Older systems still ship with ifconfig and route. These commands are also temporary.
```plain text
eth0 .1.100 netmask .255.0 up
route default gw .1.1 eth0
```
Note: Prefer ip or nmcli on modern systems.
### Enable DHCP with nmcli
A DHCP-assigned address lets the network hand out an IP address automatically.
```plain text
nmcli connection modify eth0 ipv4.method auto
nmcli connection up eth0
```
To renew or request a lease directly:
These commands set eth0 to use DHCP, restart the link so the change takes effect, and (optionally) trigger an instant lease renewal.
### Assign Multiple IP Addresses to One Interface
A network interface can have multiple addresses assigned to it, making it applicable to host multiple services on a single interface.
Using IP command (Temporary Assignment)
```plain text
addr .1.101/24 dev eth0
addr :db8::1/64 dev eth0
```
These two commands attach an extra IPv4 and an IPv6 address to eth0 until the interface resets or the system reboots
Persistent Configuration (Netplan)
Edit the /etc/netplan/01-netcfg.yaml file:
```plain text
network:
version:
renderer: networkd
ethernets:
eth0:
addresses:
- .1.100/24
- .1.101/24
- :db8::1/64
```
After editing the file, run sudo netplan apply to make the additional addresses stick across reboots.
## How to Set Up a Network Bridge in Linux
A network bridge allows multiple interfaces to act as a single network segment, which is useful in virtualization (KVM, Docker).
Using brctl (bridge-utils package)
```plain text
brctl addbr br0
brctl addif br0 eth0
addr .1.100/24 dev br0
br0 up
```
These commands create bridge br0, attach eth0 to it, give the bridge its own IP, and bring it online.
Using nmcli (for NetworkManager-managed systems)
```plain text
nmcli connection bridge ifname br0
nmcli connection modify br0 bridge.stp no
nmcli connection bridge-slave ifname eth0 master br0
nmcli connection up br0
```
This sequence builds the same bridge through NetworkManager, disables STP for faster convergence, links eth0 as a slave, and activates the bridge so guests can reach the network.
## Best Practices for Configuring Network Interfaces in Linux
### Make Your Configurations Persistent
One of the mistakes network engineers make in Linux networking is making changes that do not persist after rebooting. While specific commands can modify the network settings temporarily, they do not save these changes permanently.
To ensure that these network settings survive server reboots, modify system configuration files such as /etc/network/interfaces. Once you ensure that all changes are persistent, there will be no unexpected disruptions when a system restarts.
### Assign Static IPs for Servers
Static IP addresses are the best for servers and critical infrastructure. Unlike DHCP addresses, which can change over time, static IP addresses are more stable and reliable. For services like web hosting and database management, static IPs play a key role, as IP addresses do not need to change.
### Secure Your Network Interfaces
Network interfaces are the entry points into a system, so if they are misconfigured, they could pose a considerable security risk. To reduce attacks, administrators should turn off all unused network interfaces by modifying the configuration file to prevent automatic activation. Additionally, you should use firewall tools to control the traffic that tries to reach the system.
### Monitor Your Network Interfaces
As a system administrator, monitoring network interfaces helps prevent downtime and ensure proper network reliability. You can check the status of your network interfaces by running commands like link show or if-config -a. You can also monitor them in real time using tools like Netstat. Monitoring your systems ensures that network issues are detected early enough, reducing downtime and improving network stability.
### Constantly Update Network Packages
You must constantly update network management tools and drivers because it helps to implement security patches and other performance improvements, as outdated network packages can cause security vulnerabilities. There are specific network-related packages such as network-manager, bridge-utils and iproute2.
Setting up network interfaces in Linux is a fundamental skill every system administrator should have. Whether configuring static IP addresses or enabling DHCP, understanding these concepts will ensure that your systems are stable and have proper connectivity. Implementing best practices like monitoring traffic and securing the network interface gives you the best results. As you continue working with Linux, you can experiment with different configurations to deepen your understanding of network interfaces.
Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started