Linux list all devices in network

Список сетевых интерфейсов Linux

В операционной системе Linux не только жесткие и SSD диски представлены файлами в специальной файловой системе, но и сетевые интерфейсы. Существует несколько способов посмотреть список сетевых интерфейсов Linux, но самый простой из них — это просто посмотреть содержимое папки в файловой системе.

В этой небольшой статье мы рассмотрим все основные способы выполнить эту задачу в терминале или графическом интерфейсе.

Список сетевых интерфейсов Linux

Сетевые интерфейсы проводного интернета Ethernet обычно имеют имя, начинающиеся с символов enp, например, enp3s0. Такое именование используется только если ваш дистрибутив использует systemd, иначе будет применена старая система именования, при которой имена начинаются с символов eth, например eth0. Беспроводные сетевые интерфейсы, обычно называются wlp или wlx при использовании systemd, например, wlp3s0. Без использования systemd имя беспроводного интерфейса будет начинаться с wlan, например wlan0. Все остальные интерфейсы обычно виртуальные. Один из самых основных виртуальных интерфейсов — lo. Это локальный интерфейс, который позволяет программам обращаться к этому компьютеру. А теперь рассмотрим несколько способов посмотреть их список.

1. Файловая система

Все файлы устройств сетевых интерфейсов находятся в папке /sys/class/net. Поэтому вы можете посмотреть её содержимое:

2. Утилита ifconfig

Утилита ifconfig выводит не только список сетевых интерфейсов, но и информацию о них, такую как состояние, IP адрес, MAC адрес и другие параметры. Для отображения всех интерфейсов достаточно выполнить программу без параметров:

3. Утилита ip

Программа ifconfig устарела и ей на смену пришла утилита ip. Она объединяет в себе функции нескольких программ, например ifconfig, route, brctl и других. Посмотреть список устройств с помощью ip можно выполнив команду:

Здесь информации намного меньше, показывается только состояние устройства, MTU и ещё несколько параметров. Можно вывести информацию в более компактном виде, использовав опцию -br:

ip -br link show

В таком случае все данные отображаются в одну строчку, выводится состояние, MAC адрес и ещё несколько опций.

4. Утилита nmcli

Посмотреть всю нужную информацию можно и с помощью консольной утилиты управлением брандмауэром — nmcli:

nmcli device status

Здесь выводится подключение NetworkManager, связанное с конкретным устройством, а также его состояние.

5. Утилита netstat

Программа netstat тоже умеет показывать сетевые интерфейсы и статистику по переданным данным если ей передать опцию -i:

6. Файл /proc/net/dev

В файле /proc/net/dev тоже содержится список всех сетевых интерфейсов, а также статистика их использования:

Выводы

Теперь вы знаете как посмотреть сетевые интерфейсы в Linux, как видите, это очень просто сделать. Если у вас остались вопросы, спрашивайте в комментариях!

Источник

How to Find What Devices are Connected to Network in Linux

Brief: This quick trick shows you how to find devices connected to your local network in Linux.

Wireless networks have always been a desirable target for wannabe hackers. Wireless networks are also more vulnerable to hacking than the wired ones.

Читайте также:  Linux zen kernel что это

Forget hacking, do you ever wonder that someone might be leeching off your hard paid wifi network? Maybe a neighbor who once connected to your network and now uses it as his/her own?

It would be nice to check what devices are on your network. This way you can also see if there are some unwanted devices on your network.

So you might end up thinking, “how do I find what devices are connected to my network”?

I’ll show you how to do that in this quick tutorial. Not only it’s a good idea from security point of view, it is also a good little exercise if you have interest in networking.

We will use both, command line and GUI, way for finding out what devices are connected to your local network in Linux. The process is very simple and easy to use even for beginners.

Before you see any of that, let me tell you that your router should also be able to show all the connected devices. Check your gateway ip address and then type it in a browser. This is usually the browser interface for your router. Enter the username and password and you can see all the details and devices connected to the router.

If you don’t remember the router password or you don’t want to go that way, here’s what else you could do.

