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.

Table of Contents
    Linux Ifconfig Command: How to Use It image 1

    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 that sudo is required for installing ifconfig and enabling or disabling networks.

    Linux Ifconfig Command: How to Use It image 2

    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.

    Linux Ifconfig Command: How to Use It image 3

    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.

    Linux Ifconfig Command: How to Use It image 4

    However, both of these versions don’t include currently inactive networks. To view all network interfaces, use the ifconfig -a command instead.

    Linux Ifconfig Command: How to Use It image 5

    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

    Linux Ifconfig Command: How to Use It image 6

    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.

    Linux Ifconfig Command: How to Use It image 7

    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 29.95.245.112

    Linux Ifconfig Command: How to Use It image 8

    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

    Linux Ifconfig Command: How to Use It image 9

    The syntax for setting a broadcast address is similar:

    sudo ifconfig dummy0 broadcast 77.40.108.115

    Linux Ifconfig Command: How to Use It image 10

    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.

    Linux Ifconfig Command: How to Use It image 11

    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 69.72.169.2

    Linux Ifconfig Command: How to Use It image 12

    You can confirm that it worked by using ifconfig to get its status.

    ifconfig dummy0:0

    Linux Ifconfig Command: How to Use It image 13

    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.

    Linux Ifconfig Command: How to Use It image 14

    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.

    Leave a Reply

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