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.
Here are the commands and options we can use to get the network interfaces. These commands are safe to run without changing anything.
- ifconfig -a
- ifconfig eth0
- ip addr
- ip link show
- ip link show dev eth0
- dmesg | grep -i eth
If you’re new to the world of Linux, you can refer to this book “practical linux system administration” This in-depth book will be your guiding light, providing you with the foundational knowledge and skills required to navigate and wield the Linux command line interface (CLI) effectively and with assurance.
This essential guide covers all aspects of Linux system administration, from user maintenance, backups, filesystem housekeeping, storage management, and network setup to hardware and software troubleshooting and some application management. It’s both a practical daily reference manual for sysadmins and IT pros and a handy study guide for those taking Linux certification exams.
You’ll turn to it frequently, not only because of the sheer volume of valuable information it provides but because of the real-world examples within and the clear, useful way the information is presented. With this book at your side, you’ll be able to:
Check out this book here practical linux system administration.
This article is part of the following series.
- Get MAC address with Ansible
- 5 useful Linux network troubleshooting commands
- 3 Easy Ways to Find IP address in Linux
- 3 Ways to Find MAC Address In Linux
- 4 ways to check network usage in Linux
Table of Contents
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
Introduction of network interface in Linux
A network interface acts as a crucial link in the TCP/IP model, connecting devices to networks smoothly.
It’s like a translator between your computer and the network world. This interface handles two important addresses: the MAC address, which is like a device’s ID card, and the IP address, which helps devices find each other on the internet.
Positioned between the physical cables and the digital world, a network interface ensures that your computer can talk to other devices in a way they understand, making sure information gets where it needs to go.
Network interfaces can take various forms, such as wired Ethernet adapters, wireless adapters, or virtual interfaces.
History of network interface naming convention in Linux
In earlier versions of Linux, including Red Hat, network interfaces were named using a simple and sequential convention: eth0, eth1, eth2, and so on. This naming scheme was straightforward but had limitations, especially in environments with multiple network interfaces. It didn’t provide much context about the interfaces’ types, roles, or locations.
As systems grew more complex with various network interfaces and adapters, administrators faced challenges in identifying interfaces consistently. Virtualization, server clustering, and multiple network adapters further complicated matters, as names like eth0 might not accurately represent the purpose or location of an interface.
To address these challenges, the Consistent Network Device Naming scheme was introduced. It aimed to provide more meaningful and predictable names for network interfaces, enabling administrators to manage and troubleshoot networks more effectively.
The interface name starts with a two-character prefix based on the type of interface:
- en for Ethernet
- wl for wireless LAN (WLAN)
- ww for wireless wide area network (WWAN)
The new naming convention added structure and context to interface names. Components such as the type identifier (“en” for Ethernet), slot index, port separator and port index were introduced. These components conveyed information about the type, location, and connectivity of the interface. For example : ‘enp133s0f0’
Find network interfaces with ip addr command in Linux
In Linux, you can use the ip command to find information about network interfaces, including their IP addresses. The ip command is a powerful replacement for the older ifconfig command and provides more detailed and flexible network configuration options.
To view the network interfaces and their IP addresses using the ip command, follow these steps:
- Open your terminal or command prompt.
- Type the following command:
ip addr show
- Press Enter.
The ip addr show command (or ip a) will display a list of all network interfaces on your system along with their respective IP addresses, netmask, and additional information.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic eth0 valid_lft 84652sec preferred_lft 84652sec 3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
In this example, you can see three network interfaces:
- lo: The loopback interface, which is a virtual interface used for communication within the local machine. It has the IP address 127.0.0.1.
- eth0: An Ethernet interface with the IP address 192.168.1.100 and a subnet mask of 255.255.255.0 (equivalent to /24 CIDR notation).
- wlan0: A wireless interface that is currently down (state DOWN) and does not have an assigned IP address in this example.
Keep in mind that the actual output may vary depending on your system’s configuration and the number of network interfaces you have.
The ip command provides comprehensive information about the network interfaces, making it a valuable tool for network troubleshooting and configuration.
If you want to display information only for specific device like em1, you can use this command ip addr show dev em1.
The ip command is part of the iproute2 package, which is commonly included in most modern Linux distributions.
However, there might be some exceptions where iproute2 is not installed by default or not available due to specific system configurations.
You can refer to this article to fix ‘ip command not found ‘ error.
Find network interfaces with ifconfig command in Linux
We can find network interfaces in Linux using 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.
For example 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
List network interfaces with ip link show command in Linux
The “ip link show” command is a versatile tool in Linux that provides valuable information about network interfaces.
When you run the “ip link show” command in a terminal, it displays a list of network interfaces currently active on your Linux system. Each interface is presented with its name, state (whether it’s up or down), and associated details such as its MAC address, maximum transmission unit (MTU), and more.
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
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.
A MAC address consists of 12 hexadecimal digits, usually grouped into six pairs separated by hyphens. MAC addresses are available from 00-00-00-00-00-00 through FF-FF-FF-FF-FF-FF.
The first half of the number is typically used as a manufacturer ID, while the second half is a device identifier. In nearly all enterprise network devices today, whether Wi-Fi or Ethernet, this number is hardcoded into the device during the manufacturing process.
You can easily retrieve the MAC address of a device in Linux by utilizing the ifconfig/ip addr/ip link show command.
How to find the IP address of network interface in Linux?
An IPv4 address consists of 32 bits, usually written as four decimal numbers, or a dotted quad. Possible values range from 000.000.000.000 through 255.255.255.255, although many possible addresses are disallowed or reserved for specific purposes.
An IP address identifies a device on the global internet, acting as the device’s logical address to identify that network connection.
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?
In networking, a gateway serves as a connection point that links different networks together, enabling them to communicate and exchange data. Essentially, a gateway acts as a doorway or bridge that allows data to flow between networks with different subnets.
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!