How to Install and Use ifconfig on CentOS 7

January 12, 2021

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, certain distributions like CentOS 7 have deprecated the command and do not include it by default anymore.

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

How to Install and Use ifconfig on CentOS 7

Prerequisites

  • CentOS 7 installed
  • Access to the command line/terminal window
  • Access to root or user with sudo privileges

How to Install the ifconfig Command

The ifconfig command is part of the net-tools package available in the YUM repository.

1. Open the terminal window and update the repositories:

sudo yum update

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

sudo yum install net-tools -y

The output confirms the installation is complete.

Installing the net-tools package using the yum package manager in CentOS 7

Note: Distributions that have deprecated ifconfig encourage users to use the ip command instead. To read more about ip, refer to How to Use IP Command in Linux with Examples.

Using the ifconfig Command

The ifconfig command is versatile. It can:

  • Display information about the system’s network configuration.
  • Enable or disable a network interface.
  • Assign IP addresses, netmasks, and broadcasts 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

When used without arguments, ifconfig displays 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
  • and whether the interface is up or down
Using ifconfig without any arguments in CentOS 7

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 in CentOS 7

To see information about a specific interface, add 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 by using the following syntax:

sudo ifconfig [interface-name] 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 for disabling an interface is:

sudo ifconfig [interface-name] down

Assign the IP Address, Netmask, and Broadcast

Assign an IP address with ifconfig using the command:

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 running:

sudo ifconfig [interface-name] 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

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

sudo ifconfig [interface-name] [IP-address] netmask [netmask-value] broadcast [broadcast-value]
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 output from the  ifconfig command 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 size of a packet or a frame that can be sent over the network. The default MTU is 1500.

Increasing the MTU of the network increases 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:

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 number of the alias, separated by a colon. To create an alias, type:

sudo ifconfig [alias-name] [alias-address]

Check whether the alias was created successfully with ifconfig:

Confirming the successful creation of a network interface alias in CentOS 7

To remove an alias, run the following command:

sudo ifconfig [alias-name] down

Enable or Disable Promiscuous Mode

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

Enable promiscuous mode by typing:

sudo ifconfig [interface-name] promisc

Check if promiscuous mode is active with ifconfig:

Confirming a successful activation of promiscuous mode for a network interface in CentOS 7

To disable promiscuous mode, use the command:

sudo ifconfig [interface-name] -promisc

Note: For a complete list of ifconfig commands, type man ifconfig.

Conclusion

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

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
March 25, 2020

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