Linux Ifconfig Command: How to Use It
Plus when you should use it
In Ubuntu and other Linux distros,command line toolsare 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.
Installing Net-Tools
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 thatsudois 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:
ifconfig eth0
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 withsudo,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 29.95.245.112
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 77.40.108.115
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 ofname:x, wherenameis the network’s name andxa digit. For example, here is how to add an alias IP address to the dummy0 network.
sudo ifconfig dummy0:0 69.72.169.2
You can confirm that it worked by using ifconfig to get its status.
ifconfig dummy0:0
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.
Theofficial man pageshave 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 theman ifconfigcommand.
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.
Levin Roy is a software engineer who loves writing about technology. Whether it is Windows tips-and-tricks or in-depth guides about application development, Levin uses his practical experience and technical skills to create articles that can help solve tricky problems.Read Levin’s Full Bio
Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.
HomeAbout UsEditorial StandardsContact UsTerms of Use
Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved