How to Configure Network Interface in Linux

The ifconfig command in Linux is used to configure, manage, and display information about network interfaces. While it has been mostly replaced by ip in modern distributions, it is still useful for network troubleshooting and configuration.

Alby Andersen

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

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: ifconfig is being replaced by the ip command in modern Linux distributions.
  • Permissions: Most ifconfig operations require root privileges (use sudo).
  • Persistent Changes: Use configuration files (e.g., /etc/network/interfaces) for permanent changes.
Share This Article