Plus when you should use it
In Ubuntu and other Linux distros, command line tools are usually the best way to interact with the inner workings of the computer. The ifconfig command is used for configuring network settings on Linux.
Ifconfig is an older version of the ip command, but many still prefer ifconfig due to its simpler syntax and ease of use. But how exactly do you use ifconfig for network interface configuration? Here is a walkthrough.
The ifconfig command doesn’t come installed into Linux distributions by default. Most system administrators will install the package it belongs to when setting things up, but in some cases, it might be missing on your computer. You can install it easily.
If you try using the ifconfig command on a system that doesn’t have it installed, you’ll get an error message – along with instructions on how to install it. Just enter the command:
sudo apt install net-tools
This will install ifconfig and a few other network configuration utilities. Note that sudo is required for installing ifconfig and enabling or disabling networks.
Viewing Network Information Using ifconfig
The simplest way to use the ifconfig command is to run it directly without any parameters. This brings up information on all active interfaces, including ethernet and wireless connections.
This provides all pertinent information about the network interfaces, including MTU value (Maximum Transmission Unit), IP addresses, and packet history. If you only want the technical specs in a more digestible format with interface names, enter ifconfig -s.
However, both of these versions don’t include currently inactive networks. To view all network interfaces, use the ifconfig -a command instead.
When you already know the name of the networks and only want the status of a particular interface, you can append its name to the ifconfig command. Like this:
Enabling and Disabling Networks With ifconfig
Monitoring the status of running networks isn’t the only thing you can do with ifconfig. You can also use the command to configure almost every aspect of these interfaces, down to the MTU and the masking used.
The simplest use case is to start up or stop networks. You can do this by using the following command:
sudo ifconfig name up
The “name” parameter is the actual name of the network. This can be used to enable any of the inactive interfaces detected using the ifconfig -a command.
To disable a network, just use down instead of up:
sudo ifconfig dummy0 down
This will disable the interface.
Configuring Networks With ifconfig
Modifying any value associated with a network interface is easy. Just remember to prepend the command with sudo, as all these changes require administrator privileges to take effect.
The most common use of this feature is to assign a custom IP address to a network. For example, this is how to give a new IP address to the dummy0 interface:
sudo ifconfig dummy0 22.214.171.124
You can enter any valid IP address after the network name to assign it. You will only get a message if you entered something incorrectly. Otherwise, the change will immediately take effect.
You can also specify a netmask like this:
sudo ifconfig dummy0 netmask 255.255.255.0
The syntax for setting a broadcast address is similar:
sudo ifconfig dummy0 broadcast 126.96.36.199
If you’re looking to modify all these IP addresses for a network, it’s more efficient to lump all the commands together. Like most Linux commands, you can include multiple arguments in the same line.
A network interface can also have one or more aliases. These are specified by the syntax of name:x, where name is the network’s name and x a digit. For example, here is how to add an alias IP address to the dummy0 network.
sudo ifconfig dummy0:0 188.8.131.52
You can confirm that it worked by using ifconfig to get its status.
What Else Can You Do With ifconfig?
The ifconfig command has an extensive list of arguments that you can use to modify many other variables of a network interface. You can enable multicast, set the MTU, and activate promiscuous mode, among other things.
The official man pages have a complete list of all the arguments that can be used with ifconfig, along with a technical definition of what each does. You can, of course, invoke the manual from the terminal itself using the man ifconfig command.
When Should You Use ifconfig?
For most users, there’s little reason to be using the ifconfig command. The automatic settings provided by default are good enough for normal internet usage.
But if you’re a system administrator who wants more granular control over their network interfaces, then ifconfig is just the tool for you. You can use the command upon booting up the system to properly configure network interfaces and then pretty much forget about it.
It’s handy in diagnosing network issues as well since you can query the status of any network interface and configure it. You can use ifconfig to restart networks or even switch technical parameters until it works more smoothly.