Show all network interfaces linux

HowTo: Linux Show List Of Network Cards

H ow do I display a list of all network cards under Linux operating systems?

You can use any one of the following command to list network cards installed under Linux operating systems. Please note that the ifconfig and ip commands will also display interfaces information about vpn, loopback, and other configured interfaces.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux
Est. reading time 2m
  1. lspci command : List all PCI devices.
  2. lshw command : List all hardware.
  3. dmidecode command : List all hardware data from BIOS.
  4. ifconfig command : Outdated network config utility.
  5. ip command : Recommended new network config utility.
  6. hwinfo command : Probe Linux for network cards.
  7. ethtool command : See NIC/card driver and settings on Linux.

We use standard terms, such as the network interface controller (NIC). Also known as a network interface card, network adapter, LAN adapter or physical network interface, and so on. Let us see some useful examples for displing out NIC info on Linux.

Use lspci command Linux command to show list of network cards

Type the following lspci command along with egrep command to filter out devices:
# lspci | egrep -i —color ‘network|ethernet’
# lspci | egrep -i —color ‘network|ethernet|wireless|wi-fi’
Sample outputs from my Linux server:

How to use lshw command for displaying network cards (NIC) on Linux

The lshw command can extract detailed information on the hardware configuration of the machine including network cards. Type the following command:
# lshw -class network
Detailed hardware information about network cards on Linux:

Here is another outputs:

  1. -class network : View all network cards on your Linux system
  2. -short : Display device tree showing hardware paths, very much like the output of HP-UX’s ioscan

Let us see mask, IP and other information set up for wlp82s0:
$ ip a show wlp82s0

Linux ethtool command for Ethernet hardware devices

Want to see/query or control network driver and hardware settings on Linux? Try the the ethtool command:
$ sudo ethtool enp0s31f6
And it spitted out tons of useful information for my Ethernet network card on Linux:

We can display driver information for network card too:
$ sudo ethtool -i eth0
$ sudo ethtool -i enp0s31f6

ifconfig and ip commands

To see all configured network devices, enter:
# ifconfig -a
OR
# ip link show
OR
# ip a
Sample outputs:

Want to list all IP addresses and interfaces on Linux in a tabular format for better readability? Try:
$ ip -br -c link show
$ ip -br -c addr show

Listing network cards on Linux using hwinfo command

Open the terminal and then type:
$ sudo hwinfo —network —short

We can now obtain more info for eth0 using the ip command:
$ ip a s eth0
My IP address assigned to eth0:

The /proc/net/dev file

The dev pseudo-file contains network device status information. This gives the number of received and sent packets, the number of errors and collisions and other basic statistics. Open the terminal and then type the following cat command:
$ cat /proc/net/dev
Stats:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Conclusion

We learned about various Linux commands to display information about installed and running network cards.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

In which distro are you using the ip command? I’m trying it in Ubuntu and it seems to be a command to manipulate routing

@Chex, thanks! On Ubuntu, I was getting an error trying to run ‘ip -a’, but your command worked — and it’s very useful info.

It was a typo on part.

However, ip link show should be used.

For wireless cards I find “iwconfig” useful. I used to have problems with a wireless adapter going offline, which I worked around with “iwconfig wlan0 power off” to turn off its power management feature.

It would be most useful to correlate the HW info to the logical device name, such as the Broadcom NIC is eth1.

Try ethtool or lspci it will map both along with driver name:

Writing a shell script left as an exercise for the reader.

At any point is this site going to post anything that isn’t basic common knowledge to any linux users that isnt a complete noob?

Because if not, then I’m going to unsubscribe from your RSS feed.

I can not stop you or anyone else from unsubscribing to our RSS feed. The /faq/ section is for new users only so it has all sort of questions and answers. As you may have noticed that I’ve already started to display the difficulty level for each Q & A. I’m also working on rss feed for all three difficulties. So that users can only subscribe as follows:

  • Easy – for beginners.
  • Moderate – for Intermediate users.
  • Hard – for Advanced users.

