ifconfig Command – Linux Network Management With Examples
ifconfig command is 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 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 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.
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 provides -a parameter to ifconfig command like below.
$ ifconfig -a
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 this situations looking specific network interface configuration can become hard job for us. Ifconfig can get specific interface name to list only its configuration.
$ ifconfig ens3
Disable Network Interface
Network interfaces can be enable or disabled according to the situation. To enable or disable an interface user need root privileges. Disable a network interface will shutdown the interface and clear all configuration about it.
$ sudo ifconfig lxcbr0 down
As we see in the flags line the interface have no keyword like UP which means it is down.
Enable Network Interface
Enabling an disable network interface is similar to the disabling it. We will just provide up keyword with the interface name to the ifconfig.
$ sudo ifconfig lxcbr0 up
Assign IP Address To Network Interface
Assigning 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 network 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 willprovide the netmask keyword to the ifconfig like below.
$ sudo ifconfig ens3 netmask 255.255.255.0
Assign Broadcast Address To Network Interface
Broadcast address is used to announce to all hosts in the same network. Broadcase 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 different operations to set interface configuration. These configurations are generally done in a single shot command like below. If we want to set IP address, netmask and broadcast address in single ifconfig command we will use 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.
Change MTU for Network Interface
MTU is used the term Maximum Tranmission 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 the 1000 to solve problems. Packets those IP and upper layer data bigger than 1000 byte will not transmitted. Here is how to set MTU with ifconfig.
$ sudo ifconfig ens3 mtu 1000
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 enable all packets are received by network protocol stack.
$ sudo ifconfig ens3 promisc
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
Add Second IP To Network Interface
Linux operating system have the ability to set multiple IP addresses into single interface. Only restriction about IP address is that alternative IP addresses must be in the same network. This operation is called as adding new alias to the network interface.
$ sudo ifconfig ens3:1 192.168.122.201
Remove Second IP From Network Interface
Removing alias or alternative IP addresses can be done like below.
$ sudo ifconfig ens3:1 down
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 following command to change MAC address.
$ sudo ifconfig ens3:1 hw ether 52:54:00:17:23:1e