In Linux, the network interfaces can be configured using different command utilities, and the ifconfig command is the leading utility among them. The ifconfig command is specifically associated with network interfaces of Kernel modules.
In this blog, the installation and usage of the ifconfig command have been explained for all Linux distributions. In this blog, the below-mentioned sections are explained:
- Prerequisites: How to Install ifconfig Command Utility in Linux?
- What is the ifconfig Command Utilityin Linux?
- What is the Usage of the ifconfig Command Utility in Linux?
- Example 1: Display the Network Interfaces
- Example 2: Get the Details of Specific Network Interface
- Example 3: Assign an IP Address
- Example 4: Change the mac Address
- Example 5: Enable or Disable the Network Interface
Let’s start the blog!
Prerequisites: How to Install ifconfig Command Utility in Linux?
There are different distributions of Linux, including Debian-based and CentOS/RHEL-based. The installation method of ifconfig is the same in all distributions, only the difference is in the usage of the package manager.
To install the ifconfig command utility in Debian-based distributions, use the command:
$ sudo apt install net-tools -y
Apart from Debian-based Linux distributions, the ifconfig command can be installed on other Linux distros via the below-mentioned commands:
$ sudo dnf install net-tools -y
For Arch based Distributions:
$ sudo pacman -S net-tools -y
Once the net-tools package has been installed on your Linux distribution, then you are ready to use the ifconfig command.
What is the ifconfig command Utility in Linux?
The ifconfig command is the abbreviation of the “interface configuration” and is used to set or change the settings of the network interfaces. The general syntax of using the ifconfig command:
$ ifconfig [options] interface
The explanation of the general syntax is easy; use the ifconfig with any of its options and the interface address to which you are supposed to make changes.
What are the options of the ifconfig?
There are different options for the ifconfig command, but the basic options are:
|-a||This option is used to display all the network interfaces, whether they are up or down.|
|-s||It displays the short summarize list of network interfaces.|
|-v||Runs the command with details / verbose mode.|
Many other options can be used with the ifconfig command, and to explore them, use the command:
$ man ifconfig
The manual of the ifconfig command has been displayed.
What is the Usage of the ifconfig Command Utility in Linux?
As discussed earlier, the ifconfig command is quite a useful utility for Linux administrators and has multiple usages. This section demonstrates numerous examples representing the usage of this command:
Example 1: Display the Network Interfaces
To display the network interfaces using the ifconfig command, use its “-a” option:
$ ifconfig -a
Similar to the above command, if only a summary of the internet interfaces is required, then use the command:
$ ifconfig -s
The summary of all available internet interfaces is displayed.
Example 2: Get the Details of Specific Network Interface
To display the configuration details of the specific network interface, run the command with its name. For example, we will display the configuration details of the “enp0s3” using the command:
$ ifconfig enp0s3
Example 3: Assign an IP Address
To assign the ip address and the netmask to any network interface, the ifconfig command can be used. To understand this, we will assign the IP address “192.168.0.0” and netmask “255.255.255.0” to the enp0s3 network interface using the ifconfig command:
$ ifconfig enp0s3 192.168.0.0 netmask 255.255.255.0
Example 4: Change the mac Address
We can change the mac address of the network interface using the ifconfig command utility, for example, we assigned the new mac address to enp0s3 using the command:
$ ifconfig enp0s3 hw ether 00:00:2d:3a:2a:28
The MAC address of the enp0s3 network interface has been changed.
Example 5: Enable or Disable the Network Interface
If the resetting of the network interface is required, then first down the network interface using the “down” option:
$ ifconfig enp0s3 down
This will disable the network interface as in our case, the enp0s3 has been disabled. To enable it, run the command:
$ ifconfig enp0s3 up
The network interface has been enabled.
That’s all from this post!
In Linux, the ifconfig command Linux configures the network interfaces of Linux Kernel modules. The ifconfig command can be used to up/down the interfaces, set the IP/NetMask/Mac address of an interface, and much more. This post has briefly explained the working, usage, and installation of the ifconfig command in Linux.