ifconfig (interface configuration) is a network management tool. Ifconfig command 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, replaced by ip, and may not be available on newer Linux distributions.
If you are getting an “ifconfig: command not found” error, it means that the package containing this command is not installed on your system.
Install ifconfig in Ubuntu/Debian
Run the following command to install ifconfig on Ubuntu and Debian-based Linux distributions.
sudo apt install net-tools -y
How to use ifconfig command
The basic syntax of the ifconfig command is shown below:
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
Where:
- Interface: The name of the network interface.
- Address: The IP address you want to assign.
The configuration set with the ifconfig command is inconsistent. After rebooting the system, all changes will be lost. To make changes permanent, you must edit distribution-specific configuration files or add commands to startup scripts.
Only users with root or sudo privileges can configure network interfaces.
Display information about network interfaces
When run without options, ifconfig displays configuration information for each network interface and its associated IP address:
ifconfig -a
The output contains information about all active and inactive network interfaces:
To display configuration information for a specific network interface, enter the interface name after the command:
ifconfig <interface name>
The output will be something like this:
Assigning an IP Address and Netmask to a Network Interface
The ifconfig command allows you to assign an IP address and netmask to a network interface.
To assign an IP address and netmask, use the following syntax:
ifconfig [interface name] [ip address] subnet mask [subnet mask]
For example, to assign the eth0 interface the IP address 192.168.0.101 and the netmask 255.255.0.0, run:
ifconfig ens33 192.168.3.128 netmask 255.255.255.0
You can also assign an additional IP address to a network interface using an interface alias:
ifconfig ens33:0 192.168.3.129 netmask 255.255.255.0
Enable and disable network interfaces
Sometimes a network interface reset is required. In this case, the network interface can be enabled or disabled using the ifconfig command.
To disable the active network interface, enter the name of the device and check the box below:
ifconfig ens33 down
Use the above checkboxes to enable inactive network interfaces:
ifconfig ens33 up
Change the mac address of the network interface
MAC is a physical “media access control” address that uniquely identifies 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 ens33 hw ether 00:00:2d:3a:2a:29
Note:- But first of all you have to down your interface to change the MAC address.
tlt@ubuntu:~$ sudo ifconfig ens33 down tlt@ubuntu:~$ sudo ifconfig ens33 hw ether 00:00:2d:3a:2a:29 tlt@ubuntu:~$ sudo ifconfig ens33 up tlt@ubuntu:~$ ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.3.129 netmask 255.255.255.0 broadcast 192.168.3.255 inet6 fe80::7fae:af9b:8606:bc17 prefixlen 64 scopeid 0x20 ether 00:00:2d:3a:2a:29 txqueuelen 1000 (Ethernet) RX packets 772 bytes 888521 (888.5 KB) RX errors 2 dropped 0 overruns 0 frame 0 TX packets 599 bytes 63121 (63.1 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 19 base 0x2000 tlt@ubuntu:~$
Conclusion
We show you how to use the ifconfig command to configure and display information about network interfaces. For more information on ifconfig, see the man page for the ifconfig command.
If you have any questions please leave them in the comments below.