How to Use the Linux ifconfig Command
The ifconfig
or Interface configuration is a network configuration utility in Linux and other Unix-like systems that allows us to configure, control, and query TCP/IP network interfaces from the command-line.
Using the ifconfig
command, we can perform an array of network administration operations such as enabling and disabling interfaces, managing ARP cache, managing network routes, and more.
In this tutorial, we will explore how we can work with the ifconfig
command in Linux to perform various network tasks in our Linux systems.
How to Install ifconfig
The ifconfig
command has become deprecated and has been superseded by the ip
command which provides more functionality and performance. This means that it may not be installed by default on your target machine.
You can check if the command is installed by invoking the command:
ifconfig
If the command is not installed, you will get command not found
error:
Command 'ifconfig' not found, but can be installed with:
Installing ifconfig
on Debian-Based Distro
If you are using any Debian-based distribution, you can install the ifconfig
utility as shown in the command below:
sudo apt-get install net-tools -y
Installing ifconfig
on Rocky Linux
If you are on any REHL based distribution, you can use dnf
or yum
commands as shown below:
sudo dnf install net-tools -y
Installing ifconfig
on Arch
On any Arch-based distribution, you can use the command below to install ifconfig
.
sudo pacman -S net-tools
How to use the ifconfig
Command
Once you have the ifconfig
installed, you can invoke it from the terminal to use it. The command syntax is as shown:
ifconfig [-v] interface [aftype] options | address
Where the:
interface
- refers to the name of the network interface you wish to manage.address
- refers to the IP address you wish to assign.
Ifconfig
Show Network Interface Information
If you run the ifconfig
command without any arguments, it should return information about all the network interfaces in your system. This will include information such as the IP address (IPv4 and IPv6), Mac Address, and more.
ifconfig
Example output:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.227.84 netmask 255.255.240.0 broadcast 192.168.239.255
inet6 fe80::215:5dff:fe2a:2889 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:2a:28:89 txqueuelen 1000 (Ethernet)
RX packets 54993 bytes 79711020 (79.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11259 bytes 832608 (832.6 KB)
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 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
To get the network information for a specific address, you can use the ifconfig
followed by the name of the network interface. For example, to show network information for the interface eth0
, you can run the command:
ifconfig eth0
Output:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.227.84 netmask 255.255.240.0 broadcast 192.168.239.255
inet6 fe80::215:5dff:fe2a:2889 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:2a:28:89 txqueuelen 1000 (Ethernet)
RX packets 55021 bytes 79716280 (79.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11259 bytes 832608 (832.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Ifconfig
Assign IP Address
You can also use the ifconfig
command to assign a new IP address and netmask to a given network interface.
The syntax is as shown:
ifconfig [interface] [ip_address] netmask [subnet-mask]
For example, to assign a new IP address to the eth0
address, run the command:
ifconfig eth0 192.168.227.100 netmask 255.255.240.0
This should assign a new IP address to the eth0
interface.
Ifconfig
Enable or Disable Network Interfaces
In some instances, you may need to enable or disable a given network interface.
To disable a given network interface, use the command syntax as shown:
sudo ifconfig [interface] down
For example, to disable the eth0
run:
sudo ifconfig eth0 down
To activate an inactive interface, run the command:
sudo ifconfig [interface] up
For example, run the command:
sudo ifconfig eth0 up
Configuring Monitor Mode
Modern network interfaces support monitor or promiscuous mode which allows you to capture and view network packets. Monitor mode is an essential feature in networking hacking.
To check the most popular network cards for hacking that support Monitor mode:
https://www.geekbits.io/best-wi-fi-hacking-adapters-in-2023/
To put a network in monitor mode using ifconfig
run the command:
ifconfig [interface] promisc
To disable monitor mode, run the command:
ifconfig [interface] -promisc
Ifconfig
Change Mac Address
https://www.geekbits.io/how-to-find-the-mac-address-of-network-interface-in-linux/
To change the Mac Address of a given network interface, use the command as shown:
ifconfig [interface] hw ether [mac_addres]
For example, to change the mac address of the eth0
interface, run:
ifconfig eth0 hw ether 00:15:5d:2a:28:89
Conclusion
In this post, we explored the workings of the ifconfig
command in Linux to show information about network interfaces, configuring new addresses, configuring monitor mode, and more.
We hope you enjoyed this post. Leave us a comment down below and share with people who might find this article relevant.