ifconfig Command – Linux Network Management With Examples – POFTUT

ifconfig Command – Linux Network Management With Examples


ifconfig command is a very old and popular tool used to manage Linux, Unix, BSD systems network. Current this command alternative is IP tools commands but ifconfig popularity remains. Ifconfig command can create an interface, network address, link or interface up, link or interface down, etc. We will look in this tutorial popular features and usage examples of Linux ifconfig command.

View All Network Configuration

Generally, the first step after connecting a new server is looking at its network configuration. Without providing any parameters to the ifconfig will print out all network configuration of the Linux system. This will list all active network interfaces configuration.

$ ifconfig
View All Network Configuration
View All Network Configuration

Display All Network Interfaces

Previously we have listed all network configuration of active network interfaces. If we want to get information about inactive or disabled network interfaces we should provide -a parameter to ifconfig command like below.

$ ifconfig -a
Display All Network Interfaces
Display All Network Interfaces

View Network Settings of Specific Interface

Servers generally have more than one interface and some times interface count of Linux system can exceed 10. In these situations looking specific network interface configuration can become a hard job for us. Ifconfig can get specific interface name to list only its configuration.

$ ifconfig ens3
View Network Settings of Specific Interface
View Network Settings of Specific Interface

Disable Network Interface

Network interfaces can be enabled or disabled according to the situation. To enable or disable an interface user need root privileges. Disable a network interface will shut down the interface and clear all configuration about it.

$ sudo ifconfig lxcbr0 down
Disable Network Interface
Disable Network Interface

As we see in the flags line the interface have no keyword like UP which means it is down.

LEARN MORE  How To Get Linux Network IP Address In Different Ways ?

Enable Network Interface

Enabling a disabled network interface is similar to the disabling it. We will just provide up option with the interface name to the ifconfig.

$ sudo ifconfig lxcbr0 up
Enable Network Interface
Enable Network Interface

Assign IP Address To Network Interface

Assigning an IP address to the network interface in Linux is easy with ifconfig. After assigning the IP address to the interface the address can be used for operations. Keep in mind that this will remove current IP address and set new address so if you connected over the network will be hang.

$ sudo ifconfig ens3 192.168.122.201

Assign Netmask To Network Interface

Assigning netmask is similar to the IP address but we will provide the netmask keyword to the ifconfig like below.

$ sudo ifconfig ens3 netmask 255.255.255.0

Assign Broadcast Address To Network Interface

The broadcast address is used to announce to all hosts in the same network. Broadcast addresses generally used the last IP address in the network segment. But if it is different from last IP address we can set broadcast IP address with ifconfig like below.

$ sudo ifconfig ens3 broadcast 255.255.255.0

Assign IP, Broadcast and Netmask Address To Network Interface

Previous there examples we have looked at different operations to set interface configuration. These configurations are generally done in a single shot command like below. If we want to set an IP address, netmask and broadcast address in single ifconfig command we will use the following example syntax.

$ sudo ifconfig ens3 192.168.122.201 netmask 255.255.255.0 broadcast 192.168.122.255

As we see in the command we provide first interface name and then the IP address. After those, we provide netmask keyword and netmask value and the last one the broadcast keyword and address is provided.

LEARN MORE  How To Check If Port Is Open In Linux?

Change MTU for Network Interface

MTU is used the term Maximum Transmission Unit. MTU sets the size of IP packets those travels on networks. The default value for MTU is 1500 but this can provide some bottlenecks so the MTU can be changed to 1000 to solve problems. Packets those IP and upper-layer data bigger than 1000 byte will not transmit. Here is how to set MTU with ifconfig.

$ sudo ifconfig ens3 mtu 1000
Change MTU for Network Interface
Change MTU for Network Interface

As we see ens3 network configuration the MTU value is set to 1000

Enable Promiscuous Mode

Operating systems network stacks filter out packets those are designated different IP address than its own. This means that is a packet designated 192.168.122.5 IP address comes to 192.168.122.10 this packet is dropped by default. But there is a configuration to accept these packets. It is called promiscuous mode. When promiscuous mode is enabled all packets are received by the network protocol stack.

$ sudo ifconfig ens3 promisc
Enable Promiscuous Mode
Enable Promiscuous Mode

As we see ens3 configuration have a feature named PROMISCUOUS in the first line of configuration.

Disable Promiscuous Mode

Disabling promiscuous mode is very easy. Just provide minus before promisc option.

$ sudo ifconfig ens3 -promisc
Disable Promiscuous Mode
Disable Promiscuous Mode

Add Second IP To Network Interface

Linux operating system has the ability to set multiple IP addresses into a single interface. The only restriction about IP address is that alternative IP addresses must be in the same network. This operation is called as adding a new alias to the network interface.

$ sudo ifconfig ens3:1 192.168.122.201
Add Second IP To Network Interface
Add Second IP To Network Interface

Remove the Second IP From Network Interface

Removing alias or alternative IP addresses can be done like below.

$ sudo ifconfig ens3:1 down
Remove Second IP From Network Interface
Remove the Second IP From Network Interface

Change MAC Address of Network Interface

MAC addresses are assigned by the hardware manufacturer. Generally known as unchangeable but in the network stack, MAC addresses can be changed. Use the following command to change the MAC address.

$ sudo ifconfig ens3:1 hw ether 52:54:00:17:23:1e
Change MAC Address of Network Interface
Change MAC Address of Network Interface

1 thought on “ifconfig Command – Linux Network Management With Examples”

Leave a Comment