The ifconfig command in Linux: configure network interfaces

Introduction

In Unix-type systems, network interface management is essential for advanced managers and users. Although the ip command has been replacing ifconfig in many modern distributions, this tool remains present in numerous Linux systems, especially in inherited environments or boot scripts. ifconfig allows you to consult and modify the status of network cards, showing information such as MAC, IP, mask and MTU address. In this article we will see how to use ifconfig to inspect interfaces, activate or deactivate them, assign static IP addresses and understand their limitations to the most current tools.

What is ifconfig?

ifconfig, abbreviated «Configuration interface», is a command line program that allows you to consult and modify the parameters of network interfaces on a Linux system. Originally in BSD, it was included in the net-tools package and became a standard for showing data from each interface: MAC address, status (UP / DOWN), IP, subnetwork mask and MTU. In addition, it allows to change these features in real time without restarting the network service, which is useful for testing, diagnosis and time configurations. Although its use has decreased against the ip command, it still appears in many management manuals and scripts.

Basic syntax

The ifconfig syntax is simple: the command followed optionally from the interface name is written and then the options that indicate the action to run. Without arguments it shows a summary of all the interfaces detected; with -a also the inactive are shown. To modify an interface, your name (e.g. eth0 or wlan0) is indicated and then the parameters you want to change, such as IP address, network mask or status (up / down). The most common options are 'up' to activate, 'down' to deactivate, an IP followed by netmask to define the mask, and mtu to adjust the MTU.

Visualize interfaces

To see all the interfaces, run ifconfig-a. The flag -a also shows the inactive, which the command omits by default. The output includes, for each interface, the name, the status (UP or DOWN), the MAC address (HWaddr), the IP (inet), the network mask (netmask), the broadcast address and the MTU. There are also statistics of packages transmitted and received, errors and collisions. This information helps to diagnose problems: if an IP is missing, the interface may not be configured or DHCP did not respond; if DOWN is, it rises with ifconfig up; and an inadequate MTU can cause fragmentation or malperformance.

Enable / disable an interface

Activating or disabling an interface with ifconfig is immediate and does not require reboot the network daemon. To lift an interface use: ifconfig name _ interface up; to lower it: ifconfig name _ interface down. These commands change the state to UP or DOWN, allowing or stopping traffic, while the IP configuration remains in the kernel until a new one is assigned to it or is relifted. They are useful for replacing a cable, testing a new IP without affecting other interfaces, or isolating a security test card. If the interface is managed by NetworkManager or a persistent service, the changes can be overwritten when reactivating the service.

Assign IP address and mask

Assign a static IP address and your subnetwork mask with ifconfig is made in one step. The basic syntax is: ifconfig name _ interface address _ IP netmask mask. For example, to configure eth0 with IP 192.168.10.25 and mask 255.255.0 runs: ifconfig eth0 192.168.10.25 netmask 255.255.0. If you just want to change the mask, just repeat the current IP followed by netmask and the new mask. The activation can also be combined on the same line: ifconfig eth0 up 192.168.10.25 netmask 255.255.255.0. It is important to prevent IP from conflict and to verify that the mask correctly reflects the size of the subnetwork.

Configure routes and MTU

Beyond IP and mass, ifconfig allows adjusting other parameters that affect interface behaviour. The MTU (Maximum Transmission Unit) defines the maximum package size that can be sent without fragmentation; typical values are 1500 for Ethernet and 1492 for some PPP links. To change the MTU use: ifconfig name _ interface mtu value, for example: ifconfig eth0 mtu 1400. Although ifconfig does not manage routing tables directly, assigning an IP and mass makes the kernel create a direct route to the subnet. For a default gateway you must use route or ip route; older scripts sometimes incorrectly use ifconfig with 0.0.0.0, which does not set a gateway and should be avoided.

Practical examples and modern alternatives

To consolidate the learned, here are some practical examples you can copy in your terminal: 1. Show all interfaces: ifconfig -a. 2. Lift wlan0 and get IP using DHCP: ifconfig wlan0 up & & dhclient wlan0. 3. Configure static IP in eth0: ifconfig eth0 10.0.5.10 netmask 255.255.255.0 up. 4. Change the MTU from eth0 to 9000 for jumbo frames: ifconfig eth0 mtu 9000. Although ifconfig remains useful, the iproute2 package ip tool offers a more consistent and powerful interface, especially to manage multiple IP addresses per interface and advanced routing policies. In recent distributions ip has replaced ifconfig as default, but knowing both commands allows to manage inherited systems and understand the evolution of network tools in Linux.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish