Как посмотреть открытые порты в Linux
Сетевые порты — это механизм, с помощью которого операционная система определяет какой именно программе необходимо передать сетевой пакет. Здесь можно привести пример с домом. Например, почтальону необходимо доставить посылку. Он доставляет посылку к дому, это IP адрес компьютера. А дальше в самом доме уже должны разобраться в какую квартиру направить эту посылку. Номер квартиры — это уже порт.
Если порт открыт это означает, что какая либо программа, обычно сервис, использует его для связи с другой программой через интернет или в локальной системе. Чтобы посмотреть какие порты открыты в вашей системе Linux можно использовать множество различных утилит. В этой статье мы рассмотрим самые популярные способы посмотреть открытые порты Linux.
Как посмотреть открытые порты linux
1. netstat
Утилита netstat позволяет увидеть открытые в системе порты, а также открытые на данный момент сетевые соединения. Для отображения максимально подробной информации надо использовать опции:
- -l или —listening — посмотреть только прослушиваемые порты;
- -p или —program — показать имя программы и ее PID;
- -t или —tcp — показать tcp порты;
- -u или —udp показать udp порты;
- -n или —numeric показывать ip адреса в числовом виде.
Открытые порты Linux, которые ожидают соединений имеют тип LISTEN, а перед портом отображается IP адрес на котором сервис ожидает подключений. Это может быть определенный IP адрес или */0.0.0.0 что означают любой доступный адрес:
sudo netstat -tulpn
Утилита ss — это современная альтернатива для команды netstat. В отличие от netstat, которая берет информацию из каталога /proc, утилита ss напрямую связывается со специальной подсистемой ядра Linux, поэтому работает быстрее и её данные более точные, если вы хотите выполнить просмотр открытых портов это не имеет большого значения. Опции у неё такие же:
Можно вывести только процессы, работающие на 80-том порту:
sudo ss -tulpn | grep :80
3. lsof
Утилита lsof позволяет посмотреть все открытые в системе соединения, в том числе и сетевые, для этого нужно использовать опцию -i, а чтобы отображались именно порты, а не названия сетевых служб следует использовать опцию -P:
Ещё один пример, смотрим какие процессы работают с портом 80:
sudo lsof -i -P | grep :80
4. Nmap
Программа Nmap — мощный сетевой сканер, разработанный для сканирования и тестирования на проникновение удаленных узлов, но ничего не мешает направить его на локальный компьютер. Утилита позволяет не только посмотреть открытые порты, но и примерно определить какие сервисы их слушают и какие уязвимости у них есть. Программу надо установить:
sudo apt install nmap
Затем можно использовать:
Для простого сканирования можно запускать утилиту без опций. Детальнее о её опциях можно узнать в статье про сканирование сети в Nmap. Эта утилита ещё будет полезна если вы хотите посмотреть какие порты на компьютере доступны из интернета.
Если это публичный сервер, то результат скорее всего не будет отличатся от локального сканирования, но на домашнем компьютере все немного по другому. Первый вариант — используется роутер и в сеть будут видны только порты роутера, еще одним порогом защиты может стать NAT-сервер провайдера. Технология NAT позволяет нескольким пользователям использовать один внешний IP адрес. И так для просмотра открытых внешних портов сначала узнаем внешний ip адрес, для надежности воспользуемся онлайн сервисом:
wget -O — -q eth0.me
Дальше запускаем сканирование:
В результате мы видим, что открыт порт 80 веб-сервера и 22 — порт службы ssh, я их не открывал, эти порты открыты роутером, 80 — для веб-интерфейса, а 22 для может использоваться для обновления прошивки. А еще можно вообще не получить результатов, это будет означать что все порты закрыты, или на сервере установлена система защиты от вторжений IDS. Такая проверка портов может оказаться полезной для того, чтобы понять находится ли ваш компьютер в безопасности и нет ли там лишних открытых портов, доступных всем.
5. Zenmap
Программа Zenmap — это графический интерфейс для nmap. Она не делает ничего нового кроме того, что может делать nmap, просто предоставляет ко всему этому удобный интерфейс. Для её установки выполните:
sudo apt install zenmap
Запустить программу можно из главного меню или командой:
Затем введите адрес localhost в поле Цель и нажмите кнопку Сканирование:
После завершения сканирования утилита вывела список открытых портов Linux.
Выводы
В этой статье мы рассмотрели инструменты, которые вы можете использовать для того чтобы узнать узнать открытые порты linux. Инструментов не так много как для просмотра информации об оперативной памяти или процессоре, но их вполне хватает. А какими программами пользуетесь вы? Напишите в комментариях!
Источник
Linux china open port
Recently, we wrote two articles on the same topic. These articles help you to check whether the given port in the remote server is open.
if you want Check if the port on the remote Linux system is open [1] Please click the link to browse. if you want Check if ports on multiple remote Linux systems are open [2] Please click the link to browse. if you want Check the status of multiple ports on multiple remote Linux systems [2] Please click the link to browse.
But this article helps you check the list of open ports on the local system.
There are very few utilities for this purpose in Linux. However, I provide the four most important Linux commands to check this.
You can use the following four commands to complete this work. These commands are very famous and widely used by Linux administrators.
◈ netstat: Netstat («network statistics») is a command-line tool that displays information about network connections (in and out), such as routing tables, disguised connections, multicast members and network ports. ◈nmap: Nmap («Network Mapper») is an open source tool for network exploration and security auditing. It is designed to quickly scan large networks. ◈ss: Used to dump socket statistics. It can also be used similar to netstat. It can display more TCP status information than other tools. ◈lsof:Lsof is short for List Open. It is used to output all files opened by a certain process.
How to use the Linux command netstat to check the list of open ports in the system
netstatIt is an abbreviation of Network Statistics, which is a command-line tool that displays information about network connections (in and out), such as routing tables, disguised connections, multicast members, and network ports.
It can list all tcp, udp connections and all unix socket connections.
It is used to discover network problems and determine the number of network connections.
- # netstat — tplugn
- Active Internet connections ( only servers )
- Proto Recv — Q Send — Q Local Address Foreign Address State PID / Program name
- tcp 0 0 0.0 . 0.0 : 25 0.0 . 0.0 :* LISTEN 2038 / master
- tcp 0 0 127.0 . 0.1 : 199 0.0 . 0.0 :* LISTEN 1396 / snmpd
- tcp 0 0 0.0 . 0.0 : 80 0.0 . 0.0 :* LISTEN 1398 / httpd
- tcp 0 0 0.0 . 0.0 : 22 0.0 . 0.0 :* LISTEN 1388 / sshd
- tcp6 0 0 . 25 . * LISTEN 2038 / master
- tcp6 0 0 . 22 . * LISTEN 1388 / sshd
- udp 0 0 0.0 . 0.0 : 39136 0.0 . 0.0 :* 1396 / snmpd
- udp 0 0 0.0 . 0.0 : 56130 0.0 . 0.0 :* 1396 / snmpd
- udp 0 0 0.0 . 0.0 : 40105 0.0 . 0.0 :* 1396 / snmpd
- udp 0 0 0.0 . 0.0 : 11584 0.0 . 0.0 :* 1396 / snmpd
- udp 0 0 0.0 . 0.0 : 30105 0.0 . 0.0 :* 1396 / snmpd
- udp 0 0 0.0 . 0.0 : 50656 0.0 . 0.0 :* 1396 / snmpd
- udp 0 0 0.0 . 0.0 : 1632 0.0 . 0.0 :* 1396 / snmpd
- udp 0 0 0.0 . 0.0 : 28265 0.0 . 0.0 :* 1396 / snmpd
- udp 0 0 0.0 . 0.0 : 40764 0.0 . 0.0 :* 1396 / snmpd
- udp 0 0 10.90 . 56.21 : 123 0.0 . 0.0 :* 895 / ntpd
- udp 0 0 127.0 . 0.1 : 123 0.0 . 0.0 :* 895 / ntpd
- udp 0 0 0.0 . 0.0 : 123 0.0 . 0.0 :* 895 / ntpd
- udp 0 0 0.0 . 0.0 : 53390 0.0 . 0.0 :* 1396 / snmpd
- udp 0 0 0.0 . 0.0 : 161 0.0 . 0.0 :* 1396 / snmpd
- udp6 0 0 . 123 . * 895 / ntpd
- IPv6 / IPv4 Group Memberships
- Interface RefCnt Group
- ————— —— ———————
- lo 1 224.0 . 0.1
- eth0 1 224.0 . 0.1
- lo 1 ff02 :: 1
- lo 1 ff01 :: 1
- eth0 1 ff02 :: 1
- eth0 1 ff01 :: 1
You can also use the following command to check a specific port.
- # # netstat — tplugn | grep : 22
- tcp 0 0 0.0 . 0.0 : 22 0.0 . 0.0 :* LISTEN 1388 / sshd
- tcp6 0 0 . 22 . * LISTEN 1388 / sshd
How to use the Linux command to check the list of open ports in the system?
ssUsed to dump socket statistics. It can also display something likenetstat Information. It can display more TCP status information than other tools.
- # ss — lntu
- Netid State Recv — Q Send — Q Local Address : Port Peer Address : Port
- udp UNCONN 0 0 *: 39136 *:*
- udp UNCONN 0 0 *: 56130 *:*
- udp UNCONN 0 0 *: 40105 *:*
- udp UNCONN 0 0 *: 11584 *:*
- udp UNCONN 0 0 *: 30105 *:*
- udp UNCONN 0 0 *: 50656 *:*
- udp UNCONN 0 0 *: 1632 *:*
- udp UNCONN 0 0 *: 28265 *:*
- udp UNCONN 0 0 *: 40764 *:*
- udp UNCONN 0 0 10.90 . 56.21 : 123 *:*
- udp UNCONN 0 0 127.0 . 0.1 : 123 *:*
- udp UNCONN 0 0 *: 123 *:*
- udp UNCONN 0 0 *: 53390 *:*
- udp UNCONN 0 0 *: 161 *:*
- udp UNCONN 0 0 . 123 . *
- tcp LISTEN 0 100 *: 25 *:*
- tcp LISTEN 0 128 127.0 . 0.1 : 199 *:*
- tcp LISTEN 0 128 *: 80 *:*
- tcp LISTEN 0 128 *: 22 *:*
- tcp LISTEN 0 100 . 25 . *
- tcp LISTEN 0 128 . 22 . *
You can also use the following command to check a specific port.
- # # ss — lntu | grep ‘:25’
- tcp LISTEN 0 100 *: 25 *:*
- tcp LISTEN 0 100 . 25 . *
How to use the Linux command nmap to check the list of open ports in the system?
Nmap («Network Mapper») is an open source tool for network exploration and security auditing. It is designed to quickly scan large networks, but of course it can also work on a standalone host.
Nmap uses bare IP packets in a novel way to determine which hosts are available on the network, what services (application name and version) these hosts provide, what operating system (version) they run, and what type of packet filtering is used / Firewall, and many other features.
Although Nmap is commonly used for security audits, many system and network administrators find it also useful for daily work, such as inventorying network assets, managing service upgrade plans, and monitoring host or service uptime.
- # nmap — sTU — O localhost
- Starting Nmap 6.40 ( http : //nmap.org ) at 2019-03-20 09:57 CDT
- Nmap scan report for localhost ( 127.0 . 0.1 )
- Host is up ( 0.00028s latency ).
- Other addresses for localhost ( not scanned ): 127.0 . 0.1
- Not shown : 1994 closed ports
- PORT STATE SERVICE
- 22 / tcp open ssh
- 25 / tcp open smtp
- 80 / tcp open http
- 199 / tcp open smux
- 123 / udp open ntp
- 161 / udp open snmp
- Device type : general purpose
- Running : Linux 3.X
- OS CPE : cpe :/ o : linux : linux_kernel : 3
- OS details : Linux 3.7 — 3.9
- Network Distance : 0 hops
- OS detection performed . Please report any incorrect results at http : //nmap.org/submit/ .
- Nmap done : 1 IP address ( 1 host up ) scanned in 1.93 seconds
You can also use the following command to check a specific port.
- # nmap — sTU — O localhost | grep 123
- 123 / udp open ntp
How to use Linux command to check the list of open ports in the system?
It shows you the list of open files on the system and the process of opening them. It will also show you other information related to the file.
- # lsof — i
- COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
- ntpd 895 ntp 16u IPv4 18481 0t0 UDP *: ntp
- ntpd 895 ntp 17u IPv6 18482 0t0 UDP *: ntp
- ntpd 895 ntp 18u IPv4 18487 0t0 UDP localhost : ntp
- ntpd 895 ntp 20u IPv4 23020 0t0 UDP CentOS7 . 2daygeek . com : ntp
- sshd 1388 root 3u IPv4 20065 0t0 TCP *: ssh ( LISTEN )
- sshd 1388 root 4u IPv6 20067 0t0 TCP *: ssh ( LISTEN )
- snmpd 1396 root 6u IPv4 22739 0t0 UDP *: snmp
- snmpd 1396 root 7u IPv4 22729 0t0 UDP *: 40105
- snmpd 1396 root 8u IPv4 22730 0t0 UDP *: 50656
- snmpd 1396 root 9u IPv4 22731 0t0 UDP *: pammratc
- snmpd 1396 root 10u IPv4 22732 0t0 UDP *: 30105
- snmpd 1396 root 11u IPv4 22733 0t0 UDP *: 40764
- snmpd 1396 root 12u IPv4 22734 0t0 UDP *: 53390
- snmpd 1396 root 13u IPv4 22735 0t0 UDP *: 28265
- snmpd 1396 root 14u IPv4 22736 0t0 UDP *: 11584
- snmpd 1396 root 15u IPv4 22737 0t0 UDP *: 39136
- snmpd 1396 root 16u IPv4 22738 0t0 UDP *: 56130
- snmpd 1396 root 17u IPv4 22740 0t0 TCP localhost : smux ( LISTEN )
- httpd 1398 root 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
- master 2038 root 13u IPv4 21638 0t0 TCP *: smtp ( LISTEN )
- master 2038 root 14u IPv6 21639 0t0 TCP *: smtp ( LISTEN )
- sshd 9052 root 3u IPv4 1419955 0t0 TCP CentOS7 . 2daygeek . com : ssh -> Ubuntu18 — 04.2daygeek . com : 11408 ( ESTABLISHED )
- httpd 13371 apache 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
- httpd 13372 apache 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
- httpd 13373 apache 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
- httpd 13374 apache 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
- httpd 13375 apache 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
You can also use the following command to check a specific port.
- # lsof — i : 80
- COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
- httpd 1398 root 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
- httpd 13371 apache 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
- httpd 13372 apache 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
- httpd 13373 apache 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
- httpd 13374 apache 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
- httpd 13375 apache 3u IPv4 20337 0t0 TCP *: http ( LISTEN )
Author: Magesh Maruthamuthu [4] Topics: lujun9972 Translator: heguangzhi Proofreading: wxy
This article consists of LCTT Original compilation, Linux China Honor launch
Источник