A. Using Linux command to find devices on the network

Step 1: Install nmap

nmap is one of the most popular network scanning tool in Linux. Use the following command to install nmap in Ubuntu based Linux distributions:

You can easily install it in other Linux distributions as well. It should be in the official software repository.

Step 2: Get IP range of the network

Now we need to know the IP address range of the network. Use the ifconfig command to find the IP address in Linux. Look for wlan0 if you are using wifi or eth0 if you are using Ethernet.

$ ifconfig
wlan0 Link encap:Ethernet HWaddr 70:f1:a1:c2:f2:e9
inet addr:192.168.1.91 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::73f1:a1ef:fec2:f2e8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2135051 errors:0 dropped:0 overruns:0 frame:0
TX packets:2013773 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1434994913 (1.4 GB) TX bytes:636207445 (636.2 MB)

The important things are highlighted in bold. As you see my IP is 192.168.1.91 and the subnet mask is 255.255.255.0 which means that the ip address range on my network varies from 192.168.1.0 to 192.168.1.255.

You may also use ip a command to know your IP address in Ubuntu and other Linux distributions.

At the same time, I’ll recommend you to read about basic Linux networking commands for more information.

Step 3: Scan to find devices connected to your network

It is advisable to use root privileges while scanning the network for more accurate information. Use the nmap command in the following way:

