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
ifconfig
Lists all active interfaces with details like IP address, MAC address, subnet mask, and status.
2. View Specific Interface Details
ifconfig eth0
Shows detailed info for the interface named eth0
.
3. Enable (Bring Up) a Network Interface
sudo ifconfig eth0 up
Activates the interface eth0
.
4. Disable (Bring Down) a Network Interface
sudo ifconfig eth0 down
Deactivates the interface eth0
.
5. Assign an IP Address to an Interface
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
Sets 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:55
Changes 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 up
Creates a virtual interface eth0:1
with an additional IP address.
- Changes made with
ifconfig
are temporary and will not persist after a reboot. - Many modern Linux distributions recommend using the
ip
command (iproute2
package) for network configuration, which offers more features and flexibility. - Despite being deprecated,
ifconfig
is still useful for quick diagnostics and in environments whereip
is not available.
Alternative: Using the ip
Command
Task | ifconfig Example | ip Command 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.