This is going to take a little more time as need some sort of coding and modification on my part. Hope this helps.

ok, so idioms for the easy/intermediate/hard would be ubuntu/debian/all others? ^^

Nah, but linux is no longer for those who actually are bothered to learn how to use a computer (as opposed to the in ‘noob-land’), learn how to use windows. Now, many of the windows users who are just ‘end users’ and not computer savvy, migrate to linux, and will inadvertedly land on ubuntu like distros.

I recall on youtube, some user saying, I have been using Ubuntu for 6 months and consider myself fairly knowledgable, and then went on about DE if they are installable in other distros and what not. I don’t even know what it was, but it was so absurd, I am glad that person uttered Ubuntu and not linux, as clearly the person was clueless in the latter.

You can blame Canonical for such issue. Just visit http://www.ubuntu.com/desktop home page and try to find out word Linux. I think they are ashamed of using word Linux.

PS: I use Debian Linux 🙂

[updated] Various aspects of nixCraft can be monitored with RSS feeds including ability to sort out feed – https://www.cyberciti.biz/nixcraft-rss-feed-syndication/

Hope this helps!

@root
I don’t suppose you have noticed that at least 99% of the worlds population are at least some variant of a linux ‘noob’. It would indeed be pointless to run a web site for just the 1% who are whizz kids as you would have very few visitors indeed.

Also, I believe it should be ‘to any linux user who isn’t’

I’ve clearly lost the plot a little myself, ‘at least’ and ‘indeed’ twice in above comment. Have to stop taking these tablets.

In your scripts, the easiest way is to do something like this.

for x in `/sbin/ifconfig | grep Link | awk ‘’ | sort | egrep -v ‘inet6|lo’`
do
echo $x
done

Or you can /sbin/ifconfig $x | grep to extract and read the data into a variable to work on later.

Here is a small code you can use in your scripts.

for x in `/sbin/ifconfig | grep Link | awk ‘’ | sort | egrep -v ‘inet6|lo’`
do
echo $x
done

You can replace echo $x with
/sbin/ifconfig $x | grep (any property you are looking for) and read that into a variable.

I think some of the posts are not being accepted in the comments, Vivek. Not sure why. I thought first it was something in my browser.
I sure hope I didn’t have duplicates in the comments. 🙂

We cache page for 15 minutes. So you will not see updates immediately.

how to check the nic card settings in linux

What distro?
What specifics you are looking for?
If you mean network settings for each card, depending on your distro, it can be found at

For Redhat based distros
/etc/sysconfig/network-scripts/ifcfg-[device Name]

For Debian based distros
/etc/network/interfaces

For in depth, in detail information other settings about your network card, use ethtool.

Run
man ethtool

i have dell and i have wireless in my neighbours but shows me red cross so what i do please

I am new in linux.
now I have problem with my X-Server installation.

my machine used Red Hat V7,2
and my card is used AGX3281.

this is I did for replaced the old card, but I did with the same type.

after I finished the install the X-server, and run startx,
[root@barco1 root]# startx

xinit: No such file or directory (errno 2): no server “X” in PATH

Use the — option, or make sure that /usr/X11R6/bin is in your path and
that “X” is a program or a link to the right type of server
for your display. Possible server names include:

XFree86 XFree86 displays

giving up.
xinit: Connection refused (errno 111): unable to connect to X server
xinit: No such process (errno 3): Server error.

