ifconfig command : Learn with some examples
‘Ifconfig’ , short for ‘Interface Configuration, is a very important utility of Linux systems. It is used to check & configure network interfaces using the terminal or CLI of Linux machines. With ifconfig command we can check information regarding the network interfaces, we can configure them or we can also enable and disable them.
Any person using a Linux distro should know how to use ifconfig, especially if the distro you are using is CLI based. In this tutorial, we will learn to use ifconfig utility in detail.
Check information regarding Network Interfaces
To check complete information regarding the network interfaces, open the terminal & execute
$ ifconfig -a
Only difference between the two mentioned command is that , while ‘ifconfig’ shows information regarding all the active interfaces ; ‘ifconfig -a’ shows information of all the interfaces including interfaces that are currently not active also.
Check information regarding a particular Network Interface
We might have a number of network interfaces with names like ‘eth0’ , ‘eth1’, ‘wlan0’ etc. So if we want to see information regarding a particular network interface, then run
$ ifconfig eth0
Enabling or disabling an interface
With ifconfig, we can enable or disable a particular interface & the way we do it is
$ ifconfig eth0 up
This is to bring UP an interface, for disabling an interface the command is
$ ifconfig eth0 down
Remember, you will need sudo privileges to perform this acction.
( Recommended Read: Granting SUDO access to a local user account )
Configuring a network interfaces
We can also configure the network interfaces using the ifconfig command i.e. we can assign an IP address, netmask & broadcast address using ifconfig.
To assign an IP address to interface using ifconfig, the command is
$ ifconfig eth0 192.168.5.45
Next we will assign the netmask for assigned IP address & command to do it is
$ ifconfig netmask 255.255.240.0
Lastly to assign a broadcast address, command is
$ ifconfig broadcast 192.168.5.255
We can also combine all these command into a single command to configure all the network information in one go. We can however can’t configure gateway & DNS using ifconfig command.
To assign a gateway, run the following command,
$ route add default gw 192.168.5.10
& to add DNS, execute
$ echo “nameserver 22.214.171.124” > /etc/resolv.conf
Creating an alias or assigning multiple IP to an interface
We can also assign multiple IP addresses to a single interface using ifconfig, this process is also known as IP aliasing. To accomplish this, we need to execute the following command,
$ ifconfig eth0:1 192.168.5.50 netmask 255.255.240.0 broadcast 192.168.5.255
& if we want to remove the IP address to an alias, we can simply bring down the interface using
$ ifconfig eth0:1 down
We have also discussed IP aliasing in a more detail in our tutorial ASSIGNING MULTIPLE IP TO A SINGLE NIC.
This tutorial covers the most used functionalities that ifconfig provides, though there are plenty more options that can be used with ifconfig but that’s a topic for another day. Please do let us know if there are topics that you would like us to cover or if you have any queries, mention them in the comment box below.