The “ifconfig” Command in Linux [6+ Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The ifconfig command in Linux stands for “Interface Configuration”. It configures the necessary kernel-resident network interfaces at the system boot. Users can also apply this command to configure interfaces as per their needs. In this article, I will illustrate the basic usage of the ifconfig command in Linux.

A. Description

The ifconfig command in Linux is used to configure a network interface. If no argument is passed it lists all the active interfaces on a system.

B. Syntax

The syntax of the ifconfig command in Linux is really simple as it contains the command itself and single or multiple options. The syntax is given below.

ifconfig [OPTION]...
Note: In the above syntax OPTION enclosed by square brackets indicates that it is not mandatory and the 3 dots after the brackets represent that multiple OPTIONs can be utilized at the same time

C. Options

Many useful options are available for the ifconfig command. I have listed some of the most used ones here. However, to learn more about the ifconfig command you can always check the man page.

man ifconfig

Useful Options

  • -a: Displays all available interfaces including down ones.
  • address: Indicates the IP address to be assigned to an interface.
  • -s: Displays a short list of active interfaces.
  • -v: Displays verbose output for error conditions.
  • interface: Indicates specified interface.
  • up: Activates an interface.
  • down: Shuts down an interface.
  • mtu N: Sets the Maximum Transfer Unit (MTU) of an interface.
  • [-]arp: Enables or disables the promiscuous mode of the interface.
  • [-]promisc: Enables or disables the promiscuous mode of the interface.
  • add addr/prefixlen: Adds an IPv6 address to an interface.
  • del addr/prefixlen: Removes an IPv6 address from an interface.
Note: The options in Linux CLI (Command Line Interface) are all case-sensitive, So be cautious while using them

Installing the “ifconfig” Command in Linux

The ifconfig command may not be readily installed on your machine. You can find out whether you have it on your system or not by typing the command ifconfig itself.

ifconfig

Your system will print out the following message if you do not have it installed:Showing error message upon not finding the ifconfig command in linux.

In this case, don’t be overwhelmed. The ifconfig command comes with the net-tools package. You can install the net-tools package within a minute by following the instructions below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal

➋ Type the following in your command prompt:

sudo apt install net-tools

➌ Type your password

➍ Now, press ENTER

Output >

Upon completion of these four steps, ifconfig will be installed on your machine.Installing ifconfig command in linux.

Practical Examples of the “ifconfig” Command in Linux

The ifconfig command in Linux is a command that enables users to configure network interfaces. Some of the most useful applications of the ifconfig command have been illustrated below.

Example 1: Displaying Information on All Network Interfaces Available on the System

You can display information on all networks connected to your system using the ifconfig command in Linux. You will need to use the option –a to get this output. In this example, I will display all the interfaces available on my system. Follow the instructions below to do the same.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ifconfig -a

➌ Now, press the ENTER button.

Output >

In the given image, you can see that I have displayed all the network interfaces on my system.Displaying Information on All Network Interfaces Available on the System.


Similar Readings


Example 2: Displaying a Short  List of Active Network Interfaces Using the “ifconfig” Command in Linux

You can display a short list of all the active network interfaces using the ifconfig in Linux with the option -s. In this example, I will list the interfaces on my system. You can do the same by following the steps below.

Steps to Follow >

➊ Open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ifconfig -s

➌ Press the ENTER button.

Output >

In the image below, you can see that I have displayed a short list of the active interfaces.Displaying a Short  List of Active Network Interfaces.

Example 3: Assigning IP Address to an Interface Using the “ifconfig” Command in Linux

You can add a new IP address to your available network device using the ifconfig command in Linux. You must run the command as the superuser using the sudo keyword to achieve this task. The IP address needs to be mentioned after the specified interface. In this example, I will add the address 192.168.242.240 to the ens33 network on my system. You can do so by following the process below:

Steps to Follow >

➊ At first, launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ifconfig ens33 192.168.242.240

➌ Now, hit the ENTER button.

Output >

In the image below, you can see that I have added the desired IP address to the ens33 interface. You can again use the ifconfig command along with the interface name to view the updated IP address.Assigning IP Address to an Interface Using the ifconfig Command in Linux.

Example 4: Altering Status of Network Interfaces Using the “ifconfig” Command in Linux

You can alter the network interface status from your terminal using the ifconfig command in Linux. You can bring an interface up or down by running commands as a superuser using the sudo command. To do so, you will need to use the options up or down after a specific interface name. Follow the below examples to change the statuses separately.

Case A: Bringing an Interface Up Using the “ifconfig” Command in Linux

To bring an interface up follow the given steps.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ifconfig ens33 up

➌ Now, press the ENTER button.

➍ To view the updated status write the following command:

ip link show dev ens33

➎ Again, press ENTER.

Output >

In the image below, you can see that I have changed the interface status to UP.Bringing an Interface Up Using the ifconfig Command in Linux.

Case B: Bringing an Interface Down Using the “ifconfig” Command in Linux

To bring an interface down follow the given steps.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ifconfig ens33 down

➌ Now, press the ENTER button.

➍ To view the updated status write the following command:

ip link show dev ens33

➎ Again, press ENTER.

Output >

In the following image, you can see that I have changed the interface status to DOWN.Bringing an Interface Down Using the ifconfig Command in Linux.

Example 5: Setting MTU size Using the “ifconfig” Command in Linux

You can set the Maximum Transfer Unit of an interface using the mtu option with the ifconfig command in Linux. In this example, I will set the transfer unit of the “ens33” interface to 500. To do the same, you can go through the following steps.

Steps to Follow >

➊ At first, launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ifconfig ens33 mtu 500

➌ Hit ENTER.

Output >

In the given image, you can see that I have set the mtu amount to the desired value of 500. I again used the ifconfig command along with the interface name to view the updated mtu value.Setting MTU size Using the fconfig Command in Linux.


Similar Readings


Example 6: Enabling/Disabling Promiscuous Mode Using the “ifconfig” Command in Linux

You can enable or disable the promiscuous mode of an interface using the ifconfig command in Linux. To do so you have to use the promisc option with or without the “” to enable or disable the mode. Follow the below examples to achieve the two different modes.

Note: The promiscuous mode of an interface accepts all the incoming packets in the network flow. In general, when this mode is disabled, an interface only accepts packets that are verified and belong to the interface. It drops the other packets that are not verified. But in the promiscuous mode, it will capture all broadcasting packets

Case A: Enabling Promiscuous Mode Using the “ifconfig” Command in Linux

To enable the promiscuous mode of an interface, follow the given steps.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ifconfig ens33 promisc

➌ Hit ENTER button.

Output >

In the following image, you can see that I have enabled the promiscuous mode for the interface “ens33”. You can again use the ifconfig command along with the interface name to view the updated status.Enabling Promiscuous Mode Using the ifconfig Command in Linux.

Case B: Disabling Promiscuous Mode Using the “ifconfig” Command in Linux

To disable the promiscuous mode of an interface follow the given steps.

Steps to Follow >

➊ At first, go to the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo ifconfig ens33 -promisc

➌ Press ENTER.

Output >

In the given image, you can see that I have disabled the promiscuous mode for the interface “ens33”. You can again use the ifconfig command along with the interface name to show you the updated status.Disabling Promiscuous Mode Using the ifconfig Command in Linux.

Conclusion

This article presents the most frequent uses of the ifconfig command in Linux. Exercising the provided hands-on examples, you will be able to configure network interfaces along with viewing their information. I hope the demonstrations aid your experience in the command line and help you become a power user of Linux.


Similar Readings

Rate this post
Anonnya Ghosh

Hello there! I am Anonnya Ghosh, a Computer Science and Engineering graduate from Ahsanullah University of Science and Technology (AUST). Currently, I am working as a Linux Content Developer Executive at SOFTEKO. The strong bond between Linux and cybersecurity drives me to explore this world of open-source architecture. I aspire to learn new things further and contribute to the field of CS with my experience. Read Full Bio

Leave a Comment