and when I start lspci
[root@barco1 root]# lspci
00:00.0 Host bridge: Intel Corp.: Unknown device 2770 (rev 02)
00:02.0 Display controller: Intel Corp.: Unknown device 2772 (rev 02)
00:1c.0 PCI bridge: Intel Corp.: Unknown device 27d0 (rev 01)
00:1c.1 PCI bridge: Intel Corp.: Unknown device 27d2 (rev 01)
00:1c.2 PCI bridge: Intel Corp.: Unknown device 27d4 (rev 01)
00:1c.3 PCI bridge: Intel Corp.: Unknown device 27d6 (rev 01)
00:1d.0 USB Controller: Intel Corp.: Unknown device 27c8 (rev 01)
00:1d.1 USB Controller: Intel Corp.: Unknown device 27c9 (rev 01)
00:1d.2 USB Controller: Intel Corp.: Unknown device 27ca (rev 01)
00:1d.3 USB Controller: Intel Corp.: Unknown device 27cb (rev 01)
00:1d.7 USB Controller: Intel Corp.: Unknown device 27cc (rev 01)
00:1e.0 PCI bridge: Intel Corp. 82801BAM PCI (rev e1)
00:1f.0 ISA bridge: Intel Corp.: Unknown device 27b8 (rev 01)
00:1f.2 IDE interface: Intel Corp.: Unknown device 27c0 (rev 01)
00:1f.3 SMBus: Intel Corp.: Unknown device 27da (rev 01)
0b:05.0 PCI bridge: Intel Corp.: Unknown device b154
0b:0b.0 Ethernet controller: Intel Corp. 82541PI Gigabit Ethernet Controller (re
v 05)
0c:00.0 VGA compatible controller: ATI Technologies Inc: Unknown device 4c57
0c:01.0 VGA compatible controller: ATI Technologies Inc: Unknown device 4c57
0c:02.0 VGA compatible controller: ATI Technologies Inc: Unknown device 4c57
0c:03.0 VGA compatible controller: ATI Technologies Inc: Unknown device 4c57
0c:04.0 Host bridge: NEC Corporation Vrc5074 [Nile 4] (rev 03)

Источник

Network configuration

This article describes how to configure network connections on OSI layer 3 and above. Medium-specifics are handled in the /Ethernet and /Wireless subpages.

Contents

Check the connection

To troubleshoot a network connection, go through the following conditions and ensure that you meet them:

  1. Your network interface is listed and enabled. Otherwise, check the device driver – see /Ethernet#Device driver or /Wireless#Device driver.
  2. You are connected to the network. The cable is plugged in or you are connected to the wireless LAN.
  3. Your network interface has an IP address.
  4. Your routing table is correctly set up.
  5. You can ping a local IP address (e.g. your default gateway).
  6. You can ping a public IP address (e.g. 8.8.8.8 , which is a Google DNS server and is a convenient address to test with).
  7. Check if you can resolve domain names (e.g. archlinux.org ).

This article or section needs expansion.

ping is used to test if you can reach a host.

For every reply you receive, the ping utility will print a line like the above. For more information see the ping(8) manual. Note that computers can be configured not to respond to ICMP echo requests. [1]

If you receive no reply, this may be related to your default gateway or your Internet Service Provider (ISP). You can run a traceroute to further diagnose the route to the host.

Network management

To set up a network connection, go through the following steps:

  1. Ensure your network interface is listed and enabled.
  2. Connect to the network. Plug in the Ethernet cable or connect to the wireless LAN.
  3. Configure your network connection:
    • static IP address
    • dynamic IP address: use DHCP

net-tools

Arch Linux has deprecated net-tools in favor of iproute2 .[2]

Deprecated command Replacement commands
arp ip neighbor
ifconfig ip address, ip link
netstat ss
route ip route

iproute2

iproute2 is a dependency of the base meta package and provides the ip(8) command-line interface, used to manage network interfaces, IP addresses and the routing table. Be aware that configuration made using ip will be lost after a reboot. For persistent configuration, you can use a network manager or automate ip commands using scripts and systemd units. Also note that ip commands can generally be abbreviated, for clarity they are however spelled out in this article.

Network interfaces

By default udev assigns names to your network interfaces using Predictable Network Interface Names, which prefixes interfaces names with en (wired/Ethernet), wl (wireless/WLAN), or ww (WWAN). See systemd.net-naming-scheme(7) .

