The ifconfig command in Linux: configuring network interfaces

Introduction

In Unix-like systems, managing network interfaces is essential for administrators and advanced users. Although the ip command has been replacing ifconfig in many modern distributions, this tool remains present on numerous Linux systems, especially in legacy environments or boot scripts. ifconfig allows querying and modifying the state of network cards, showing information such as MAC address, IP, netmask, and MTU. In this article we will see how to use ifconfig to inspect interfaces, bring them up or down, assign static IP addresses, and understand its limitations compared to more current tools.

What is ifconfig?

ifconfig, short for “interface configuration”, is a command-line program that allows querying and modifying the parameters of network interfaces on a Linux system. Originating from BSD, it was included in the net-tools package and became a standard for displaying data for each interface: MAC address, state (UP/DOWN), IP, subnet mask, and MTU. Moreover, it allows changing these characteristics in real time without restarting the network service, which is useful for testing, diagnosis, and temporary configurations. Although its usage has decreased in favor of the ip command, it still appears in many manuals and administration scripts.

Basic Syntax

The syntax of ifconfig is simple: you write the command followed optionally by the interface name and then the options indicating the action to execute. Without arguments it shows a summary of all detected interfaces; with -a it also shows the inactive ones. To modify an interface, you specify its name (for example, eth0 or wlan0) and then the parameters you wish to change, such as the IP address, netmask, or state (up/down). The most common options are ‘up’ to bring up, ‘down’ to take down, an IP followed by netmask to define the mask, and mtu to adjust the MTU.

Viewing Interfaces

To see all interfaces, run ifconfig -a. The -a flag also shows inactive interfaces, which the command omits by default. The output includes, for each interface, the name, state (UP or DOWN), MAC address (HWaddr), IP address (inet), netmask (netmask), broadcast address, and MTU. It also shows statistics for transmitted and received packets, errors, and collisions. This information helps diagnose problems: if an IP is missing, perhaps the interface is not configured or DHCP did not respond; if it is DOWN, you bring it up with ifconfig up; and an inappropriate MTU can cause fragmentation or poor performance.

Activating/Deactivating an Interface

Activating or deactivating an interface with ifconfig is immediate and does not require restarting the network daemon. To bring up an interface use: ifconfig interface_name up; to take it down: ifconfig interface_name 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 or the interface is brought up again. They are useful for replacing a cable, testing a new IP without affecting other interfaces, or isolating a card for security testing. If the interface is managed by NetworkManager or a persistent service, the changes may be overwritten when the service is restarted.

Assigning IP Address and Netmask

Assigning a static IP address and its subnet mask with ifconfig is done in a single step. The basic syntax is: ifconfig interface_name IP_address netmask netmask. For example, to configure eth0 with IP 192.168.10.25 and netmask 255.255.255.0 you run: ifconfig eth0 192.168.10.25 netmask 255.255.255.0. If you only want to change the mask, simply repeat the current IP followed by netmask and the new mask. You can also combine activation on the same line: ifconfig eth0 up 192.168.10.25 netmask 255.255.255.0. It is important to avoid IPs that cause conflicts and verify that the mask correctly reflects the subnet size.

Configuring Routes and MTU

Beyond IP and mask, ifconfig allows adjusting other parameters that affect interface behavior. The MTU (Maximum Transmission Unit) defines the maximum packet 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 interface_name mtu value, for example: ifconfig eth0 mtu 1400. Although ifconfig does not directly manage routing tables, assigning an IP and mask causes the kernel to create a direct route to the subnet. For a default gateway you must use route or ip route; older

This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .