How To Install And Use Ifconfig On CentOS 7 | phoenixNAP KB

One

of the most common ways to configure a network interface on Linux is to use the ifconfig command. The command comes preinstalled on many Linux distributions. However, certain distributions like CentOS 7 have stopped using the command and no longer include it by default.

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

Prerequisites

  • CentOS 7 installed
  • Accessing the command

  • line window/terminal 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. Then download and install net-tools using yum: sudo yum install net-tools –

y The

result confirms that the installation is complete

. Using the ifconfig command The

ifconfig command is versatile. You can:

Display information

  • about the system’s network settings
  • .

  • 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
  • .

  • Turn promiscuous mode on or off.
  • Display network

configuration information When used without arguments, ifconfig

displays information about the current network interfaces. The output displays all the

essential information for the active network

interfaces, including: the

  • MAC address of the hardware
  • IP addresses (inet)
  • netmasks
  • broadcast addresses
  • and whether the interface

  • is active or inactive

To view all interfaces, including inactive interfaces

, add the -a argument: ifconfig -a

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

To view information about a specific interface, add the

interface name to the command: ifconfig [interface-name] The output

displays information for

the specified 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: The syntax for disabling an interface is: sudo ifconfig [name-interface] down Assign 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 [value-broadcast] Run the ifconfig

command to verify that the output displays the new values: Alternatively, you can assign all values on one line: sudo ifconfig

[interface-name] [IP address] netmask [netmask value] broadcast [broadcast value]

Change

the MAC address

of the network interface 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 of the ifconfig command shows the change in MAC settings:

Change the Network

Interface

MTU

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

Increasing the MTU of the network increases the speed of data transfer.

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, on 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 if the alias was created correctly with ifconfig: To delete 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 every incoming network packet in its entirety. 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:

To disable promiscuous mode, use the command:

sudo ifconfig [interface-name] –

promisc

Conclusion

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