Listing network interfaces

Both wired and wireless interface names can be found via ls /sys/class/net or ip link . Note that lo is the virtual loopback interface and not used in making network connections.

Wireless device names can also be retrieved using iw dev . See also /Wireless#Get the name of the interface.

If your network interface is not listed, make sure your device driver was loaded successfully. See /Ethernet#Device driver or /Wireless#Device driver.

Enabling and disabling network interfaces

Network interfaces can be enabled or disabled using ip link set interface up|down , see ip-link(8) .

To check the status of the interface enp2s0 :

The UP in
is what indicates the interface is up, not the later state DOWN .

Static or dynamic IP address?

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

If you are using a Wi-FI or a router, for example, at home, you will most likely be using a dynamic IP address. The IP address is assigned by the Wi-Fi or router and it is what your computer should be configured to use. Or, if you are at home and your computer is connected to your ISP’s modem, for example, a cable modem, that will also be using a dynamic IP address. Dynamic IP addresses can change each time you turn your computer on. In a work environment you may have a static IP address or a dynamic IP address. At home you can configure your router to always assign your computer the same IP address in which case you are using a static IP address. When you are using a dynamic IP address you will need to use DHCP so that it can set up your network interface with the correct IP address. In addition to configuring your IP address, DHCP can also configure your routing (how to get from where you are to wherever on the network you are going) as well as your name servers, which convert the host name, for example, google.com, into its IP address, that number with dots in it.

Static IP address

A static IP address can be configured with most standard network managers and also dhcpcd.

To manually configure a static IP address, add an IP address as described in #IP addresses, set up your routing table and configure your DNS servers.

IP addresses

List IP addresses:

Add an IP address to an interface:

Note that:

  • the address is given in CIDR notation to also supply a subnet mask
  • + is a special symbol that makes ip derive the broadcast address from the IP address and the subnet mask

Delete an IP address from an interface:

Delete all addresses matching a criteria, e.g. of a specific interface:

Routing table

The routing table is used to determine if you can reach an IP address directly or what gateway (router) you should use. If no other route matches the IP address, the default gateway is used.

The routing table is managed using ip-route(8) .

PREFIX is either a CIDR notation or default for the default gateway.

List IPv4 routes:

List IPv6 routes:

A Dynamic Host Configuration Protocol (DHCP) server provides clients with a dynamic IP address, the subnet mask, the default gateway IP address and optionally also with DNS name servers.

To use DHCP you need a DHCP server in your network and a DHCP client:

Client Package Archiso Note Systemd units
dhcpcd dhcpcd Yes DHCP, DHCPv6, ZeroConf, static IP dhcpcd.service , dhcpcd@interface.service
ISC dhclient dhclient Yes DHCP, DHCPv6, BOOTP, static IP dhclient@interface.service

Servers

This article or section needs expansion.

Server Package IPv4 IPv6 GUI Interfaces Storage backend(s) Note
dhcpd dhcp Yes Yes Glass-ISC-DHCP ? File
dnsmasq dnsmasq Yes Yes No ? File Also DNS, PXE and TFTP
Kea kea Yes Yes Kea-Anterius (Experimental) REST, RADIUS and NETCONF File, MySQL, PostgreSQL and Cassandra Also DNS

Network managers

A network manager lets you manage network connection settings in so called network profiles to facilitate switching networks.

Network manager GUI Archiso [3] CLI tools PPP support
(e.g. 3G modem)
DHCP client systemd units
ConnMan 8 unofficial No connmanctl(1) Yes (with ofono AUR ) internal connman.service
netctl 2 unofficial No netctl(1) , wifi-menu Yes dhcpcd or dhclient netctl-ifplugd@interface.service , netctl-auto@interface.service
NetworkManager Yes No nmcli(1) , nmtui(1) Yes internal or dhclient NetworkManager.service
systemd-networkd No Yes ( base ) networkctl(1) No internal systemd-networkd.service , systemd-resolved.service
Wicd Yes No wicd-cli(8) , wicd-curses(8) No dhcpcd or dhclient wicd.service

