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 order is censured and supplanted with ip and may not be remembered for the more current 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 Debian
Run the following command to install ifconfig:
sudo apt install net-tools -y
Install ifconfig on Centos
On CentOS and other RHEL based Linux distros, type:
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
- 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 is not permanent. After a 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.
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.10 and netmask 255.255.0.0 to the interface eth0, you would run:
ifconfig eth0 192.168.0.10 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.11 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