Skip to main content

如何检查 Linux 中的开放端口列表? | Linux 中国


最近,我们就同一主题写了两篇文章。这些文章内容帮助你如何检查远程服务器中给定的端口是否打开。
如果你想 检查远程 Linux 系统上的端口是否打开[1] 请点击链接浏览。如果你想 检查多个远程 Linux 系统上的端口是否打开[2] 请点击链接浏览。如果你想 检查多个远程 Linux 系统上的多个端口状态[2] 请点击链接浏览。
但是本文帮助你检查本地系统上的开放端口列表。
在 Linux 中很少有用于此目的的实用程序。然而,我提供了四个最重要的 Linux 命令来检查这一点。
你可以使用以下四个命令来完成这个工作。这些命令是非常出名的并被 Linux 管理员广泛使用。
◈ netstat:netstat (“network statistics”) 是一个显示网络连接(进和出)相关信息命令行工具,例如:路由表, 伪装连接,多点传送成员和网络端口。
◈ nmap:Nmap (“Network Mapper”) 是一个网络探索与安全审计的开源工具。它旨在快速扫描大型网络。
◈ ss: ss 被用于转储套接字统计信息。它也可以类似 netstat 使用。相比其他工具它可以展示更多的TCP状态信息。
◈ lsof: lsof 是 List Open File 的缩写. 它用于输出被某个进程打开的所有文件。
如何使用 Linux 命令 netstat 检查系统中的开放端口列表
netstat 是 Network Statistics 的缩写,是一个显示网络连接(进和出)相关信息命令行工具,例如:路由表、伪装连接、多播成员和网络端口。
它可以列出所有的 tcp、udp 连接和所有的 unix 套接字连接。
它用于发现发现网络问题,确定网络连接数量。
  1. # netstat -tplugn
  2. Active Internet connections (only servers)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 2038/master
  5. tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 1396/snmpd
  6. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1398/httpd
  7. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1388/sshd
  8. tcp6 0 0 :::25 :::* LISTEN 2038/master
  9. tcp6 0 0 :::22 :::* LISTEN 1388/sshd
  10. udp 0 0 0.0.0.0:39136 0.0.0.0:* 1396/snmpd
  11. udp 0 0 0.0.0.0:56130 0.0.0.0:* 1396/snmpd
  12. udp 0 0 0.0.0.0:40105 0.0.0.0:* 1396/snmpd
  13. udp 0 0 0.0.0.0:11584 0.0.0.0:* 1396/snmpd
  14. udp 0 0 0.0.0.0:30105 0.0.0.0:* 1396/snmpd
  15. udp 0 0 0.0.0.0:50656 0.0.0.0:* 1396/snmpd
  16. udp 0 0 0.0.0.0:1632 0.0.0.0:* 1396/snmpd
  17. udp 0 0 0.0.0.0:28265 0.0.0.0:* 1396/snmpd
  18. udp 0 0 0.0.0.0:40764 0.0.0.0:* 1396/snmpd
  19. udp 0 0 10.90.56.21:123 0.0.0.0:* 895/ntpd
  20. udp 0 0 127.0.0.1:123 0.0.0.0:* 895/ntpd
  21. udp 0 0 0.0.0.0:123 0.0.0.0:* 895/ntpd
  22. udp 0 0 0.0.0.0:53390 0.0.0.0:* 1396/snmpd
  23. udp 0 0 0.0.0.0:161 0.0.0.0:* 1396/snmpd
  24. udp6 0 0 :::123 :::* 895/ntpd
  25. IPv6/IPv4 Group Memberships
  26. Interface RefCnt Group
  27. --------------- ------ ---------------------
  28. lo 1 224.0.0.1
  29. eth0 1 224.0.0.1
  30. lo 1 ff02::1
  31. lo 1 ff01::1
  32. eth0 1 ff02::1
  33. eth0 1 ff01::1
你也可以使用下面的命令检查特定的端口。
  1. # # netstat -tplugn | grep :22
  2. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1388/sshd
  3. tcp6 0 0 :::22 :::* LISTEN 1388/sshd
如何使用 Linux 命令 ss 检查系统中的开放端口列表?
ss 被用于转储套接字统计信息。它也可以显示类似 netstat 的信息。相比其他工具它可以展示更多的 TCP 状态信息。
  1. # ss -lntu
  2. Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
  3. udp UNCONN 0 0 *:39136 *:*
  4. udp UNCONN 0 0 *:56130 *:*
  5. udp UNCONN 0 0 *:40105 *:*
  6. udp UNCONN 0 0 *:11584 *:*
  7. udp UNCONN 0 0 *:30105 *:*
  8. udp UNCONN 0 0 *:50656 *:*
  9. udp UNCONN 0 0 *:1632 *:*
  10. udp UNCONN 0 0 *:28265 *:*
  11. udp UNCONN 0 0 *:40764 *:*
  12. udp UNCONN 0 0 10.90.56.21:123 *:*
  13. udp UNCONN 0 0 127.0.0.1:123 *:*
  14. udp UNCONN 0 0 *:123 *:*
  15. udp UNCONN 0 0 *:53390 *:*
  16. udp UNCONN 0 0 *:161 *:*
  17. udp UNCONN 0 0 :::123 :::*
  18. tcp LISTEN 0 100 *:25 *:*
  19. tcp LISTEN 0 128 127.0.0.1:199 *:*
  20. tcp LISTEN 0 128 *:80 *:*
  21. tcp LISTEN 0 128 *:22 *:*
  22. tcp LISTEN 0 100 :::25 :::*
  23. tcp LISTEN 0 128 :::22 :::*