Set the hostname

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

A hostname is a unique name created to identify a machine on a network, configured in /etc/hostname —see hostname(5) and hostname(7) for details. The file can contain the system’s domain name, if any. To set the hostname, edit /etc/hostname to include a single line with myhostname :

To temporarily set the hostname (until reboot), use hostname(1) from inetutils :

To set the «pretty» hostname and other machine metadata, see machine-info(5) .

Local hostname resolution

This article or section needs expansion.

nss-myhostname(8) (an NSS module provided by systemd) provides local hostname resolution without having to edit /etc/hosts . It is enabled by default.

Some software may however still read /etc/hosts directly, see [4] [5] for examples. To prevent them from potentially breaking, hanging or otherwise delaying operation, make sure they can resolve the local hostname and localhost by configuring the hosts(5) file:

For a system with a permanent IP address, replace 127.0.1.1 with that permanent IP address. For a system with a fully qualified domain name, insert the fully qualified domain name before the hostname. For example:

As a result the system resolves to both entries:

Local network hostname resolution

To make your machine accessible in your LAN via its hostname you can:

  • edit the /etc/hosts file for every device in your LAN, see hosts(5)
  • set up a DNS server to resolve your hostname and make the LAN devices use it (e.g. via #DHCP)
  • or the easy way: use a Zero-configuration networking service:
    • Hostname resolution via Microsoft’s NetBIOS. Provided by Samba on Linux. It only requires the nmb.service . Computers running Windows, macOS, or Linux with nmb running, will be able to find your machine.
    • Hostname resolution via mDNS. Provided by either nss_mdns with Avahi (see Avahi#Hostname resolution for setup details) or systemd-resolved. Computers running macOS, or Linux with Avahi or systemd-resolved running, will be able to find your machine. The older Win32 API does not support mDNS, which may prevent some older Windows applications from accessing your device.

Tips and tricks

Change interface name

You can change the device name by defining the name manually with an udev-rule. For example:

These rules will be applied automatically at boot.

A couple of things to note:

  • To get the MAC address of each card, use this command: cat /sys/class/net/device_name/address
  • Make sure to use the lower-case hex values in your udev rules. It does not like upper-case.

If the network card has a dynamic MAC, you can use DEVPATH , for example:

To get the DEVPATH of all currently-connected devices, see where the symlinks in /sys/class/net/ lead. For example:

The device path should match both the new and old device name, since the rule may be executed more than once on bootup. For example, in the second rule, «/devices/pci*/*1c.0/*/net/enp*» would be wrong since it will stop matching once the name is changed to en . Only the system-default rule will fire the second time around, causing the name to be changed back to e.g. enp1s0 .

If you are using a USB network device (e.g. Android phone tethering) that has a dynamic MAC address and you want to be able to use different USB ports, you could use a rule that matched depending on vendor and product ID instead:

To test your rules, they can be triggered directly from userspace, e.g. with udevadm —debug test /sys/class/net/* . Remember to first take down the interface you are trying to rename (e.g. ip link set enp1s0 down ).

Revert to traditional interface names

If you would prefer to retain traditional interface names such as eth0, Predictable Network Interface Names can be disabled by masking the udev rule:

Alternatively, add net.ifnames=0 to the kernel parameters.

Set device MTU and queue length

You can change the device MTU and queue length by defining manually with an udev-rule. For example:

mtu : Using a value larger than 1500 (so called jumbo frames) can significantly speed up your network transfers. Note that all network interfaces, including switches in the local network, must support the same MTU in order to use jumbo frames. For PPPoE, the MTU should not be larger than 1492. You can also set MTU via systemd.netdev(5) .

tx_queue_len : Small value for slower devices with a high latency like modem links and ISDN. High value is recommended for server connected over the high-speed internet connections that perform large data transfers.

Bonding or LAG

IP address aliasing

IP aliasing is the process of adding more than one IP address to a network interface. With this, one node on a network can have multiple connections to a network, each serving a different purpose. Typical uses are virtual hosting of Web and FTP servers, or reorganizing servers without having to update any other machines (this is especially useful for nameservers).

Example

To manually set an alias, for some NIC, use iproute2 to execute

To remove a given alias execute

Packets destined for a subnet will use the primary alias by default. If the destination IP is within a subnet of a secondary alias, then the source IP is set respectively. Consider the case where there is more than one NIC, the default routes can be listed with ip route .

Promiscuous mode

Toggling promiscuous mode will make a (wireless) NIC forward all traffic it receives to the OS for further processing. This is opposite to «normal mode» where a NIC will drop frames it is not intended to receive. It is most often used for advanced network troubleshooting and packet sniffing.

If you want to enable promiscuous mode on interface enp2s0 run enable promiscuous@enp2s0.service .

Investigate sockets

ss is a utility to investigate network ports and is part of the iproute2 package. It has a similar functionality to the deprecated netstat utility.

Common usage includes:

Display all TCP Sockets with service names:

Display all TCP Sockets with port numbers:

Display all UDP Sockets:

For more information see ss(8) .

Troubleshooting

The TCP window scaling problem

TCP packets contain a «window» value in their headers indicating how much data the other host may send in return. This value is represented with only 16 bits, hence the window size is at most 64KiB. TCP packets are cached for a while (they have to be reordered), and as memory is (or used to be) limited, one host could easily run out of it.

Back in 1992, as more and more memory became available, RFC 1323 was written to improve the situation: Window Scaling. The «window» value, provided in all packets, will be modified by a Scale Factor defined once, at the very beginning of the connection. That 8-bit Scale Factor allows the Window to be up to 32 times higher than the initial 64KiB.

It appears that some broken routers and firewalls on the Internet are rewriting the Scale Factor to 0 which causes misunderstandings between hosts. The Linux kernel 2.6.17 introduced a new calculation scheme generating higher Scale Factors, virtually making the aftermaths of the broken routers and firewalls more visible.

The resulting connection is at best very slow or broken.

How to diagnose the problem

First of all, let us make it clear: this problem is odd. In some cases, you will not be able to use TCP connections (HTTP, FTP, . ) at all and in others, you will be able to communicate with some hosts (very few).

When you have this problem, the output from dmesg is okay, logs are clean and ip addr will report normal status. and actually everything appears normal.

If you cannot browse any website, but you can ping some random hosts, chances are great that you are experiencing this problem: ping uses ICMP and is not affected by TCP problems.

You can try to use Wireshark. You might see successful UDP and ICMP communications but unsuccessful TCP communications (only to foreign hosts).

Ways of fixing it

To fix it the bad way, you can change the tcp_rmem value, on which Scale Factor calculation is based. Although it should work for most hosts, it is not guaranteed, especially for very distant ones.

Simply disable Window Scaling. Since Window Scaling is a nice TCP feature, it may be uncomfortable to disable it, especially if you cannot fix the broken router. There are several ways to disable Window Scaling, and it seems that the most bulletproof way (which will work with most kernels) is to add the following line to /etc/sysctl.d/99-disable_window_scaling.conf (see also sysctl):

This problem is caused by broken routers/firewalls, so let us change them. Some users have reported that the broken router was their very own DSL router.

More about it

This section is based on the LWN article TCP window scaling and broken routers and an archived Kernel Trap article: Window Scaling on the Internet.

There are also several relevant threads on the LKML.

Connected second PC unable to use bridged LAN

First PC have two LAN. Second PC have one LAN and connected to first PC. Lets go second PC to give all access to LAN after bridged interface:

This article or section needs expansion.

Источник

Читайте также:  Как сбросить настройки линукс до заводских
Оцените статью