如何在Linux中使用Netstat检查和列出侦听端口

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

带有示例Linux Netstat命令

列出所有监听端口(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
List All Listening Ports
List All Listening Ports
列出所有监听端口

列出监听的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
List Listening TCP Ports
List Listening TCP Ports
列出监听的TCP端口

列出监听的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 Listening UDP Ports
List Listening UDP Ports
列出监听的UDP端口

列出已建立的连接(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
List Established Connections
List Established Connections
列出已建立的连接

筛选端口列表(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

Linux Grep命令简介和示例

筛选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或逻辑。 在此示例中,我们将在单个命令中同时过滤sshtelnet端口。

$ netstat -l | grep "ssh|telnet"
Filter Multiple Ports In Single Command
Filter Multiple Ports In Single Command
在单个命令中过滤多个端口
LEARN MORE  Linux wc Command Word and Line Count Tutorial With Examples
了解更多Linux wc命令字和行数教程及示例

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值