Linux ifconfig Command
ifconfig
(interface configuration) is a Linux command-line utility that allows you to display and configure network interfaces on your system. In the Linux operating system, it is used to configure network interfaces and examine their status. You can adjust ARP cache, routes, assign IP addresses, enable or disable interfaces, and more with ifconfig.
In this tutorial, you will learn how to use the ifconfig
command. We will also address a few FAQs on Linux ifconfig
Command.
How to Install ifconfig
The ifconfig
command is deprecated and replaced by ip
and may not be included in newer Linux distributions.
If you get the error message "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 the following command:
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>]
Where:
interface
- is the name of the network interface.address
- is the IP address you want to assign.
The ifconfig
command does not set persistent configurations. After rebooting the system, all changes will be lost. To make the changes permanent, you must either edit the distribution-specific configuration file or add the command to the startup script. Only the root user or a user with sudo privileges can configure the network interface.
Display Information of Network Interfaces
When called without any options, ifconfig
displays the configuration information of all network interfaces and associated IP addresses:
ifconfig -a
All active and dormant network interfaces are listed in the output:
Output
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 a specific network interface, write the interface name after the command:
ifconfig eth0
Output will be like this:
Output
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 IP addresses and network masks to network interfaces.
Use the following syntax to assign an IP address and a network mask:
ifconfig [interface-name] [ip-address] netmask [subnet-mask]
For example, to assign the IP address 192.168.0.101
and netmask 255.255.0.0
to the eth0 interface, you would run:
ifconfig eth0 192.168.0.101 netmask 255.255.0.0
You can also specify a secondary IP address for a network interface using an interface alias:
ifconfig eth0:0 192.168.0.102 netmask 255.255.0.0
Enable and Disable a Network Interface
You might need to reset the network interface occasionally. 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 followed by the indicator downwards:
ifconfig eth0 down
To enable inactive network interfaces, use the up flag:
ifconfig eth0 up
Enable and Disable Promiscuous Mode
Promiscuous allows a network interface to access and view all packets on the network. You can use the ifconfig
command to enable and disable distribution on a specific network device.
To enable broadcast on the network interface, enter the promotional flag after the device name:
ifconfig eth0 promisc
To disable promiscuous mode, use the -promisc
flag
ifconfig eth0 -promisc
Change MTU of a Network Interface
The "Maximum Transmission Unit" MTU helps to limit the size of packets transmitted on an interface.
You can change the MTU value with the syntax:
ifconfig [interface-name] mtu [mtu-value]
For example, to set the MTU value of the network interface eth0
to 500
, run the following command:
ifconfig eth0 mtu 500
Change the MAC address of a Network Interface
A "Media Access Control" MAC is a physical address that uniquely identifies devices on a network.
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:3a:2a:28
FAQs on Linux ifconfig Command
Can the "ifconfig" command show all network interfaces?
Yes, running "ifconfig" without specifying a network interface name displays information for all active network interfaces on your system.
How can I assign an IP address to a network interface using "ifconfig"?
To assign an IP address to a network interface using "ifconfig", use the following command: "sudo ifconfig interface_name ip_address netmask subnet_mask". For example, "sudo ifconfig eth0 192.168.0.10 netmask 255.255.255.0" sets the IP address of "eth0" to "192.168.0.10" with a subnet mask of "255.255.255.0".
Can I enable or disable a network interface using "ifconfig"?
Yes, you can enable or disable a network interface using "ifconfig". To bring up an interface, use "sudo ifconfig interface_name up". To bring it down, use "sudo ifconfig interface_name down".
How do I view only active network interfaces with "ifconfig"?
To view only active network interfaces, you can use the "-a" option with "ifconfig". For example, "ifconfig -a" shows all active and inactive interfaces.
Can "ifconfig" display the MAC address of a network interface?
Yes, "ifconfig" displays the MAC address of a network interface under the "HWaddr" or "ether" field in the output.
Are there alternatives to "ifconfig" in Linux?
Yes, newer Linux distributions often recommend using the "ip" command or other network management tools like "nmcli" or "nmtui" for network interface configuration and management.
Conclusion
We have shown you how to use the ifconfig
command to configure and display information about network interfaces.
If you have any queries, please leave a comment below and we’ll be happy to respond to them.