Posted on July 21, 2023 by nexonhost
How to use Linux ifconfig Command
ifconfig (interface configuration) is a network management tool. It is used to configure and view the status of the network interfaces in Linux operating systems. With ifconfig, you can assign IP addresses, enable or disable interfaces, manage ARP cache, routes, and more.
How to Install ifconfig
The ifconfig command is deprecated and replaced with ip and may not be included in the newer Linux distributions.
If you get an error message saying “ifconfig: command not found”, it means that the package that contains the command is not installed on your system.Install ifconfig on Ubuntu/Debian
On Ubuntu and Debian-based based Linux distributions, run the following command to install ifconfig:
- sudo apt install net-tools -yInstall ifconfig on Centos
To install ifconfig on CentOS and other RHEL based Linux distros, type:
- sudo dnf install net-tools -y
How to Use the ifconfig Command
The basic syntax of the ifconfig command is shown below:
- ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
Where:
- interface – is the name of the network interface.
- address – is the IP address that you want to assign.
The configurations set with the ifconfig command are not persistent. After a system restart, all changes are lost. To make the changes permanent, you need to edit the distro-specific configuration files or add the commands to a startup script.
Only root or users with sudo privileges can configure network interfaces.
Display Information of Network Interfaces
When invoked without any options, ifconfig displays the configuration information of all network interfaces and associated ip address:
- ifconfig -a
The output includes information about all active and inactive network interfaces:
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 89.41.179.2 netmask 255.255.255.0 broadcast 89.41.179.255
- inet6 fe80::216:3eff:feb0:809e prefixlen 64 scopeid 0x20<link>
- ether 00:16:3e:b0:80:9e txqueuelen 1000 (Ethernet)
- RX packets 1674979566 bytes 869825180281 (810.0 GiB)
- RX errors 0 dropped 450 overruns 0 frame 0
- TX packets 192746341 bytes 119566822624 (111.3 GiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
- inet 127.0.0.1 netmask 255.0.0.0
- inet6 ::1 prefixlen 128 scopeid 0x10<host>
- loop txqueuelen 1000 (Local Loopback)
- RX packets 458227 bytes 77272468 (73.6 MiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 458227 bytes 77272468 (73.6 MiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
To display the configuration information of any specific network interface, write the interface name after the command:
- ifconfig eth0
The output will look something like this:
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 89.41.179.2 netmask 255.255.255.0 broadcast 89.41.179.255
- inet6 fe80::216:3eff:feb0:809e prefixlen 64 scopeid 0x20<link>
- ether 00:16:3e:b0:80:9e txqueuelen 1000 (Ethernet)
- RX packets 1674981941 bytes 869825380277 (810.0 GiB)
- RX errors 0 dropped 450 overruns 0 frame 0
- TX packets 192746711 bytes 119566906746 (111.3 GiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Assign an IP address and Netmask to a Network Interface
With the ifconfig command, you can assign an IP address and netmask to a network interface.
Use the following syntax to assign the IP address and netmask:
- ifconfig [interface-name] [ip-address] netmask [subnet-mask]
For example, to assign the IP address 192.168.0.101 and netmask 255.255.0.0 to the interface eth0, you would run:
- ifconfig eth0 192.168.0.101 netmask 255.255.0.0
You can also assign a secondary IP address to a network interface using the interface aliasing:
- ifconfig eth0:0 192.168.0.102 netmask 255.255.0.0
Enable and Disable a Network Interface
Sometimes, you may need to reset the network interface. In this case, the ifconfig command can be used to enable or disable a network interface.
To disable an active network interface , enter the device name followed by the down flag:
- ifconfig eth0 down
To enable an inactive network interface, use the up flag:
- ifconfig eth0 up
Enable and Disable Promiscuous Mode
Promiscuous allows a network interface to access and view all packets in a network. You can use the ifconfig command to enable and disable the promiscuous on a specific network device.
To enable the promiscuous mode on a network interface, enter the promisc flag after the device name:
- ifconfig eth0 promisc
To disable the promiscuous mode, use the -promisc flag
- ifconfig eth0 -promisc
Change MTU of a Network Interface
The MTU “Maximum Transmission Unit” allows you to limit the size of packets that are transmitted on an interface.
You can change the MTU value using the syntax:
- ifconfig [interface-name] mtu [mtu-value]
For example, set the MTU value of a network interface eth0 to 500, run the following command:
- ifconfig eth0 mtu 500
Change the MAC address of a Network Interface
The MAC “Media Access Control” is the physical address that uniquely identifies the devices on a network.
To change the MAC address of a network interface, use the hw ether flag to set the new MAC address:
- ifconfig eth0 hw ether 00:00:2d:3a:2a:28
Conclusion
We’ve shown you how to use the ifconfig command to configure and display information about a network interface.