How to Install and Use ifconfig on CentOS and Rocky Linux

December 23, 2024

Introduction

One of the most common ways to configure a network interface in Linux is using the ifconfig command. The command comes preinstalled on many Linux distributions. However, it has been deprecated in some Rocky Linux and CentOS versions, so they no longer include it by default.

In this tutorial, you will learn how to install and use ifconfig on CentOS and Rocky Linux.

How to install and use the ifconfig command on CentOS and Rocky Linux - a tutorial.

Prerequisites

How to Install the ifconfig Command

Before installing the ifconfig command, check if it is already installed on your system. Run:

ifconfig

If the command outputs information about network interfaces, then it is already installed and you can refer to our tutorial to see how to use the ifconfig command. If the output states "command not found, " follow the steps below to install it.

The ifconfig command is part of the net-tools package available in the YUM repository. Follow the steps below to install net-tools:

1. Open the terminal window and update the existing packages on your system:

sudo yum update -y

Wait for the process to complete.

2. Next, download and install net-tools with yum:

sudo yum install net-tools -y
Installing the net-tools package using the yum package manager in Rocky Linux.

The output confirms the installation is complete.

Note: Distributions that have deprecated ifconfig encourage users to use the ip command instead. To read more about ip, see how to use the IP command in Linux.

Using the ifconfig Command

The ifconfig command is versatile. Some of its capabilities are to:

  • Display information about the system's network configuration.
  • Enable or disable a network interface.
  • Assign IP addresses, netmask, and broadcast to network interfaces.
  • Change the MAC address.
  • Change the maximum transmission unit (MTU).
  • Create network interface aliases.
  • Enable or disable promiscuous mode.

Display Network Configuration Information

Run ifconfig without arguments to display information about the current network interfaces. The output shows all the essential information for the active network interfaces, including:

  • The hardware MAC address.
  • IP addresses (inet).
  • Netmasks.
  • Broadcast addresses.
  • Information on whether the interface is up or down.
Example of the ifconfig command output.

To see all the interfaces, including the inactive ones, add the -a argument:

ifconfig -a

In the example below, the output shows two active and one inactive interface:

Using ifconfig with -a option to see both active and inactive interfaces on Rocky Linux.

To see information about a specific interface, append the interface name to the command:

ifconfig [interface_name]

The output displays information for the specified interface:

Using ifconfig to check a particular network interface.

Enable or Disable a Network Interface

Enable a network interface with the following syntax:

sudo ifconfig [interface_name] up

For example:

sudo ifconfig enp0s8 up

The command does not produce any output. However, running ifconfig shows that the list of active connections now includes enp0s8:

A previously inactive interface showing up as active after using the ifconfig command.

The syntax to disable an interface is:

sudo ifconfig [interface_name] down

Assign the IP Address, Netmask, and Broadcast

The ifconfig command allows you to configure a network interface's IP address, netmask, and broadcast values:

  • Assign an IP address with ifconfig using the following syntax:
sudo ifconfig [interface_name] [IP_address]
  • To assign a new netmask value, type:
sudo ifconfig [interface_name] netmask [netmask_value]
  • Assign a new broadcast by using:
sudo ifconfig [interface_name] broadcast [broadcast_value]

Alternatively, you can assign all the values in one line:

sudo ifconfig [interface_name] [IP_address] netmask [netmask_value] broadcast [broadcast_value]

Run the ifconfig command to verify the output displays the new values:

Output from ifconfig after changing IP address, netmask and broadcast in one line.

Change the Network Interface MAC Address

The MAC address is a unique identifier of a device on a network. To change the MAC address of a network interface, type:

sudo ifconfig [interface_name] hw ether [MAC_address]

The ifconfig command output shows the change in the MAC configuration:

Changing the MAC address using the ifconfig command.

Change the Network Interface MTU

The maximum transmission unit (MTU) is the largest packet or frame size that can be sent over the network. The default MTU is 1500.

Increase the network MTU to increase the data transfer rate.

To change the MTU value with ifconfig, use the following syntax:

sudo ifconfig [interface_name] mtu [MTU_value]

Check the ifconfig output to confirm the change:

Changing the MTU value with ifconfig to increase data transfer rate.

Create Network Interface Aliases

To associate more than one IP address with a single network interface, use IP aliases. The ifconfig command allows aliases, with the condition that their IP addresses belong to the same netmask.

An alias name consists of the main interface name and the alias number, separated by a colon. To create an alias, type:

sudo ifconfig [alias_name] [alias_address]

Check whether the alias was created successfully with ifconfig:

Creating a network alias with ifconfig on Rocky Linux.

To remove an alias, use the syntax below:

sudo ifconfig [alias_name] down

Enable or Disable Promiscuous Mode

Promiscuous mode allows a network device to intercept and read each network packet that arrives in its entirety. It is often used to monitor network activity.

Enable promiscuous mode by typing:

sudo ifconfig [interface_name] promisc

Check if the promiscuous mode is active with ifconfig:

Activate promiscuous mode with ifconfig on Rocky Linux.

To disable promiscuous mode, use the command:

sudo ifconfig [interface_name] -promisc

Note: For a complete list of ifconfig commands, use the man command:

man ifconfig

Conclusion

This article provided instructions for installing and using the ifconfig command on CentOS and Rocky Linux. Furthermore, it presented a list of common ifconfig commands for network interface management.

Next, learn how to monitor network traffic in Linux or how to use the Nmap network scanner.

Was this article helpful?
YesNo
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
How to Test Network Speed in Linux via CLI
November 25, 2020

This article shows you numerous ways to test network speed in Linux via CLI. Learn how to install and use...
Read more
How to Change or Set Hostname on CentOS 8 / RHEL 8
August 10, 2020

If you decide to change your hostname, you have multiple available options to do so. Follow the methods in...
Read more
How to Configure CentOS Network Settings
December 25, 2024

Configure CentOS network settings using the command line or the Network Manager TUI. This guide shows you how...
Read more
Linux Commands Cheat Sheet: With Examples
November 2, 2023

A list of all the important Linux commands in one place. Find the command you need, whenever you need it or...
Read more