Linux provides a number of commands to manage network interfaces. In this post, we will discuss 4 different commands: ifconfig, ip addr, ip link show, dmesg.
The ifconfig command displays information about all active network interfaces on your system. However, this command has been deprecated in favor of ip command.
The ip command is a powerful replacement for the older ifconfig command that can be used to manage network interfaces and routing tables.
The dmesg command can be used to display the kernel ring buffer, which contains messages from the Linux kernel. These messages can include information about the system hardware, software, and network interfaces.
These commands are safe to run without changing anything.
Here are the commands and options we can use to get the network interfaces.
- ifconfig -a
- ifconfig eth0
- ip addr
- ip link show
- ip link show dev eth0
- dmesg | grep -i eth
Procedure to get network interfaces in Linux
- Open the terminal application.
- Type ifconfig -a or ip addr or ip link show
- Press Enter to run the command.
- The output will list all the network interfaces
Find network interfaces with ifconfig command in Linux
The best Linux command to find network interfaces is to use ifconfig command. Open the terminal and type “ifconfig -a”. This will return a list of all available network interfaces on Linux system.
If you do not specify an interface name, the ifconfig command will display information for all of the network interfaces on the system.
$ ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001
inet 10.1.0.203 netmask 255.255.255.0 broadcast 10.1.0.255
ether 02:1b:4c:94:27:1b txqueuelen 1000 (Ethernet)
RX packets 1716963 bytes 472994059 (451.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7964635 bytes 11377273850 (10.5 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
You can append the name of the interface to the end of the command (e.g. “ifconfig eth0”) to view information about a specific interface.
So if I want to display information only for specific device like eth0, I will use this command ifconfig eth0.
$ ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.254.222.37 netmask 255.255.254.0 broadcast 10.254.223.255
ether fa:16:3e:18:3a:76 txqueuelen 1000 (Ethernet)
RX packets 94405374 bytes 5781082518 (5.3 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23249315 bytes 1034177108 (986.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
This command is available on most Unix-like operating systems, including Linux and macOS.
If you receive a message “ifconfig command not found” when you try to use it, you can run the following command to install it.
On Debian based distros:
# apt update
# apt install net-tools
On Red Hat based distros:
# dnf install net-tools
To get more details about this command, I highly recommend the following article.
Find network interfaces with ip add command in Linux
Another way to find your network interface in Linux is to use the ip command. The ip command displays a variety of information about your system’s networking configuration.
To view information about all available interfaces, type “ip addr” into a terminal. This will return a list of interfaces along with their assigned IP addresses.
The ip command is one of my favorite commands to use on the terminal. This command is an incredibly useful tool for network configuration and troubleshooting.
This command also allows you to configure network interfaces, add routes, and manipulate network devices.
Whether I am setting up a new network or resolving a connectivity issue, the ip command is an essential part of my toolkit.
$ ip addr
1: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
link/ether 02:1b:4c:94:27:1b brd ff:ff:ff:ff:ff:ff
inet 10.1.0.203/24 brd 10.1.0.255 scope global dynamic noprefixroute eth0
valid_lft 3029sec preferred_lft 3029sec
If you want to display information only for specific device like em1, you can use this command ip addr show dev em1.
To learn more about ip command, I highly recommend the following guide.
List network interfaces with ip link show command in Linux
The ip link show command can also be used to find your network interface in Linux.
To view information about a specific interface, simply append the interface number to the end of the command (e.g. “ip link show eth0”).
$ ip link show
1: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 02:1b:4c:94:27:1b brd ff:ff:ff:ff:ff:ff
check network interfaces with dmesg command in Linux
If you are unsure of the name of your network interface, you can use the dmesg command to find it. The dmesg command prints messages from the kernel ring buffer. This information can be useful for finding hardware devices on your system.
To use this command, type “dmesg | grep -i eth” into a terminal. This will return a list of lines that contain the word “eth”, which is typically used to identify network interfaces.
$ sudo dmesg |grep -i eth
[ 20.680677] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
what is network interface in Linux
The network interface in Linux is a term used to describe the device that your computer uses to connect to a network. This could be a wired or wireless connection, depending on your setup.
Network interfaces can take various forms, such as wired Ethernet adapters, wireless adapters, or virtual interfaces.
This interface is responsible for transmitting and receiving data over the network, allowing the computer to access the internet or communicate with other devices on the network.
The network interface is usually represented by the eth0 or wlan0 device in Linux, but it may vary depending on your system.
How to find the MAC address of network interface in Linux?
Each NIC has a unique address (the hardware address, known as Media Access Control [MAC] address), which identifies that NIC.
This address is six pairs of hexadecimal bits separated by colons (:). A MAC address looks similar to this: 00:60:08:8F:5A:D9.
The MAC address of a device in Linux can be found using the ifconfig command. This will print the MAC address for your network interfaces. You can also use the ip link show command to find the MAC address.
How to find the IP address of network interface in Linux?
To find your IP address in Linux, use the ip addr command. This will print the IP address and other information about your network interfaces.
If you want to find out your public IP address, you can use the curl command. This will send a request to a web server and return your public IP address. curl ifconfig.me
How to find the gateway of network interface in Linux?
To find the gateway in Linux, you can use the route command. This will print the IP address of the gateway for your default route. You can also use the ip addr command to find the gateway.
I hope this blog post has been helpful in finding your network interface in Linux. If you have any questions, feel free to leave a comment below! Thanks for reading!