The ifconfig command in Linux is used to configure and display network interface parameters. While it’s being replaced by the ip command in modern systems, ifconfig remains widely used for managing network interfaces, IP addresses, and more. Below are practical examples to master ifconfig:
- Display All Network Interfaces
- Display a Specific Network Interface
- Enable a Network Interface
- Disable a Network Interface
- Assign an IP Address to an Interface
- Assign a Netmask to an Interface
- Assign an IP Address and Netmask Together
- Change the MAC Address of an Interface
- Enable Promiscuous Mode
- Disable Promiscuous Mode
- Set the MTU (Maximum Transmission Unit)
- Add an Alias IP Address
- Remove an Alias IP Address
- Display Only Active Interfaces
- Display Interface Statistics
Display All Network Interfaces
ifconfig
Shows details for all active network interfaces (IP, MAC, MTU, etc.).
Display a Specific Network Interface
ifconfig eth0
Shows details for the eth0 interface.
Enable a Network Interface
ifconfig eth0 up
Activates the eth0 interface.
Disable a Network Interface
ifconfig eth0 down
Deactivates the eth0 interface.
Assign an IP Address to an Interface
ifconfig eth0 192.168.1.100
Sets the IP address of eth0 to 192.168.1.100.
Assign a Netmask to an Interface
ifconfig eth0 netmask 255.255.255.0
Sets the netmask for eth0 to 255.255.255.0.
Assign an IP Address and Netmask Together
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
Configures both IP and netmask for eth0.
Change the MAC Address of an Interface
ifconfig eth0 hw ether 00:11:22:33:44:55
Sets the MAC address of eth0 to 00:11:22:33:44:55.
Enable Promiscuous Mode
ifconfig eth0 promisc
promisc: Enables promiscuous mode for packet sniffing.
Disable Promiscuous Mode
ifconfig eth0 -promisc
Disables promiscuous mode on eth0.
Set the MTU (Maximum Transmission Unit)
ifconfig eth0 mtu 1500
Sets the MTU for eth0 to 1500 bytes.
Add an Alias IP Address
ifconfig eth0:0 192.168.1.101
Adds a secondary IP (192.168.1.101) to eth0.
Remove an Alias IP Address
ifconfig eth0:0 down
Deactivates the alias interface eth0:0.
Display Only Active Interfaces
ifconfig -a
Shows all interfaces, including inactive ones.
Display Interface Statistics
ifconfig eth0
Shows packet statistics (RX/TX packets, errors, etc.) for eth0.
Key Notes:
- Deprecation:
ifconfigis being replaced by theipcommand in modern Linux distributions. - Permissions: Most
ifconfigoperations require root privileges (usesudo). - Persistent Changes: Use configuration files (e.g.,
/etc/network/interfaces) for permanent changes.
