howtouselinux

4 Ways to Find network interface in Linux

Table of Contents

In Linux, the network interface can be found in a few different ways. In this blog post, we will discuss four of the most common methods for finding your network interface.

We will also provide instructions on how to execute each method. Keep in mind that the commands listed below may vary depending on your specific distribution of Linux.

The following commands can be used to find the network interface in Linux.

  • ifconfig -a
  • ifconfig eth0
  • ip addr
  • ip link show
  • ip link show dev eth0
  • dmesg | grep -i eth

 

Procedure to get network interface in Linux

The procedure to find the network interface in Linux is as follows:

  • Open the terminal application.
  • Type ifconfig -a or ip addr or ip link show
  • Press Enter to run the command.
  • The output will display information about all the network interfaces on the system.

 

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.

The network interface is usually represented by the eth0 or wlan0 device, but it may vary depending on your system.

Find network interface with ifconfig command in Linux

The most simple method to find network interface in Linux 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.

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.

$ 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

So if you want to display information only for specific device like eth0, you can 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

The ifconfig command can be used to configure a network interface. The basic syntax for the ifconfig command is:

ifconfig interface ip address netmask NETMASK BROADCAST_ADDRESS

This will set the IP address, netmask and broadcast address for the specified network interface.

If you do not specify an interface name, the ifconfig command will display information for all of the network interfaces on the system.

You can also use the ifconfig command to enable or disable a network interface. The basic syntax for this is:

ifconfig interface up or down

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

This command is available on most Unix-like operating systems, including Linux and macOS. We can also use ifconfig command to troubleshoot network issues.

Find network interface with ip add command in Linux

Another way to find your network interface in Linux is to use the ip command. The ip command can be used to display 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.

$ 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 do not specify an interface, the ip address command will display information for all of the IP addresses on the Linux system.

If you want to display information only for specific device like em1, you can use this command ip addr show dev em1.

List network interface with ip link show command in Linux

The ip link show command can also be used to find your network interface in Linux.This command will return a list of all available interfaces on your system. Each interface will be represented by a number.

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 interface 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?

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.

How to configure your network interface in Linux?

To configure your network in Linux, you can use the ifconfig command. This will allow you to change the IP address, netmask, gateway and other settings for your network interfaces. You can also use the ip addr command to configure your network.

We 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!

David Cao
David Cao

Hey there! I am David, a Cloud & DevOps Enthusiast and 18 years of experience as a Linux engineer. I work with AWS, Git & GitHub, Linux, Python, Ansible, and Bash. I am a technical blogger and a Software Engineer, enjoy sharing my learning and contributing to open-source.