How to use ifconfig in Linux

Introduction

To configure, manage, and query network interface parameters through the command-line interface or in a system configuration script, use the “interface configuration” (abbreviated as “ifconfig”) program on Unix/Linux operating systems.
The “ifconfig” command can display the current network configuration information, configure a network interface’s hardware address, IP address, netmask, or broadcast address, create an alias for the network interface, and enable or deactivate network interfaces.
The “Useful “ifconfig” Commands” and their real-world applications are covered in this article. They could be very useful to you when managing and configuring network interfaces in Linux systems.

View All Network Interface Settings

Without any parameters, the “ifconfig” program will list all the details of the current interfaces. The assigned IP address of a server can also be checked using the ifconfig command.

ifconfig

Display Information for Every Network Interface

The details of any active or inactive network interfaces on the server will be shown by the ifconfig command that follows with the -a argument. The outcomes for eth0, lo, sit0, and tun0 are shown.

ifconfig -a

View the Network Settings for a Particular Interface

When the “ifconfig” command is used with the argument interface name (eth0), the specific network interface’s specifications are shown.

ifconfig eth0

Activating a Network Interface

If a network interface is not in an inactive state, the “up” or “ifup” flag with the interface name (eth0) activates it and enables data transmission and reception. For instance, the eth0 interface can be activated with “ifconfig eth0 up” or “ifup eth0.”

ifconfig eth0 up

Disable a Network Interface

The given network interface is turned down when the “down” or “ifdown” flag is present with the interface name (eth0). For instance, if the eth0 interface is inactive, the command “ifconfig eth0 down” or “ifdown eth0” deactivates it.

ifconfig eth0 down

or

ifdown eth0

Give a Network Interface an IP Address

Use the following command with the interface name (eth0) and desired IP address to allocate an IP address to a particular interface. For instance, “ifconfig eth0 172.18.22.120” will configure interface eth0’s IP address.

ifconfig eth0 172.20.25.120

Assign a Netmask to Network Interface

It is possible to define a netmask for a specific interface by using the “ifconfig” command with the “netmask” option and the interface name (eth0). Ifconfig eth0 netmask 255.255.255.240, for instance, will configure the network mask for the specified eth0 interface.

ifconfig eth0 netmask 255.255.255.240

Assign a Broadcast to Network Interface

The broadcast address for the specified interface will be set when the “broadcast” parameter is used with the interface name. For instance, the command “ifconfig eth0 broadcast 172.16.25.63” changes the interface eth0’s broadcast address to 172.20.25.175.

ifconfig eth0 broadcast 172.20.25.175

Broadcast, Netmask, and Assign an IP to a Network Interface

Use the “ifconfig” command with every option listed below to assign an IP address, Netmask address, and Broadcast address all at once.

ifconfig eth0 172.20.25.120 netmask 255.255.255.240 broadcast 172.18.22.175

Change MTU for a Network Interface

The “MTU” option determines the maximum transmission unit to an interface. By adjusting the MTU, you can control the maximum size of packets transmitted on an interface. A maximum number of octets can be sent to an interface using the MTU in a single transaction.

For instance, the command “ifconfig eth0 mtu 1000” will set the maximum transmission unit to a specified number (i.e., 1000). All network interfaces do not support MTU adjustments.

ifconfig eth0 mtu 1000

Enable Promiscuous Mode

When a network card receives a packet in normal mode, it checks that the packet belongs to that card. However, the promiscuous mode accepts all packets that run via the network card. If not, it drops the packet normally.

The packets that pass across the network interface are captured and examined by modern network tools using the promiscuous mode. Use the following command to set the promiscuous mode.

ifconfig eth0 promisc

Disable Promiscuous Mode

Use the “-promisc” switch to drop back to the network interface in normal mode and disable promiscuous mode.

ifconfig eth0 -promisc

Add New Alias to Network Interface

Using the alias functionality of the ifconfig program, you can configure extra network interfaces. Use the following command to add the alias network interface for eth0. Please be aware that the alias network address belongs to the same subnet mask. For instance, if the eth0 network IP address is 172.16.25.130, the alias IP address must be 172.16.25.137.

ifconfig eth0:0 172.16.25.137

Next, use the “ifconfig eth0:0” command to confirm the network interface address of the newly formed alias.

ifconfig eth0:0

Remove Alias to Network Interface

The following command can be used to eliminate an alias network interface if you no longer need it or if you misconfigured it.

ifconfig eth0:0 down

Modify the Network Interface’s MAC Address

Use the following command with the option “hw ether” to modify an eth0 network interface’s MAC (Media Access Control) address. See the example below.

ifconfig eth0 hw ether CC:BB:F5:DD:MM:FF

Conclusion

These are the most helpful commands for setting network interfaces in Linux. Use the man command “man ifconfig” at the terminal for more details on how to use the ifconfig command.

Leave a Reply

Your email address will not be published.