你也可以使用下面的命令检查特定的端口。
  1. # # ss -lntu | grep ':25'
  2. tcp LISTEN 0 100 *:25 *:*
  3. tcp LISTEN 0 100 :::25 :::*
如何使用 Linux 命令 nmap 检查系统中的开放端口列表?
Nmap (“Network Mapper”) 是一个网络探索与安全审计的开源工具。它旨在快速扫描大型网络,当然它也可以工作在独立主机上。
Nmap 使用裸 IP 数据包以一种新颖的方式来确定网络上有哪些主机可用,这些主机提供什么服务(应用程序名称和版本),它们运行什么操作系统(版本),使用什么类型的数据包过滤器/防火墙,以及许多其他特征。
虽然 Nmap 通常用于安全审计,但许多系统和网络管理员发现它对于日常工作也非常有用,例如网络资产清点、管理服务升级计划以及监控主机或服务正常运行时间。
  1. # nmap -sTU -O localhost
  2. Starting Nmap 6.40 ( http://nmap.org ) at 2019-03-20 09:57 CDT
  3. Nmap scan report for localhost (127.0.0.1)
  4. Host is up (0.00028s latency).
  5. Other addresses for localhost (not scanned): 127.0.0.1
  6. Not shown: 1994 closed ports
  7. PORT STATE SERVICE
  8. 22/tcp open ssh
  9. 25/tcp open smtp
  10. 80/tcp open http
  11. 199/tcp open smux
  12. 123/udp open ntp
  13. 161/udp open snmp
  14. Device type: general purpose
  15. Running: Linux 3.X
  16. OS CPE: cpe:/o:linux:linux_kernel:3
  17. OS details: Linux 3.7 - 3.9
  18. Network Distance: 0 hops
  19. OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
  20. Nmap done: 1 IP address (1 host up) scanned in 1.93 seconds
你也可以使用下面的命令检查特定的端口。
  1. # nmap -sTU -O localhost | grep 123
  2. 123/udp open ntp
如何使用 Linux 命令 lsof 检查系统中的开放端口列表?
它向你显示系统上打开的文件列表以及打开它们的进程。还会向你显示与文件相关的其他信息。
  1. # lsof -i
  2. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  3. ntpd 895 ntp 16u IPv4 18481 0t0 UDP *:ntp
  4. ntpd 895 ntp 17u IPv6 18482 0t0 UDP *:ntp
  5. ntpd 895 ntp 18u IPv4 18487 0t0 UDP localhost:ntp
  6. ntpd 895 ntp 20u IPv4 23020 0t0 UDP CentOS7.2daygeek.com:ntp
  7. sshd 1388 root 3u IPv4 20065 0t0 TCP *:ssh (LISTEN)
  8. sshd 1388 root 4u IPv6 20067 0t0 TCP *:ssh (LISTEN)
  9. snmpd 1396 root 6u IPv4 22739 0t0 UDP *:snmp
  10. snmpd 1396 root 7u IPv4 22729 0t0 UDP *:40105
  11. snmpd 1396 root 8u IPv4 22730 0t0 UDP *:50656
  12. snmpd 1396 root 9u IPv4 22731 0t0 UDP *:pammratc
  13. snmpd 1396 root 10u IPv4 22732 0t0 UDP *:30105
  14. snmpd 1396 root 11u IPv4 22733 0t0 UDP *:40764
  15. snmpd 1396 root 12u IPv4 22734 0t0 UDP *:53390
  16. snmpd 1396 root 13u IPv4 22735 0t0 UDP *:28265
  17. snmpd 1396 root 14u IPv4 22736 0t0 UDP *:11584
  18. snmpd 1396 root 15u IPv4 22737 0t0 UDP *:39136
  19. snmpd 1396 root 16u IPv4 22738 0t0 UDP *:56130
  20. snmpd 1396 root 17u IPv4 22740 0t0 TCP localhost:smux (LISTEN)
  21. httpd 1398 root 3u IPv4 20337 0t0 TCP *:http (LISTEN)
  22. master 2038 root 13u IPv4 21638 0t0 TCP *:smtp (LISTEN)
  23. master 2038 root 14u IPv6 21639 0t0 TCP *:smtp (LISTEN)
  24. sshd 9052 root 3u IPv4 1419955 0t0 TCP CentOS7.2daygeek.com:ssh->Ubuntu18-04.2daygeek.com:11408 (ESTABLISHED)
  25. httpd 13371 apache 3u IPv4 20337 0t0 TCP *:http (LISTEN)
  26. httpd 13372 apache 3u IPv4 20337 0t0 TCP *:http (LISTEN)
  27. httpd 13373 apache 3u IPv4 20337 0t0 TCP *:http (LISTEN)
  28. httpd 13374 apache 3u IPv4 20337 0t0 TCP *:http (LISTEN)
  29. httpd 13375 apache 3u IPv4 20337 0t0 TCP *:http (LISTEN)
你也可以使用下面的命令检查特定的端口。
  1. # lsof -i:80
  2. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  3. httpd 1398 root 3u IPv4 20337 0t0 TCP *:http (LISTEN)
  4. httpd 13371 apache 3u IPv4 20337 0t0 TCP *:http (LISTEN)
  5. httpd 13372 apache 3u IPv4 20337 0t0 TCP *:http (LISTEN)
  6. httpd 13373 apache 3u IPv4 20337 0t0 TCP *:http (LISTEN)
  7. httpd 13374 apache 3u IPv4 20337 0t0 TCP *:http (LISTEN)
  8. httpd 13375 apache 3u IPv4 20337 0t0 TCP *:http (LISTEN)

via: https://www.2daygeek.com/linux-scan-check-open-ports-using-netstat-ss-nmap/

Comments

Popular posts from this blog

OWASP Top 10 Threats and Mitigations Exam - Single Select

Last updated 4 Aug 11 Course Title: OWASP Top 10 Threats and Mitigation Exam Questions - Single Select 1) Which of the following consequences is most likely to occur due to an injection attack? Spoofing Cross-site request forgery Denial of service   Correct Insecure direct object references 2) Your application is created using a language that does not support a clear distinction between code and data. Which vulnerability is most likely to occur in your application? Injection   Correct Insecure direct object references Failure to restrict URL access Insufficient transport layer protection 3) Which of the following scenarios is most likely to cause an injection attack? Unvalidated input is embedded in an instruction stream.   Correct Unvalidated input can be distinguished from valid instructions. A Web application does not validate a client’s access to a resource. A Web action performs an operation on behalf of the user without checking a shared sec