$ sudo nmap -sn 192.168.1.0/24
Starting Nmap 5.21 ( http://nmap.org ) at 2012-09-01 21:59 CEST

Nmap scan report for neufbox (192.168.1.1)
Host is up (0.012s latency).
MAC Address: E0:A1:D5:72:5A:5C (Unknown)
Nmap scan report for takshak-bambi (192.168.1.91)
Host is up.
Nmap scan report for android-95b23f67te05e1c8 (192.168.1.93)
Host is up (0.36s latency).

As you can see that there are three devices connected to my network. The router itself, my laptop and my Galaxy S2.

If you are wondering about why I used 24 in the above command, you should know a little about CIDR notation. It basically means that the scanning will be from 192.168.1.0 to 192.168.1.255.

B. Using GUI tool to find devices connected to network

When I first wrote this article, there was no GUI tool for this task. Then I came across a new network monitoring tool being developed for elementary OS. I suggested including a periodic device scan feature in this tool and the developer readily agreed.

Читайте также:  Kyocera m2040dn картридж аналог

So, now we have a GUI tool that does this task. It’s called Nutty (last updated in 2019). Just install this app and run it. It will periodically scan for new devices on the network and will notify you if there is a new device.

This application is only available for elementary OS, Ubuntu and hopefully, other Ubuntu based Linux distributions. You can find installation instructions on this detailed article on Nutty.

Oh, you can also log in to your router and see the devices connected to your devices. I let you figure the best way to find devices connected to your network.

Creator of It’s FOSS. An ardent Linux user & open source promoter. Huge fan of classic detective mysteries ranging from Agatha Christie and Sherlock Holmes to Detective Columbo & Ellery Queen. Also a movie buff with a soft corner for film noir.

Источник

How To Find Available Network Interfaces On Linux

List Ethernet Cards In Linux And Unix

We can configure network interfaces in Linux during the installation time. But, some of you might prefer to do it after installation or change the existing settings. As you know already, you must first know how many interfaces are available on the system in-order to configure network settings from command line. This detailed tutorial addresses all the possible ways to list and find available network interfaces on Linux and Unix operating systems.

Find available network interfaces in Linux

We can find the available network cards in couple ways. In this guide, we will discuss 10 ways to list network interface cards in Linux.

1. List network interfaces using ifconfig command

The most commonly used method to find the network interface details using ifconfig command. I believe some of Linux users might still use this.

Sample output:

As you see in the above output, I have two network interfaces namely enp5s0 (on board wired ethernet adapter) and wlp9s0 (wireless network adapter) on my Linux box. Here, lo is loopback interface, which is used to access all network services locally. It has an IP address 127.0.0.1 .

We can also use the same ‘ifconfig’ command in many UNIX variants, for example FreeBSD, to list available network cards.

2. List network interfaces using ip command

The ‘ifconfig’ command is deprecated in the latest Linux versions. So you can use ‘ip’ command to display the network interfaces as shown below.

Sample output:

You can also use the following commands as well.

Did you notice that these command also shows the connected state of the network interfaces? If you closely look at the above output, you will notice that my Ethernet card is not connected with network cable (see the word «DOWN» in the above output). And wireless network card is connected (See the word «UP»). For more details, check our previous guide to find the connected state of network interfaces on Linux.

These two commands ( ifconfig and ip ) are just enough to find the available network cards on your Linux systems.

However, there are few other methods available to list network interfaces on Linux.

3. List network interfaces using /sys/class/net/ directory

The Linux Kernel saves the network interface details inside /sys/class/net directory. You can verify the list of available interfaces by looking into this directory.

Sample output:

4. List network interfaces using /proc/net/dev file

In Linux operating systems, /proc/net/dev file contains statistics about network interfaces.

To view the available network cards, just view its contents using command:

Sample output:

5. List network interfaces using netstat command

The netstat command displays various details such as network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

Читайте также:  Как правильно установить принтер для печати

Sample output:

Please be mindful that netstat is obsolete. The Replacement for «netstat -i» is «ip -s link» . Also note that this method will list only the active interfaces, not all available interfaces.

6. List network interfaces using nmcli command

The nmcli is a command-line tool for controlling NetworkManager and reporting network status. It is used to create, display, edit, delete, activate, and deactivate network connections and display network status.

If you have Linux system with Network Manager installed, you can list the available network interfaces using nmcli tool using the following commands:

Sample output:

You can also use this command to show network interfaces in your Linux system:

Most of the aforementioned utilities comes pre-installed in most Linux and Unix systems. There are also a few more external utilities available to show list of network cards.

7. Show list of network interfaces using hwinfo

Hwinfo is a command line utility to view the hardware information in a Linux system. It probes for the hardware present in a Linux system and displays the extensive details of each hardware device.

Hwinfo is available in the official repositories of many Linux distributions. To install hwinfo on RPM-based systems, run:

On Deb-based systems, you can install hwinfo using the following command:

Once installed, run the following command to list the name of the network interfaces using hwinfo utility:

Sample output:

8. Show network interfaces using lshw

Lshw (Hardware Lister) is a CLI utility that provides detailed information of the hardware configuration of a Linux system.

To show the list of network cards in Linux with lshw utility, run:

Sample output:

9. View network interfaces using inxi

Inxi is yet another command line system information tool like hwinfo and lshw. It shows system hardware, CPU, drivers, Xorg, Desktop, Kernel, GCC version(s), Processes, RAM usage, and a wide variety of other useful information.

To show information about the network cards, including the vendor, card driver and number of available network interfaces in a Linux system, run inix with -N option:

Related read:

10. Display network interfaces using lspci

The lspci command lists all PCI devices in a Linux system.

To view the list of available network interfaces in a Linux system, use lspci with egrep command like below:

Sample output:

List only the name of available network interfaces

What we have seen so far is various methods to find the available network interfaces in Linux. In all of the aforementioned methods, we displayed the available network interfaces along with some additional details, such as RX/TX details, Mac address, connected state, mode, type of the network and a few more. If you want to strip unnecessary details and list only the name of the network interfaces, you can use one of the following commands.

Sample output:

To exclude the loopback device (lo) from the output, run this command instead:

As stated earlier, ifconfig command is deprecated. If ifconfig command is not available, use ip command to display only the name of the network interfaces with -o flag like below:

You can also use the following command as well:

Conclusion

In this guide, we discussed ten different methods to find and list the available network interfaces on Linux and Unix. We’ve also looked at a few ways to display only the name of the network interfaces in Linux.

Check the following guides to know how to configure IP address on Linux.

Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix enthusiast and FOSS supporter. He lives in Tamilnadu, India.

Источник

КомпСовет