When setting up a Linux server, troubleshooting network connectivity, or assigning static IP addresses to virtual machines, you need direct access to the system’s network interface controllers (NICs). You must know exactly what IP address the server holds, its subnet mask, and whether the physical ethernet port is actually active. Historically, the primary tool for extracting this information and configuring network interfaces on Linux has been the ifconfig command.
Why Use the ifconfig Command?
The ifconfig (Interface Configuration) command is a staple of UNIX-like operating systems. While modern Linux distributions are slowly transitioning to the newer ip command, ifconfig remains deeply embedded in legacy scripts, online tutorials, and the muscle memory of veteran system administrators. It provides an immediate, readable snapshot of all active network adapters, their assigned IPv4 and IPv6 addresses, MAC addresses, and transmission error statistics.
Step 1: View Active Network Interfaces
The most common usage is to simply list the currently active network connections.
- Open your Linux terminal.
- Type the following command and press Enter:
ifconfig
The output will display blocks of information for each active interface. You will typically see eth0 or enp3s0 (your physical ethernet connection) and lo (the local loopback interface). Look for the inet value to find your current IPv4 address.
Step 2: View All Interfaces (Including Inactive Ones)
By default, ifconfig only shows interfaces that are currently “up” (turned on). If a network cable is unplugged or an adapter is disabled, it will be hidden.
- Use the
-a(all) flag to reveal every piece of network hardware the system detects:
ifconfig -a
This is crucial for identifying the correct name of a new, unconfigured network card you just installed.
Step 3: Enable or Disable an Interface
You can use ifconfig to administratively shut down a network connection without unplugging the physical cable.
- To disable an interface (e.g.,
eth0), you must run the command with root privileges usingsudo:
sudo ifconfig eth0 down
- To turn the interface back on, use the
upcommand:
sudo ifconfig eth0 up
Step 4: Assign a Temporary IP Address
You can quickly force an interface to adopt a specific IP address for temporary testing. Note that this change is not persistent and will revert when the system reboots.
- Specify the interface name, the new IP address, and the
netmaskparameter:
sudo ifconfig eth0 192.168.1.150 netmask 255.255.255.0
The interface will instantly drop its old IP and adopt the new one.
While the newer ip command is recommended for modern script development, mastering ifconfig ensures you can confidently navigate and troubleshoot almost any legacy or bare-metal Linux environment.