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.
In this article, we’ll explore how to use the ifconfig
command.
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 -y
Install 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>]
Copy
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:
docker0 Link encap:Ethernet HWaddr 56:84:7a:fe:97:99
inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:4198 errors:0 dropped:0 overruns:0 frame:0
TX packets:4198 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:498729 (498.7 KB) TX bytes:498729 (498.7 KB)
eth0 Link encap:Ethernet HWaddr 4c:bb:58:9c:f5:55
inet addr:172.20.10.3 Bcast:172.20.10.15 Mask:255.255.255.240
inet6 addr: 2401:4900:1d65:40a1:4ebb:58ff:fe9c:f555/64 Scope:Global
inet6 addr: 2401:4900:1d65:40a1:f1c9:6a90:2d99:924e/64 Scope:Global
inet6 addr: fe80::4ebb:58ff:fe9c:f555/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:84110 errors:0 dropped:0 overruns:0 frame:0
TX packets:59727 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70667629 (70.6 MB) TX bytes:20886290 (20.8 MB)
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 Link encap:Ethernet HWaddr 4c:bb:58:9c:f5:55
inet addr:172.20.10.3 Bcast:172.20.10.15 Mask:255.255.255.240
inet6 addr: 2401:4900:1d65:40a1:4ebb:58ff:fe9c:f555/64 Scope:Global
inet6 addr: 2401:4900:1d65:40a1:f1c9:6a90:2d99:924e/64 Scope:Global
inet6 addr: fe80::4ebb:58ff:fe9c:f555/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:84110 errors:0 dropped:0 overruns:0 frame:0
TX packets:59727 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70667629 (70.6 MB) TX bytes:20886290 (20.8 MB)
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]
Copy
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]
Copy
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