Linux ifconfig command

ifconfig (interface configuration) is a network management tool. It is used to configure and view the status of 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 will look at how to use the ifconfig command.

How to install ifconfig

The ifconfig command has been deprecated, replaced with ip in newer Linux distributions, and may not be included in them.

If you receive the error “ifconfig: command not found”, it means that the package containing the command is not installed on your system.

Install ifconfig on Ubuntu / Debian

On Ubuntu and Debian 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 distributions, type:

sudo dnf install net-tools -y

How to use ifconfig command

The basic syntax for the ifconfig command is shown below:

ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]

Where:

  • interface is the name of the network interface.
  • address – the IP address you want to assign.

The configurations set with the ifconfig command are not permanent. After restarting the system, all changes are lost. To make the changes permanent, you need to edit the configuration files for a specific distribution or add commands to the startup script.

Root or privileged users only sudo can configure network interfaces.

Displaying information about network interfaces

When called without any options, ifconfig displays configuration information for all network interfaces and the 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 configuration information for any particular network interface, write the interface name after the command:

ifconfig eth0

The result 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 the network interface

With the ifconfig command, you can assign an IP address and netmask to a network interface.

Use the following syntax to assign an IP address and netmask:

ifconfig [interface-name] [ip-address] netmask [subnet-mask]

For example, to assign IP address 192.168.0.101 and netmask 255.255.0.0 on interface eth0, you would run:

ifconfig eth0 192.168.0.101 netmask 255.255.0.0

You can also assign an additional IP address to the network interface using the interface alias:

ifconfig eth0:0 192.168.0.102 netmask 255.255.0.0

Enabling and disabling 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 the network interface.

To disable the active network interface, enter the device name and set the down checkbox:

ifconfig eth0 down

To enable an inactive network interface, use the up flag:

ifconfig eth0 up

Enabling and disabling promiscuous mode

Messy allows the network interface to access and view all packets on the network. You can use the ifconfig command to enable or disable promiscuous communication on a specific network device.

To enable promiscuous mode on the network interface, enter the promisc flag after the device name:

ifconfig eth0 promisc

To disable promiscuous mode, use the -promisc flag

ifconfig eth0 -promisc

Change MTU of network interface

MTU “Maximum Transmission Unit” allows you to limit the size of packets transmitted over the interface.

You can change the MTU value using the syntax:

ifconfig [interface-name] mtu [mtu-value]

For example, to set the MTU value of the eth0 network interface to 500, run the following command:

ifconfig eth0 mtu 500

Change the MAC address of the network interface

MAC “Media Access Control” is a physical address that uniquely identifies devices on a network.

To change the MAC address of a network interface, use the hw ether flag to set a new MAC address:

ifconfig eth0 hw ether 00:00:2d:3a:2a:28

Conclusion

We showed you how to use the ifconfig command to configure and display network interface information. For more information on ifconfig, visit the ifconfig command manual page.

If you have any questions, please leave a comment below.

Related Posts