1. Network Interfaces

A linux network interface is the crucial point of connection between the kernel's software networking stack and the physical network hardware. It allows your operating system to send and receive data over a network. We've already seen an example of what a configured linux interface looks like:

pete@icebox:~$ ifconfig -a
eth0      Link encap:Ethernet  HWaddr 1d:3a:32:24:4d:ce
          inet addr:192.168.1.129  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fd60::21c:29ff:fe63:5cdc/64 Scope:Link

Understanding Network Interfaces

When you view your network settings, you'll see interfaces with names like eth0 (the first Ethernet card), wlan0 (a wireless interface), or lo (the loopback interface). The loopback interface is a special virtual interface that represents your own computer, allowing you to connect to services running locally.

An interface can be in an "up" or "down" state. An "up" state means it's active and ready to transmit data, while "down" deactivates it. Key information displayed for each interface includes the HWaddr (its unique MAC address), inet address (its IPv4 address), and inet6 address (its IPv6 address), along with the subnet mask and broadcast address.

The Legacy ifconfig Command

The ifconfig command is a classic tool for configuring a linux network interface. On system boot, it typically runs to set up interfaces based on configuration files. While still available on many systems, it is now considered a legacy tool.

You can use ifconfig to manually assign an IP address and bring an interface up:

ifconfig eth0 192.168.2.1 netmask 255.255.255.0 up

You can also use the related ifup and ifdown commands to easily activate or deactivate an interface:

ifup eth0
ifdown eth0

The Modern ip Command

The ip command is the modern and more powerful replacement for ifconfig. It is the preferred method for managing the network stack on most current Linux distributions.

Here are some common examples of its usage:

Show information for all interfaces:

ip link show

Show detailed statistics for a specific interface:

ip -s link show eth0

Show IP addresses assigned to interfaces:

ip address show

Bring an interface up or down:

ip link set eth0 up
ip link set eth0 down

Add an IP address to an interface:

ip address add 192.168.1.1/24 dev eth0

Network Configuration Files

While commands like ip and ifconfig configure the live state of an interface, these changes are not permanent and will be lost on reboot. To make settings persistent, you must edit configuration files.

A common location for these files is /etc/network/interfaces. The etc network interfaces file is particularly prevalent on Debian-based systems like Ubuntu. Managing debian network interfaces through this file allows you to define static IP addresses, gateways, and other settings that are applied automatically at boot. The structure within debian network/interfaces is straightforward and well-documented.

Sign in to save your learning progress

Sign in

Exercises

Put your knowledge into practice with these hands-on labs. They will help reinforce your understanding of network interfaces and IP addressing.

  1. Identify MAC and IP Addresses in Linux - Practice using the ip a command to identify network addressing information, including MAC, IPv4, and IPv6 addresses on a Linux system.
  2. Manage IP Addressing in Linux - Learn to configure static and dynamic IP addresses, set a default gateway, and verify network configurations using the ip command.
  3. Explore IP Address Types and Reachability in Linux - Explore different IP address types (private, public, multicast) and test network reachability using ping and ip a.

These labs will help you apply the concepts of network interface identification and IP addressing in real scenarios and build confidence with Linux networking.

Quiz

What is the legacy command used to configure a Linux network interface? Please answer in English, using only lowercase letters.