One of many useful commands to master as an administrator of Linux systems is the ifconfig command. Ifconfig command is used to configure network interfaces. Ifconfig is used to initialize the network interface and to enable or disable the interfaces.
Here are several common usages of ifconfig command.
View Network Settings of an Ethernet Adapter
Ifconfig, when invoked with no arguments will display all the details of currently active interfaces. If you give the interface name as an argument, the details of that specific interface will be displayed.
$ ifconfig eth0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.102.21.76 netmask 255.255.254.0 broadcast 10.102.21.255 ether 00:1e:4f:98:76:df txqueuelen 1000 (Ethernet) RX packets 1633574 bytes 1109841880 (1.0 GiB) RX errors 0 dropped 343 overruns 0 frame 0 TX packets 189136 bytes 16446062 (15.6 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 21 memory 0xfebe0000-fec00000
Display Details of All interfaces
$ ifconfig -a
Assign 192.168.1.3 as the IP address for the interface eth0
$ sudo ifconfig eth0 192.168.1.3
Change Subnet mask of the interface eth0
$ sudo ifconfig eth0 netmask 255.255.255.0
Change Broadcast address of the interface eth0
$ sudo ifconfig eth0 broadcast 192.168.1.255
Assign ip-address, netmask and broadcast at the same time to interface eht0
$ sudo ifconfig eth0 192.168.1.3 netmask 255.255.255.0 broadcast 192.168.1.255
Take Down an Interface
$ ifconfig eth0 down
Bring Up an Interface
$ ifconfig eth0 up
This will change the Maximum transmission unit (MTU) to XX. MTU is the maximum number of octets the interface is able to handle in one transaction. For Ethernet the Maximum transmission unit by default is 1500. This usually will get change to correct netork communication issues. In this example we are changing the MTU to 1480.
$ sudo ifconfig eth0 mtu 1480
Some Un-Common Uses
Set NIC to Promiscuous mode
By default when a network card receives a packet, it checks whether the packet belongs to itself. If not, the interface card normally drops the packet. But in promiscuous mode, the card doesn’t drop the packet. Instead, it will accept all the packets which flows through the network card. This is very useful in troubleshooting connection issues.
$ sudo ifconfig eth0 promisc
Remove NIC from Promiscuous mode
$ sudo ifconfig eth0 -promisc
As you can see ifconfig is a very handy tool to have knowledge as a Linux administrator and is easy and quick to manage your systems.