CKA Simulator Kubernetes 1.22

  https://killer.sh Pre Setup Once you've gained access to your terminal it might be wise to spend ~1 minute to setup your environment. You could set these: alias k = kubectl                         # will already be pre-configured export do = "--dry-run=client -o yaml"     # k get pod x $do export now = "--force --grace-period 0"   # k delete pod x $now Vim To make vim use 2 spaces for a tab edit ~/.vimrc to contain: set tabstop=2 set expandtab set shiftwidth=2 More setup suggestions are in the tips section .     Question 1 | Contexts Task weight: 1%   You have access to multiple clusters from your main terminal through kubectl contexts. Write all those context names into /opt/course/1/contexts . Next write a command to display the current context into /opt/course/1/context_default_kubectl.sh , the command should use kubectl . Finally write a second command doing the same thing into /opt/course/1/context_default_no_kubectl.sh , but without the use of k

标 题: 关于Daniel Guo 律师

发信人: q123452017 (水天一色), 信区: I140 标  题: 关于Daniel Guo 律师 关键字: Daniel Guo 发信站: BBS 未名空间站 (Thu Apr 26 02:11:35 2018, 美东) 这些是lz根据亲身经历在 Immigration版上发的帖以及一些关于Daniel Guo 律师的回 帖,希望大家不要被一些马甲帖广告帖所骗,慎重考虑选择律师。 WG 和Guo两家律师对比 1. fully refund的合约上的区别 wegreened家是case不过只要第二次没有file就可以fully refund。郭家是要两次case 没过才给refund,而且只要第二次pl draft好律师就可以不退任何律师费。 2. 回信速度 wegreened家一般24小时内回信。郭律师是在可以快速回复的时候才回复很快,对于需 要时间回复或者是不愿意给出确切答复的时候就回复的比较慢。 比如:lz问过郭律师他们律所在nsc区域最近eb1a的通过率,大家也知道nsc现在杀手如 云,但是郭律师过了两天只回复说让秘书update最近的case然后去网页上查,但是上面 并没有写明tsc还是nsc。 lz还问过郭律师关于准备ps (他要求的文件)的一些问题,模版上有的东西不是很清 楚,但是他一般就是把模版上的东西再copy一遍发过来。 3. 材料区别 (推荐信) 因为我只收到郭律师写的推荐信,所以可以比下两家推荐信 wegreened家推荐信写的比较长,而且每封推荐信会用不同的语气和风格,会包含lz写 的research summary里面的某个方面 郭家四封推荐信都是一个格式,一种语气,连地址,信的称呼都是一样的,怎么看四封 推荐信都是同一个人写出来的。套路基本都是第一段目的,第二段介绍推荐人,第三段 某篇或几篇文章的abstract,最后结论 4. 前期材料准备 wegreened家要按照他们的模版准备一个十几页的research summary。 郭律师在签约之前说的是只需要准备五页左右的summary,但是在lz签完约收到推荐信 ,郭律师又发来一个很长的ps要lz自己填,而且和pl的格式基本差不多。 总结下来,申请自己上心最重要。但是如果选律师,lz更倾向于wegreened,