ifconfig command

The ifconfig command is a very popular tool available on most Linux distros. The name “ifconfig” comes from “Interface Configuration”, it is used to check our system’s network interface and we can also use it to change some of the network interface settings.

By using ifconfig we can quickly take a look at the different settings of our network interface, change them and even enable and disable them as necessary. And today we are going to take a look at how the ifconfig command works, explain a bit more about what it is, the main options available and of course, we are going to check out some usage examples too.


What is ifconfig?

If you are running a Linux distro that is CLI-based (that means, based on a command-line interface), then you need to know how to use ifconfig, because sooner or later you will need this tool to change and view a lot of different settings related to your server’s network interface.

ifconfig has 3 main purposes:

  • View the current network interface settings.
  • Change some of those settings.
  • Enable or disable different network interfaces in our system.

ifconfig command explained

Install ifconfig on CentOS, Ubuntu and Debian

In modern CentOS distros like CentOS 7 and CentOS 8 we can quickly install ifconfig using the system’s package manager, DNF, or the previous version of it, called YUM, can also be used. YUM comes linked to DNF in CentOS 8 so it should work as we were using DNF.

To install ifconfig we will need to install a package called “net-tools” and for doing this we need a user capable of using sudo commands. Another possibility is to use the root user, so pick whichever is available to you and executed the following to install ifconfig in CentOS:

yum install net-tools

And that is all, just type ‘y’ or ‘yes’ when the prompt asks for permission to install the desired software.

On Debian and Ubuntu, if you get an ifconfig: command not found error, you can install the ifconfig command by typing the following command:

apt-get install net-tools

That’s it.

How to use the ifconfig command

The most basic function of ifconfig is to check out the network interface settings, this can quickly be done by running the following command in our CLI:


The output will display all of the currently active network interfaces in the system. But wait for a second, what if I have other network interfaces but those are currently disabled? Is there a way to view them? Of course, to do that you just have to add the -a option to the previous command:

ifconfig -a

And what if you only want to see the current settings of one particular network interface? Let’s assume that we have 3 network interfaces called eth0, eth1, and eth2. How can we view only the settings of interface eth1? That is pretty easy, we just need to run ifconfig and add the interface’s name after it, so for eth1 the correct command would be:

ifconfig eth1

Now, if you want to enable one interface there is a quick way to do it thanks to ifconfig, we just need to add an “up” option to the previous commando, so for example, if eth2 is disabled, then we can quickly enable it this way:

ifconfig eth2 up

And what about disabling it? It works the same way, but instead of “up” we will have to use the “down” option, so if you want to disable eth0 you should use this command:

ifconfig eth0 down

Before doing this make sure you are picking the right interface, because you may accidentally bring down the server’s main network interface if you get the wrong interface name, and that, of course, won’t be good.

There are a few more things that we can do with the ifconfig command. If we want to assign a particular IP address to a particular network interface, then we can do it in a second. In the following example we will add IP to the interface called “eth1”:

ifconfig eth1

We can also assign a netmask, so let’s see an example where we assign netmask

infconfig netmask

Pretty easy, right? But there’s more. What about adding a broadcast address? Yeah, we can do that too using ifconfig, in this example we will use

ifconfig broadcast

But wait, is there a better way to do all of this instead of using three different commands? Yes, there is, we can combine the three of them in one single command, which based on our previous examples will look like this:

ifconfig eth1 netmask broadcast

That makes it a lot faster, don’t you think?

ifconfig command options explained

There are a few more options available for ifconfig, let’s take a look at those that are used the most:

-a: this option let us see all the network interfaces, not just those that are enabled.

-s: with this option we're going to be able to view a short list of all the network interfaces.

-v: displays additional verbose data

apr: this option is used to enable ARP in the selected interface.

mtu N: with this option we will be able to ser the maximum MTU for the interface. 'N' is the desired MTU.


And that’s pretty much it for the ifconfig command. As you can see you can use this great tool to do different things like checking network interfaces, you can change their settings and also enable or disable the interfaces as you need, all directly from your command-line interface with just a few commands.

Further reading:

About the Author: Santiago Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.

Leave a Reply

Your email address will not be published. Required fields are marked *