15、linux命令-netstat
ahcoder 2025-01-05 15:33 10 浏览
15、linux命令-netstat
主要命令
netstat -a 显示所有网络连接
netstat -a | grep baidu.com
netstat -a | grep ESTABLISHED
netstat -a | grep tcp | grep LISTEN
netstat -at # 仅显示tcp
netstat -au # 仅显示udp
netstat -l # 要显示所有监听套接字
netstat -p # 获取程序及其进程ID
netstat -n # 以数字方式获取与IP地址和端口有关的所有数据
netstat -lnpt
netstat -lnpu
netstat -rn # 查看路由
netstat -i # 列出网口信息
The term “netstat” stands for Network Statistics. In layman’s terms, netstat command displays the current network connections, networking protocol statistics, and a variety of other interfaces.
术语“ netstat”代表网络统计信息。 用外行术语来说,netstat命令显示当前的网络连接,网络协议统计信息以及各种其他接口。
If we enter netstat in the terminal, without any background knowledge of computer networking, the system throws a wide range of networking jargon at us. It is the responsibility of the programmer to extract important information while flushing out the rest.
如果我们在终端中输入netstat ,而没有任何计算机联网的背景知识,则系统会向我们抛出各种各样的网络术语。 程序员有责任在清除其余信息的同时提取重要信息。
In this article, we will answer some of the queries related to computer networking using the netstat command.
在本文中,我们将使用netstat命令回答一些与计算机网络相关的查询。
使用Netstat命令识别活动的网络连接 (Identify Active Network Connections Using the Netstat Command)
To display all the active network connections in Linux, we use
要显示Linux中所有活动的网络连接,我们使用
netstat -a
Output:
输出:
Netstat All 1
Netstat全部1
The standard output contains six columns:
标准输出包含六列:
- Proto (Protocol) 协议(Protocol)
- Recv-Q (Receiving Queue) Recv-Q(接收队列)
- Send-Q (Sending Queue) Send-Q(发送队列)
- Addresses
- Local Address
netstat
- Foreign Address 地址
- 本地地址
netstat
- 外部地址
- State 状态
To understand this better, suppose we open a website www.lookip.net. On running the command:
为了更好地理解这一点,假设我们打开一个网站www.lookip.net 。 运行命令时:
netstat -a | grep lookip.net
We will get the following output:
我们将得到以下输出:
Search lookip.net using the netstat command
使用netstat命令搜索lookip.net
As it quite clear that, we extracted all the network connections in progress with a particular foreign address. In the command, ‘|‘ is used to pass the output of one sub-command to another, whereas grep is a searching tool in Linux.
显然,我们使用特定的外部地址提取了所有正在进行的网络连接。 在命令中,' | '用于将一个子命令的输出传递给另一个子命令,而grep是Linux中的搜索工具。
Note: This technique cannot be applied for all kinds of websites since not every website has a foreign address matching the URL.
注意:由于并非每个网站都有与URL匹配的外部地址,因此该技术无法应用于所有类型的网站。
To further experiment with the data provided by the netstat command, we can write commands focusing on protocols, addresses, or states:
为了进一步试验netstat命令提供的数据,我们可以编写针对协议,地址或状态的命令:
Display all established connections
显示所有已建立的连接
netstat -a | grep ESTABLISHED
Display all TCP connections in listening state
显示所有处于侦听状态的TCP连接
netstat -a | grep tcp | grep LISTEN
Instead of creating custom commands, Linux provides some in-built options for fetching specific information.
Linux提供了一些内置选项来获取特定信息,而不是创建自定义命令。
基于协议过滤 (Filtering based on Protocols)
For TCP specific queries, -t option is used. To display only the TCP connections:
对于TCP特定查询,使用-t选项。 要仅显示TCP连接:
netstat -at
Note: To apply multiple filters in a single netstat command, the options are appended.注意:要在单个netstat命令中应用多个过滤器,将附加这些选项。
For UDP specific queries, -u option is used. To display all the sockets following UDP :
对于UDP特定查询,使用 -u 选项。 要显示所有遵循UDP的套接字:
netstat -au
基于状态的选项: (State-based option:)
To display all listening sockets:
要显示所有监听套接字:
netstat -l
使用Netstat使用网络连接识别程序 (Identify the programs using network connections using Netstat)
To fetch the programs and their process IDs, we use:
要获取程序及其进程ID,我们使用:
netstat -p
For TCP specific programs:
对于TCP特定程序:
netstat -pt
Output :
输出:
Programs following TCP
TCP之后的程序
As we can notice, Chrome is accessing the internet with the process id as 16648. This information can be used to kill or stop any program accessing some network without the knowledge of the user.
我们可以注意到,Chrome正在使用进程ID为16648的Internet进行访问。这些信息可用于杀死或阻止任何程序在不知情的情况下访问某个网络。
Note: It may happen that some program information might be hidden if the current user is not the root user. To become a root user in Linux, the command sudo su and entering the password can help. For further information, refer to this.
注意:如果当前用户不是root用户,则可能会隐藏某些程序信息。 要成为Linux的root用户,可以使用sudo su命令并输入密码。 欲了解更多信息,请参阅此 。
使用Netstat命令列出每个网络连接的IP地址 (Using the Netstat Command to List IP Addresses of Each Network Connection)
For fetching all the data related to IP addresses and ports numerically, we use:
为了以数字方式获取与IP地址和端口有关的所有数据,我们使用:
netstat -n
We can display addresses numerically for programs following TCP by:
我们可以通过以下方式以数字方式显示遵循TCP的程序的地址:
netstat -ptn
Output:
输出:
Programs following TCP (numeric)
TCP之后的程序(数字)
The difference is very vivid as we can see the IP addresses as well as port numbers for each connection.
区别非常明显,因为我们可以看到每个连接的IP地址和端口号。
每个协议的统计数据是什么? (What are the statistics for each protocol?)
To access the summary statistics for each type of protocol using the netstat command, we run:
要使用netstat命令访问每种协议的摘要统计信息,我们运行:
netstat -s
Output:
输出:
Statistics for each protocol
每种协议的统计信息
使用Netstat命令显示路由表 (Using the Netstat Command to Display the Routing Table)
Any device on a network needs to decide where to route the data packets. The routing table contains information to make these decisions. To acquire the contents of the routing table in numerics, we use the following command option:
网络上的任何设备都需要决定将数据包路由到何处。 路由表包含做出这些决定的信息。 要获取数字形式的路由表的内容,我们使用以下命令选项:
netstat -rn
Output:
输出:
Contents of routing table
路由表内容
The kernel routing table consists of the following columns:
内核路由表由以下几列组成:
- Destination 目标
- Gateway 网关
- Genmask Genmask
- Flags 标志
- MSS MSS
- Window 窗口
- irtt (Initial Round Trip Time) irtt (初始往返时间)
- Iface (Interface) Iface (接口)
Note: The columns having zero value means that the default size is being used.注意:具有零值的列表示正在使用默认大小。
列出活动的网络接口 (List out the active network interfaces)
To access any information from the internet, there has to be some link between the system and the network. That point of interconnection is provided by a network interface. We run the command:
要从Internet访问任何信息,系统与网络之间必须存在某些链接。 互连点由网络接口?提供。 我们运行命令:
netstat -i
Output:
输出:
Network interfaces
网络接口
The kernel interface table comprises of:
内核接口表包括:
- Iface (Interface) Iface(接口)
- MTU MTU
- RX RX
- TX TX
- OK OK
- ERR ERR
- DRP DRP
- OVR OVR
- Flg Flg
The command netstat features a wide range of knowledge which makes it impossible, to sum up in just one article. We can always refer man pages in Linux by:
netstat具有广泛的知识,仅凭一篇文章就无法总结。 我们总是可以通过以下方式引用Linux中的手册页:
man netstat
and to learn more about netstat options we can ask help in terminal by:
要了解有关netstat选项的更多信息,我们可以通过以下方式在终端中寻求帮助:
netstat -h
参考文献: (References:)
- Linux – netstat man pageLinux – netstat手册页
翻译自: https://www.journaldev.com/41196/netstat-command-in-linux
资料来源如何在Linux中使用netstat命令
提交参考资料,PK现有内容
博客作者cunchi4221
拓展阅读
linux环境下使用netstat命令查看网络信息Linux网络相关命令:netstat,ssLinux网络监控命令——netstatLinux中netstat与ss命令之间的区别linux 端口监听 Netstat 常用命令Linux中的netstat命令详解
相关推荐
- ARM64内核内存布局图(ARM64内核内存布局图解)
-
ARM64架构处理器采用48位物理寻址机制,最大可以寻找到256TB的物理地址空间。对于目前的应用来说已经足够了,不需要扩展到64位的物理地址寻址。虚拟地址也同样最大支持48位支持,所以在处理器的架构...
- ARM64 linux 调试串口通信(ARM64 linux 调试串口通信实验报告)
-
ARM64linux调试串口通信随着国产机普及很多工作也转移到了新平台上,以前调试设备用的笔记本电脑也换成新国产ARM64架构的了。本文以绿联CM204USB-A转RJ45Console调试线...
- Gentoo Linux 终止对 Itanium IA-64 体系的支持
-
GentooLinux是最后几个继续维护Itanium(IA-64)架构构建的Linux发行版之一,但现在这些已停产的英特尔处理器正在逐步淘汰。由于Linux6.7内核放弃了对Itan...
- 如何检查 Linux 系统是 32 位还是 64 位?这9个命令查的又快又准!
-
在Linux系统中,位数(bit)通常指的是CPU架构的位宽,即CPU一次能够处理的数据量。32位系统和64位系统在内存寻址能力、计算性能和软件支持上存在显著差异:「32位系统」:...
- 调出好画面!带你玩转飞凌嵌入式AM62x开发板的显示接口
-
来源:飞凌嵌入式官网“显示”是嵌入式开发板最为重要的功能之一,能够支持更多种类、更高规格的显示接口,意味着它能够应对的使用场景也更加广泛。每一款嵌入式开发板在出厂前都会做屏幕调试,但在客户的实际项目开...
- 带你玩转AM62x开发板的显示接口——LVDS的显示和修改方式
-
此前小编已为大家介绍过OK6254-C开发板的RGB显示和修改方式,今天将继续为大家介绍OK6254-C开发板的LVDS显示和修改方式。话不多说,我们进入正题。1、LVDS接口规格飞凌嵌入式OK62...
- AM335x继任者?AM6254性能解析(am2361p)
-
飞凌嵌入式FET6254-C核心板基于TISitaraTMAM62x系列工业级处理器设计开发,采用ARMCortex-A53架构,主频最高可达1.4GHz;并集成了丰富的接口,可广泛应用于的工...
- 如何在 Linux 发行版中安装微信和 QQ?
-
很多人因为工作沟通的原因需要用到微信和QQ,那么如何在Linux发行版中安装微信和QQ呢?以下是一些尝试的解决方法。QQ上一个版本的QQLinux版还是在2009年,而在现在,基于N...
- MySQL:物理备份工具XBK(mysql 备份方案)
-
XBK的优缺点:XBK(PerconaXtraBackup)优点:1.免费2.热备:备份期间不阻塞innodb和XtraDB表,但会阻塞Myisam表3.物理备份:备份恢复快XBK缺点:1.不支持远...
- AMD锐龙9 9950X CPU AIDA64跑分曝光:比7950X最高快45%
-
IT之家6月26日消息,Anandtech论坛网友igor_kavinski本周一发布帖子,分享了AMD旗舰锐龙99950X处理器的AIDA64基准测试跑分,与当前基于Z...
- qemu linux内核(5.10.209)开发环境搭建
-
版本信息宿主机:ubuntu20.04.6LTS(FocalFossa)虚拟机:ubuntu20.04.6LTS(FocalFossa)安装宿主机的步骤省略,和一般的在vmware中安...
- iPhone 7成刷机神器,成功运行乌班图、Linux、安卓
-
在智能机刚开始流行的时候,很多手机发烧友都喜欢刷机,当时民间大神们制作了特别多优化的ROM。后来随着手机硬件的逐步提升,以及厂商们对系统的大力优化,让大家对于刷机的兴趣也越来越少。不知道大家还记得这部...
- 12 款最佳免费开源 Linux 渲染器 | 火狐浏览器 130.0 版本更新
-
12款最佳免费开源Linux渲染器Linux的一大优势在于其拥有丰富的开源软件,可以满足艺术家、摄影师、动画师和设计师的需求。凭借价格低廉的硬件、免费的软件以及少量的才能和灵感,任何人都可以创...
- Linux中xargs 命令详解与实用场景
-
xargs是Linux系统中常用的命令行工具之一,它能够从标准输入构造参数列表并传递给其他命令使用,是处理批量数据操作时的重要利器。一、xargs的基本语法xargs[OPTION]...[C...
- Linux 磁盘扩容(非LVM)方式(linux扩容lvm磁盘容量)
-
今天接到一个客户的需求,CentOS的/分区容量太小了,OA系统所有的数据都在这下面,由于当时前同事给客户安装系统时采用了标准分区,而不是LVM逻辑卷,所以不支持在线扩容。df-hT查看磁盘使...
- 一周热门
- 最近发表
-
- ARM64内核内存布局图(ARM64内核内存布局图解)
- ARM64 linux 调试串口通信(ARM64 linux 调试串口通信实验报告)
- Gentoo Linux 终止对 Itanium IA-64 体系的支持
- 如何检查 Linux 系统是 32 位还是 64 位?这9个命令查的又快又准!
- 调出好画面!带你玩转飞凌嵌入式AM62x开发板的显示接口
- 带你玩转AM62x开发板的显示接口——LVDS的显示和修改方式
- AM335x继任者?AM6254性能解析(am2361p)
- 如何在 Linux 发行版中安装微信和 QQ?
- MySQL:物理备份工具XBK(mysql 备份方案)
- AMD锐龙9 9950X CPU AIDA64跑分曝光:比7950X最高快45%
- 标签列表
-
- linux 远程 (37)
- u盘 linux (32)
- linux 登录 (34)
- linux 路径 (33)
- linux 文件命令 (35)
- linux 是什么 (35)
- linux 界面 (34)
- 查看文件 linux (35)
- linux 语言 (33)
- linux代码 (32)
- linux 查看命令 (33)
- 关闭linux (34)
- root linux (33)
- 删除文件 linux (35)
- linux 主机 (34)
- linux与 (33)
- linux 函数 (35)
- linux .ssh (35)
- cpu linux (35)
- 查看linux 系统 (32)
- linux 防火墙 (33)
- linux 手机 (32)
- linux 镜像 (34)
- linux mac (32)
- linux ip地址 (34)