Home // How to use the ifconfig command – The Basics

How to use the ifconfig command – The Basics

0 4 mins read
| Published on: August 6, 2022 | Last updated on: July 31, 2023

The network administration tool ifconfig (interface configuration) Is used in Linux systems to setup and monitor network interfaces. You may use ifconfig to assign IP addresses, activate or disable interfaces, control ARP cache, routes, and other things.

We’ll look at how to utilise the ifconfig command in this tutorial.

How to Setup ifconfig

The command has been deprecated and superseded by ip, thus it may not be present in recent Linux editions.

If you see an error message that says “ifconfig: command not found,” it signifies that the package containing the command is not installed on your system.

Install on Ubuntu/Debian

To install it on Ubuntu and Debian-based Linux systems, use the following command:

sudo apt install net-tools -y

Install on Centos

To install it on CentOS and other RHEL-based Linux distributions, enter:

sudo dnf install net-tools -y

How to Use the ifconfig Command

The fundamental syntax of the ifconfig command is provided below:

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

Where:

  • interface – used to identify a network interface
  • address – is the IP address that you want to assign.

The command’s settings are not durable. All modifications are lost after a system restart. You must update the distro-specific configuration files or add the instructions to a startup script to make the changes permanent.

Network interfaces can only be configured by root or users with sudo access.

Display Network Interface Information

Ifconfig shows all network interfaces’ configuration details and associated IP addresses when run without any options:

ifconfig -a

All active and dormant network interfaces are listed in the output:

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:10.0.0.25  Bcast:10.0.0.255  Mask:255.255.255.0
          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)

After the command, provide the name of the network interface you want to show configuration information for:

ifconfig eth0

This is how the result will appear:

eth0      Link encap:Ethernet  HWaddr 4c:bb:58:9c:f5:55  
          inet addr:10.0.0.25  Bcast:10.0.0.255  Mask:255.255.255.0
          
          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)

Give a network interface a Netmask and an IP address.

You may provide a network interface an IP address and a netmask with the ifconfig command.

The IP address and netmask should be assigned using the syntax shown below:

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

For instance, to give the interface eth0 the IP address 10.0.0.25 and the netmask 255.255.0.0, you would execute:

ifconfig eth0 10.0.0.25 netmask 255.255.0.0

Using interface aliasing, you may also provide a network interface a secondary IP address:

ifconfig eth0:0 10.0.0.26 netmask 255.255.0.0

Enable and Disable a Network Interface

Resetting the network interface could be necessary sometimes. In this situation, a network interface may be enabled or disabled using the ifconfig command.

The device name must be accompanied by the down flag in order to shutdown an active network interface:

ifconfig eth0 down

Use the up flag to activate a dormant network interface:

ifconfig eth0 up

Enable and Disable Promiscuous Mode

A network interface can observe and access all packets on a network thanks to promiscuity. The promiscuous feature on a particular network device may be enabled and disabled using the ifconfig command.

Enter the promisc flag after the device name to activate the promiscuous mode on a network interface:

ifconfig eth0 promisc

To disable the promiscuous mode, use the -promisc flag

ifconfig eth0 -promisc

Change MTU of a Network Interface

You may restrict the size of packets that are sent on an interface using the MTU (“Maximum Transmission Unit”) setting.

The following syntax can be used to modify the MTU value:

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

Run the command below, for instance, to adjust the MTU value of network interface eth0 to 500.

ifconfig eth0 mtu 500

Change the MAC address of a Network Interface

The physical address that specifically identifies the devices on a network is called MAC, or “Media Access Control.”

Use the hw ether flag to set the new MAC address when changing a network interface’s MAC address:

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

Conclusion

You now know how to use the ifconfig command to set up and show information about a network interface. For more information, see the man page for the ifconfig command.

If you have questions, please leave a comment below.

IF YOU ARE HAVING PROBLEMS WITH THIS GUIDE, EMAIL US AT:

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Copyright @2022-2024 All Right Reserved – PCPlanet

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. You understand and give your consent that your IP address and browser information might be processed by the security plugins installed on this site. By clicking “Accept”, you consent to the use of ALL the cookies.
.
Accept Read More

Privacy & Cookies Policy