15、linux命令-
主要命令
-a 显示所有网络连接
-a | grep
-a | grep
-a | grep tcp | grep
-at # 仅显示tcp
-au # 仅显示udp
-l # 要显示所有监听套接字
-p # 获取程序及其进程ID
-n # 以数字方式获取与IP地址和端口有关的所有数据
-lnpt
-lnpu
-rn # 查看路由
-i # 列出网口信息
The term “” for . In ’s terms, the , , and a of other .
术语“ ”代表网络统计信息。 用外行术语来说,命令显示当前的网络连接,网络协议统计信息以及各种其他接口。
If we enter in the , any of , the a wide range of at us. It is the of the to while out the rest.
如果我们在终端中输入 ,而没有任何计算机联网的背景知识,则系统会向我们抛出各种各样的网络术语。 程序员有责任在清除其余信息的同时提取重要信息。
In this , we will some of the to using the .
在本文中,我们将使用命令回答一些与计算机网络相关的查询。
使用命令识别活动的网络连接 ( Using the )
To all the in Linux, we use
要显示Linux中所有活动的网络连接,我们使用
-a
:
输出:
All 1
全部1
The six :
标准输出包含六列:
State 状态
To this , we open a . On the :
为了更好地理解这一点,假设我们打开一个网站 。 运行命令时:
-a | grep
We will get the :
我们将得到以下输出:
using the
使用命令搜索
As it quite clear that, we all the in with a . In the , ‘|‘ is used to pass the of one sub- to , grep is a tool in Linux.
显然,我们使用特定的外部地址提取了所有正在进行的网络连接。 在命令中,' | '用于将一个子命令的输出传递给另一个子命令,而grep是Linux中的搜索工具。
Note: This be for all kinds of since not every has a the URL.
注意:由于并非每个网站都有与URL匹配的外部地址,因此该技术无法应用于所有类型的网站。
To with the data by the , we can write on , , or :
为了进一步试验命令提供的数据,我们可以编写针对协议,地址或状态的命令:
all
显示所有已建立的连接
-a | grep
all TCP in state
显示所有处于侦听状态的TCP连接
-a | grep tcp | grep
of , Linux some in-built for .
Linux提供了一些内置选项来获取特定信息,而不是创建自定义命令。
基于协议过滤 ( based on )
For TCP , -t is used. To only the TCP :
对于TCP特定查询,使用-t选项。 要仅显示TCP连接:
-at
Note: To apply in a , the are .注意:要在单个命令中应用多个过滤器,将附加这些选项。
For UDP , -u is used. To all the UDP :
对于UDP特定查询,使用 -u 选项。 要显示所有遵循UDP的套接字:
-au
基于状态的选项: (State-based :)
To all :
要显示所有监听套接字:
-l
使用使用网络连接识别程序 ( the using using )
To fetch the and their IDs, we use:
要获取程序及其进程ID,我们使用:
-p
For TCP :
对于TCP特定程序:
-pt
:
输出:
TCP
TCP之后的程序
As we can , is the with the id as 16648. This can be used to kill or stop any some the of the user.
我们可以注意到,正在使用进程ID为16648的进行访问。这些信息可用于杀死或阻止任何程序在不知情的情况下访问某个网络。
Note: It may that some might be if the user is not the root user. To a root user in Linux, the sudo su and the can help. For , refer to this.
注意:如果当前用户不是root用户,则可能会隐藏某些程序信息。 要成为Linux的root用户,可以使用sudo su命令并输入密码。 欲了解更多信息,请参阅此 。
使用命令列出每个网络连接的IP地址 (Using the to List IP of Each )
For all the data to IP and ports , we use:
为了以数字方式获取与IP地址和端口有关的所有数据sudo命令,我们使用:
-n
We can for TCP by:
我们可以通过以下方式以数字方式显示遵循TCP的程序的地址:
-ptn
:
输出:
TCP ()
TCP之后的程序(数字)
The is very vivid as we can see the IP as well as port for each .
区别非常明显,因为我们可以看到每个连接的IP地址和端口号。
每个协议的统计数据是什么? (What are the for each ?)
To the for each type of using the , we run:
要使用命令访问每种协议的摘要统计信息,我们运行:
-s
:
输出:
for each
每种协议的统计信息
使用命令显示路由表 (Using the to the Table)
Any on a needs to where to route the data . The table to make these . To the of the table in , we use the :
网络上的任何设备都需要决定将数据包路由到何处。 路由表包含做出这些决定的信息。 要获取数字形式的路由表的内容,我们使用以下命令选项:
-rn
:
输出:
of table
路由表内容
The table of the :
内核路由表由以下几列组成:
Note: The zero value means that the size is being used.注意:具有零值的列表示正在使用默认大小。
列出活动的网络接口 (List out the )
To any from the , there has to be some link the and the . That point of is by a . We run the :
要从访问任何信息,系统与网络之间必须存在某些链接。 互连点由网络接口提供。 我们运行命令:
-i
:
输出:
网络接口
The table of:
内核接口表包括:
The a wide range of which makes it , to sum up in just one . We can refer man pages in Linux by:
具有广泛的知识,仅凭一篇文章就无法总结。 我们总是可以通过以下方式引用Linux中的手册页:
man
and to learn more about we can ask help in by:
要了解有关选项的更多信息,我们可以通过以下方式在终端中寻求帮助:
-h
参考文献: (:)
翻译自:
资料来源如何在Linux中使用命令
提交参考资料sudo命令,PK现有内容
博客作者
拓展阅读
linux环境下使用命令查看网络信息Linux网络相关命令:,网络监控命令——中与ss命令之间的区别linux 端口监听 常用命令Linux中的命令详解