netstat
is very useful tool which provides a lot of information about the network of operating system. netstat
command can list ip addreass, route, port, connections etc. More detailed information about the netstat
command can be found in the following tutorial.
netstat
是非常有用的工具,可提供有关操作系统网络的大量信息。 netstat
命令可以列出ip addreass,路由,端口,连接等。有关netstat
命令的更多详细信息,请参见以下教程。
Linux Netstat Command With Examples
列出所有监听端口(List All Listening Ports)
We can use netstat
-l
options in order to list all listening ports. This will list both TCP and UDP ports with IPv4 and IPv6 . But also Unix domain sockets will be printed in the end of the list after TCP and UDP ports.
我们可以使用netstat
-l
选项来列出所有监听端口。 这将列出具有IPv4和IPv6的TCP和UDP端口。 但是,Unix域套接字也将打印在TCP和UDP端口之后的列表末尾。
$ netstat -l

列出监听的TCP端口(List Listening TCP Ports)
TCP is reliable protocol which provides non data loss. Applications generally prefers and uses TCP protocol for network connections and data transfer. We can use -t
option in order to only list TCP ports.
TCP是可靠的协议,可提供无数据丢失。 应用程序通常偏爱TCP协议并将其用于网络连接和数据传输。 我们可以使用-t
选项以仅列出TCP端口。
$ netstat -l -t

列出监听的UDP端口(List Listening UDP Ports)
We have also have the ability to only list UDP ports. We will use -u
option in order to only list UDP ports.
我们还具有仅列出UDP端口的功能。 我们将使用-u
选项以仅列出UDP端口。
$ netstat -l -u

列出已建立的连接(List Established Connections)
We can also list only established connections by removing -l
option which is used in previous examples. -l
was used to list only listening ports.
我们也可以通过删除前面示例中使用的-l
选项来仅列出已建立的连接。 -l
用于仅列出侦听端口。
$ netstat

筛选端口列表(Filter The Port List)
Now the most funny part. If we are running netstat in a busy server or system we will get a lot of output. In this situations we should filter printed list. We will use grep
command where detailed information can be get from following tutorial.
现在最有趣的部分。 如果我们在繁忙的服务器或系统中运行netstat,我们将获得很多输出。 在这种情况下,我们应该过滤打印清单。 我们将使用grep
命令,可从以下教程中获取详细信息。
Introduction to Linux Grep Command With Examples
筛选SSH端口(Filter SSH Port)
$ netstat -l | grep ssh
过滤HTTP端口 (Filter HTTP Port)
$ netstat -l | grep http
筛选器RDP端口 (Filter RDP Port)
$ netstat -l | grep rdp
筛选Telnet端口 (Filter Telnet Port)
$ netstat -l | grep telnet
在单个命令中过滤多个端口 (Filter Multiple Ports In Single Command)
If we need to filter multiple ports in a single command we should use grep
or logic. In this example we will filter both ssh
and telnet
ports in single command.
如果需要在单个命令中过滤多个端口,则应使用grep
或逻辑。 在此示例中,我们将在单个命令中同时过滤ssh
和telnet
端口。
$ netstat -l | grep "ssh|telnet"

翻译自: https://www.poftut.com/how-to-check-and-list-listening-ports-with-netstat-in-linux/