Understanding the ifconfig Command in Linux
The ifconfig command is a fundamental network utility in Linux systems used to view and configure network interfaces. It provides information about active network devices and allows users to set IP addresses, enable or disable interfaces, and perform basic network troubleshooting.
While it has been mostly replaced by the ip command in newer Linux distributions, ifconfig remains widely used for its simplicity and effectiveness.
What is ifconfig?
- Full form: Interface Configuration
- Purpose: To display and modify the configuration of network interfaces on a Linux system.
- Supports: Physical interfaces (Ethernet, Wi-Fi) and virtual interfaces (loopback, aliases).
1. Display All Active Network Interfaces
ifconfigLists all active interfaces with details like IP address, MAC address, subnet mask, and status.
2. View Specific Interface Details
ifconfig eth0Shows detailed info for the interface named eth0.
3. Enable (Bring Up) a Network Interface
sudo ifconfig eth0 upActivates the interface eth0.
4. Disable (Bring Down) a Network Interface
sudo ifconfig eth0 downDeactivates the interface eth0.
5. Assign an IP Address to an Interface
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0Sets a static IP address 192.168.1.100 and subnet mask on interface eth0.
6. Change MAC Address (Temporary)
sudo ifconfig eth0 hw ether 00:11:22:33:44:55Changes the hardware (MAC) address of eth0. This change is temporary and resets on reboot.
7. Add an Alias IP Address
sudo ifconfig eth0:1 192.168.1.101 netmask 255.255.255.0 upCreates a virtual interface eth0:1 with an additional IP address.
- Changes made with
ifconfigare temporary and will not persist after a reboot. - Many modern Linux distributions recommend using the
ipcommand (iproute2package) for network configuration, which offers more features and flexibility. - Despite being deprecated,
ifconfigis still useful for quick diagnostics and in environments whereipis not available.
Alternative: Using the ip Command
Task | ifconfigExample | ipCommand Equivalent |
|---|---|---|
Show all interfaces |
|
|
Bring interface up |
|
|
Assign IP address |
|
|
The ifconfig command is a straightforward and effective tool for managing network interfaces on Linux. It provides immediate insight and control over network settings but is gradually being replaced by more powerful utilities like the ip command.