Configuring Network Interfaces in Linux

Properly configuring network interfaces is essential for managing network connections on a Linux system. This guide will walk you through the basic concepts, configuration methods, and common tools used for setting up and managing network interfaces.

Understanding Network Interfaces

A network interface in Linux is a software representation of a physical or virtual network device. It can be connected to a network and assigned an IP address, making it possible to send and receive data.

Need a networking refresher? Check out the linux networking basics.

Types of Network Interfaces

  • Ethernet (eth0, eth1, etc.): Represents physical network interfaces connected via Ethernet cables.
  • Loopback (lo): A special interface used by the system for internal communication.
  • Wireless (wlan0, wlp2s0, etc.): Interfaces for wireless network devices.
  • Virtual Interfaces: Used in containerization and virtualization (e.g., veth, br0 for bridge interfaces).

Configuring Network Interfaces Manually

Using ip Command

The ip command is the modern and versatile tool for managing network interfaces in Linux. Below are some common tasks:

View Interfaces

ip a

Assign IP Address

sudo ip addr add 192.168.1.100/24 dev eth0

Bring Interface Up/Down

sudo ip link set eth0 up
sudo ip link set eth0 down

Using ifconfig

While deprecated in many distributions, ifconfig is still widely used:

View Interfaces

ifconfig

Assign IP Address

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up

Persistent Network Configuration

To ensure network settings persist across reboots, configurations should be written to specific files based on your Linux distribution.

Debian/Ubuntu

Edit the /etc/network/interfaces file:

auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1

Red Hat/CentOS

For Red Hat-based distributions, network configurations are typically stored in /etc/sysconfig/network-scripts/ifcfg-eth0:

DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

Using NetworkManager

For more dynamic environments, especially desktop systems, NetworkManager provides an easy way to manage network settings:

  • Command Line:
    nmcli dev show
    nmcli con add type ethernet ifname eth0 con-name Home ip4 192.168.1.100/24 gw4 192.168.1.1
  • Graphical Interface: Use nmtui or GUI tools for interactive configuration.

Bridge Interfaces

Bridge interfaces are used to link multiple containers or virtual machines to the same network:

sudo ip link add name br0 type bridge
sudo ip link set br0 up
sudo ip link set eth0 master br0

Go deeper on learning bridge networks.

Troubleshooting Network Interfaces

Networking issues can often be traced to misconfigured interfaces. Use these tools to troubleshoot:

Check Interface Status

ip link show

Test Connectivity

ping 8.8.8.8

Review Logs

sudo journalctl -xe