@wxy
https://linux.cn/article-15013-1.html
This commit is contained in:
Xingyu Wang 2022-09-09 15:41:14 +08:00
parent 32fe59ad9b
commit 578c0666a4
2 changed files with 596 additions and 595 deletions

View File

@ -0,0 +1,596 @@
[#]: subject: "21 Basic Linux Networking Commands You Should Know"
[#]: via: "https://itsfoss.com/basic-linux-networking-commands/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lkxed"
[#]: translator: "wxy"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-15013-1.html"
你应该知道的 22 个基本的 Linux 网络命令
======
![](https://img.linux.net.cn/data/attachment/album/202209/09/151623qbizibbrzfrffrpc.jpg)
我们并不是每天都会谈论 Linux 的命令行。但正如一些读者指出的那样,你们也想学习一些命令行的技巧。
因此,我整理了一份基本的 Linux 网络命令清单,这些命令在我的大学时代帮助了我,让我对如何在网络方面使用 Linux 有了坚定的认识。
这些命令将帮助你设置网络,以及解决你在 Linux 系统中可能遇到的各种网络问题。
### Linux 中的基本网络命令
这个汇编包括了 CLI 实用程序,它们将帮助你排除网络问题、监控数据包和连接的设备,以及更多。
在我展示这些命令的一些细节之前,让我分享一下我今天要讨论的所有命令的简要概述。
| 命令 | 说明 |
| :- | :- |
| `ip` | 操纵路由来分配和配置网络参数 |
| `traceroute` | 识别数据包到达主机的路径 |
| `tracepath` | 在追踪网络主机的路径时,获取最大传输单元 |
| `ping` | 通常用于检查主机和服务器之间的连接情况 |
| `ss` | 获得有关网络套接字的详细信息 |
| `dig` | 给出所有关于 DNS 名称服务器的必要信息 |
| `host` | 输出特定域和主机的 IP 地址 |
| `hostname` | 主要用于输出和更改主机名 |
| `curl` | 在网络上通过各种协议传输数据 |
| `mtr` | `ping``traceroute` 的组合,用于诊断网络 |
| `whois` | 获取有关注册的域名、IP 地址、名称服务器等信息 |
| `ifplugstatus` | 检测本地以太网设备的链接状态 |
| `iftop` | 监视与带宽有关的统计信息 |
| `tcpdump` | 数据包嗅探和分析工具,用于捕获、分析和过滤网络流量 |
| `ethtool` | 允许用户配置以太网设备 |
| `nmcli` | 用于网络连接的故障排除工具 |
| `nmap` | 主要用于审计网络安全 |
| `bmon` | 开源工具,用于监控实时带宽 |
| `firewalld` | 配置防火墙规则的 CLI 工具 |
| `iperf` | 测量网络性能和调整的工具 |
| `speedtest-cli` | speedtest.net 的 CLI 工具,用于检查网速 |
| `vnstat` | 主要用于监控网络流量和带宽消耗 |
现在,让我们用例子和更深入的方式讨论它们。
请注意,并不是所有的命令都会预装。我已经添加了针对 Debian/Ubuntu 的说明。对于其他发行版,请使用你的软件包管理器进行安装。
#### 1、ip 命令
`ip` 命令是最基本的,但也是最重要的,你会发现系统管理员经常使用它,其用于从操纵路由到分配和配置网络参数。
虽然用例可能无穷无尽,但让我向你展示 `ip` 命令的最基本用例(寻找 IP 地址)。
```
ip address
```
![ip address][1]
同样,你也可以使用 `ip` 命令来持续监控设备的状态,请使用 `monitor` 参数而不是我们之前用来获取 IP 地址的 `address` 参数:
```
ip monitor
```
![ip monitor][2]
#### 2、traceroute
使用 `traceroute` 命令,你可以确定数据包到达主机的路线。而且,当你想询问数据包的传输情况和数据包所走的跳数时,它可能相当有用。
默认情况下,你的系统可能没有安装 `traceroute`,如果你使用的是 Debian 及派生的发行版(包括 Ubuntu安装时只需使用一个命令
```
sudo apt install traceroute
```
例如,追踪到 google.com 的数据包:
```
traceroute google.com
```
![traceroute google.com][3]
默认情况下,`traceroute` 会使用 IPv4但是你可以通过使用 `-6` 选项来改变这一行为,该选项将指示 `traceroute` 使用 IPv6。让我告诉你怎么做
![traceroute -6 google.com][4]
#### 3、tracepath
`tracepath` 命令用于发现 MTU最大传输单元同时追踪到网络主机的路径。它与我上面讨论的 `traceroute` 很相似,但它不需要 `sudo` 权限,而且也没有像它那么多功能。
但是,首先什么是 MTU
MTU 就是可以在网络上传输或接收的最大帧或数据包。
现在,让我们看一下 google.com 的 `tracepath` 的基本例子:
```
tracepath google.com
```
![tracepath google.com][5]
同样,你可以使用 `-b` 选项同时打印出 IP 地址和主机名。
```
tracepath -b google.com
```
![tracepath -b google.com][6]
#### 4、ping
[ping 命令][7]<ruby>数据包网络飞龙探云手<rt>Packet Internet Groper</rt></ruby> 🤣) 可以说是在排除网络故障时最重要的命令之一,因为它是检查主机和服务器之间连接情况的最常用方法。
例如,我 `ping` 谷歌:
```
ping google.com
```
![ping google.com][8]
这里,最后一行(`min/avg/max`)表示从指定的服务器获得响应的时间。
如果你得到一个错误提示 `bash: ping: command not found` LCTT 译注:不会吧?),你可以查看我们的指南 [如何在 Ubuntu 上安装 Ping][9]。
#### 5、ss
`ss`<ruby>套接字统计<rt>socket statistics</rt></ruby>)命令用于详细了解网络套接字(在网络上发送和接收数据的端点)。
要列出所有监听和非监听的 TCP 连接,你必须使用 `-at` 选项,如下所示:
```
ss -at
```
![ss -at][10]
同样,你可以使用 `-au` 选项对 UDP 端口进行同样的操作:
```
ss -au
```
![ss -au][11]
#### 6、dig
[dig 命令][12]<ruby>域信息龙爪手<rt>Domain Information Groper</rt></ruby> 😜)用于获取有关域名的所有必要信息。
要在基于 Ubuntu 的发行版上安装 `dig` 工具,请按照给出的命令进行:
```
sudo apt install dnsutils
```
现在,让我告诉你如何获取一个特定主机的信息,在这个例子中,我将获取 itsfoss.com 的信息:
```
dig itsfoss.com
```
![dig itsfoss.com][13]
#### 7、host
`host` 命令主要用于获取一个特定主机的 IP 地址,或者你可以从一个特定的 IP 地址获取主机名。换句话说,它是一个 DNS 查询工具。
要找到主机的 IP你只需要在 `host` 命令中附加主机名。让我告诉你怎么做:
```
host itsfoss.com
```
![host itsfoss.com][14]
同样,你可以用一个 IP 地址来获取主机名:
```
host 8.8.4.4
```
![host 8.8.4.4][15]
#### 8、hostname
如果你已经使用了一段时间的 Linux你一定很熟悉这个命令因为这主要是用来 [改变你的系统的主机名][16] 和 NIS网络信息系统的主机名。
当不使用任何选项时,它可以得到系统当前的主机名。
```
hostname
```
![hostname][17]
从包含所需主机名的文件中改变主机名是这个工具的另一个有趣的功能:
```
sudo hostname -F <filename>
```
![sudo hostname -F][18]
#### 9、curl
`curl`<ruby>客户端 URL<rt>Client URL</rt></ruby>)命令主要用于在网络上传输数据,支持各种协议,包括 HTTP、FTP、IMAP 和许多其他协议。
这个工具是首选的自动化工具,因为它是在没有任何人类互动的情况下工作的,也可以用于端点测试、调试和错误记录。
`curl` 工具没有预装,如果你在任何 Debian 及其派生发行版上,你只需要使用以下命令进行安装:
```
sudo apt install curl
```
使用 `curl` 命令 [下载文件][19] 非常容易,你只需在 URL 中使用 `-O` 选项,就可以开始了。
```
curl -O [URL]
```
![curl -o url][20]
在下载大文件时,进度条会很方便,你可以用 `curl``-#` 选项来显示进度条。
![curl -# -O][21]
#### 10、mtr
它是 `ping``traceroute` 工具的组合,主要用于网络诊断,并提供网络响应和连接的实时情况。
使用 `mtr` 的最简单方法是用它跟上一个主机名或 IP 地址,它将给出一个实时的 `traceroute` 报告。
```
mtr [URL/IP]
```
![mtr google.com][22]
如果你想让 `mtr` 同时显示主机名和 IP 地址,你可以把它和 `-b` 选项配对,如下图:
```
mtr -b [URL]
```
![mtr -b][23]
#### 11、whois
`whois` 可以帮助你找到有关注册的域名、IP 地址、名称服务器等信息,因为它是 whois 目录服务的客户端。
这个工具可能没有预装在你的设备上,要在基于 Debian/Ubuntu 的发行版上安装,你可以使用给出的命令:
```
sudo apt install whois
```
一般来说,`whois` 命令是与给出的域名配对使用的:
```
whois [DomainName]
```
![whois google.com][24]
另外,你也可以用一个 IP 地址来代替域名,你会得到同样的细节。
#### 12、ifplugstatus
`ifplugstatus` 是一个最基本的,但也是最有用的工具,足以在基本水平上排除连接问题。它用于检测本地以太网的链接状态,其工作方式与 `mii-diag`、`mii-tool` 和 `ethtool` 类似,支持所有三个 API。
在基于 Debian/Ubuntu 的发行版上安装,你可以按照给出的命令进行:
```
sudo apt install ifplugd
```
这个工具没有任何花哨的选项,经常不需要与任何配对选项而使用:
```
ifplugstatus
```
![ifplugstatus][25]
#### 13、iftop
`iftop`<ruby>接口的 top<rt>Interface TOP</rt></ruby>)经常被管理员用来监控与带宽有关的统计数据,当你遇到网络问题时,也可以作为诊断工具使用。
这个工具需要手动安装,可以通过给出的命令在运行 Debian/Ubuntu 的机器上轻松安装。
```
sudo apt install iftop
```
`iftop` 在没有任何选项的情况下使用时,它会显示默认接口的带宽统计。
```
sudo iftop
```
![iftop][26]
你也可以通过在设备名称后面加上 `-i` 选项来指定网络设备。
```
sudo iftop -i <DeviceName>.
```
在我的例子中,是 `enp1s0`,所以我的输出将是如下:
![sudo iftop -i enp1s0][27]
#### 14、tcpdump
`tcpdump` 是一个数据包嗅探和分析工具,用于捕获、分析和过滤网络流量。它也可以作为一个安全工具使用,因为它将捕获的数据保存在可以 [通过 Wireshark 访问][28] 的 pcap 文件中。
像许多其他工具一样,`tcpdump` 没有预装如果你是在Debian/Ubuntu 上,你可以按照下面的命令进行安装:
```
sudo apt install tcpdump
```
一旦你完成了安装,你可以获得当前接口的捕获数据包,如下所示:
```
sudo tcpdump
```
![sudo tcpdump][29]
那么如何将捕获的数据包保存在 pcap 文件中呢?让我告诉你怎么做:
```
sudo tcpdump -w Captured_Packets.cap -i < networkdevice >
```
![sudo tcpdump -w][30]
要访问保存的文件,你需要使用 `-r` 选项加上文件名。
```
sudo tcpdump -r Captured_Packets.pcap
```
![sudo tcpdump -r filename][31]
#### 15、ethtool
顾名思义,`ethtool` 工具主要涉及管理以太网设备。使用这个工具,你可以调整网卡速度、自动协商特性等。
但它可能没有预装在你的机器上,可以通过利用给出的命令安装在 Debian/Ubuntu 机器上:
```
sudo apt install ethtool
```
要获取接口的详细信息,你只需在命令后面加上设备名称,如下所示:
```
sudo ethtool <InterfaceName>
```
![sudo ethtool enp1s0][32]
#### 16、nmcli
作为一个简单而强大的网络故障排除工具,它是任何系统管理员在排除网络故障时首先使用的工具之一,也可以在脚本中使用。
你可以使用 `nmcli` 命令来监控设备的连接状态:
```
nmcli dev status
```
![nmcli dev status][33]
当不使用任何选项时,它将带来你系统中所有现有设备的信息:
```
nmcli
```
![nmcli][34]
#### 17、nmap
`nmap` 是一个探索和审计网络安全的工具。它经常被黑客和安全爱好者使用,因为它允许你获得网络的实时信息、连接到你的网络的 IP 的详细信息、端口扫描,以及更多。
要在基于 Debian/Ubuntu 的发行版上安装 `nmap` 工具,请使用给出的命令:
```
sudo apt install nmap
```
让我们开始扫描主机名:
```
nmap itsfoss.com
```
![nmap itsfoss.com][35]
#### 18、bmon
`bmon` 是一个开源的工具,用于监测实时带宽和调试问题,以更人性化的方式呈现统计数据。这个工具最好的部分是图形显示,甚至可以在 HTML 中得到你的输出!
安装非常简单,因为 `bmon` 存在于流行的 Linux 发行版的默认仓库中,这也包括 Debian/Ubuntu。
```
sudo apt install bmon
```
现在,你只需要启动 `bmon`,就可以用眼睛愉快地监控带宽了:
```
bmon
```
![bmon][36]
#### 19、firewalld
管理防火墙可以说是网络安全的核心部分,这个工具允许你添加、配置和删除防火墙的规则。
但是 firewalld 需要手动安装,如果你使用的是基于 Debian/Ubuntu 的发行版,你可以利用给出的命令进行安装:
```
sudo apt install firewalld
```
例如,我将向你展示,如何为公共区域永久地打开 80 端口:
```
sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
```
![sudo firewall-cmd --permanent --zone=public][37]
同样,要删除最近添加的规则,你必须使用 `-remove` 选项,如下所示:
```
sudo firewall-cmd --zone=public --remove-port=80/tcp
```
![sudo firewall-cmd --zone=public --remove][38]
#### 20、iperf
`iperf` 是一个用 C 语言编写的开源工具,允许用户进行网络性能测量和调整。
这个工具存在于 Debian/Ubuntu 的默认资源库中,可以通过给出的命令安装:
```
sudo apt install iperf
```
要开始监控网络,用户必须通过给出的命令在服务器上启动这个客户端:
```
iperf -s -u
```
其中,`-s` 选项表示服务器,`-u` 选项为 UDP 格式。
![iperf -s -u][39]
现在,你可以通过提供首选协议的 IP 地址有效载荷连接到你的服务器(使用 `-c` 选项表示客户端)。在这个例子中,我选择了 UDP使用 `-u` 选项),有效载荷为 100
```
iperf -c 10.0.2.15 -u 100
```
![iperf -c][40]
#### 21、speedtest-cli
顾名思义,这是 speedtest.net 网站的 CLI 工具。这个在 Apache 2.0 许可下发布的开源工具,当你想从 CLI 获得一个可靠的 [检查网速][41] 的来源时,会有很大帮助。
安装非常简单,如果你是在 Debian/Ubuntu 上,可以利用给出的命令轻松安装:
```
sudo apt install speedtest-cli
```
一旦你完成了安装部分,你只需要使用一行命令即可测试你的速度:
```
speedtest-cli
```
![speedtest-cli][42]
#### 22、vnstat
`vnstat` 工具主要被系统管理员用来监控网络流量和带宽消耗(大部分情况下),因为这个工具可以监控你系统的网络接口的流量。
和其他网络工具一样,你可以在默认的软件库中找到 `vnstat`,如果你在 Debian/Ubuntu 上,可以通过给出的命令进行安装:
```
sudo apt install vnstat
```
你可以使用 `vnstat` 命令,不需要任何选项,它将带来你系统所有可用接口的基本统计信息:
```
vnstat
```
![vnstat][43]
对于实时监控,你可以将 `vnstat` 命令与 `-l` 选项配对。
![vnstat -l][44]
### 一个长长的清单,对吗?
这个汇编连冰山一角都算不上,只是分享了每个命令的目的和基本例子,因为增加更多的命令会使这个清单变得更长。
流行的但 [已废弃的 Linux 命令][45],如 `ipconfig`,已被故意排除在这个列表之外。
如果你很好奇,你可以学习 [如何最大限度地利用手册页][46],这将教会你如何使用任何实用程序的最大潜力。
如果我忘了提到任何你喜欢的东西,请在评论中告诉我。
--------------------------------------------------------------------------------
via: https://itsfoss.com/basic-linux-networking-commands/
作者:[Sagar Sharma][a]
选题:[lkxed][b]
译者:[wxy](https://github.com/wxy)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lkxed
[1]: https://itsfoss.com/wp-content/uploads/2022/08/ip-address-1.png
[2]: https://itsfoss.com/wp-content/uploads/2022/08/ip-monitor.png
[3]: https://itsfoss.com/wp-content/uploads/2022/08/traceroute-google.com_.png
[4]: https://itsfoss.com/wp-content/uploads/2022/08/traceroute-6-google.com_.png
[5]: https://itsfoss.com/wp-content/uploads/2022/08/tracepath-google.com_.png
[6]: https://itsfoss.com/wp-content/uploads/2022/08/tracepath-b-google.com_.png
[7]: https://linuxhandbook.com/ping-command-ubuntu/
[8]: https://itsfoss.com/wp-content/uploads/2022/08/ping-google.com_.png
[9]: https://linuxhandbook.com/ping-command-ubuntu/
[10]: https://itsfoss.com/wp-content/uploads/2022/08/ss-at.png
[11]: https://itsfoss.com/wp-content/uploads/2022/08/ss-au.png
[12]: https://linuxhandbook.com/dig-command/
[13]: https://itsfoss.com/wp-content/uploads/2022/08/dig-itsfoss.com_.png
[14]: https://itsfoss.com/wp-content/uploads/2022/08/host-itsfoss.com_.png
[15]: https://itsfoss.com/wp-content/uploads/2022/08/host-8.8.4.4.png
[16]: https://itsfoss.com/change-hostname-ubuntu/
[17]: https://itsfoss.com/wp-content/uploads/2022/08/hostname.png
[18]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-hostname-f.png
[19]: https://linuxhandbook.com/curl-command-examples/
[20]: https://itsfoss.com/wp-content/uploads/2022/08/curl-o-url.png
[21]: https://itsfoss.com/wp-content/uploads/2022/08/curl-o.png
[22]: https://itsfoss.com/wp-content/uploads/2022/08/mtr-google.com_.png
[23]: https://itsfoss.com/wp-content/uploads/2022/08/mtr-b.png
[24]: https://itsfoss.com/wp-content/uploads/2022/08/whois-google.com_.png
[25]: https://itsfoss.com/wp-content/uploads/2022/08/ifplugstatus.png
[26]: https://itsfoss.com/wp-content/uploads/2022/08/iftop.png
[27]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-iftop-i-enp1s0.png
[28]: https://itsfoss.com/install-wireshark-ubuntu/
[29]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-tcpdump.png
[30]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-tcpdump-w-.png
[31]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-tcpdump-r-filename.png
[32]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-ethtool-enp1s0.png
[33]: https://itsfoss.com/wp-content/uploads/2022/08/nmcli-dev-status.png
[34]: https://itsfoss.com/wp-content/uploads/2022/08/nmcli.png
[35]: https://itsfoss.com/wp-content/uploads/2022/08/nmap-itsfoss.com_.png
[36]: https://itsfoss.com/wp-content/uploads/2022/08/bmon-800x591.png
[37]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-firewall-cmd-permanent-zonepublic.png
[38]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-firewall-cmd-zonepublic-remove.png
[39]: https://itsfoss.com/wp-content/uploads/2022/08/iperf-s-u.png
[40]: https://itsfoss.com/wp-content/uploads/2022/08/iperf-c-.png
[41]: https://itsfoss.com/network-speed-monitor-linux/
[42]: https://itsfoss.com/wp-content/uploads/2022/08/speedtest-cli.png
[43]: https://itsfoss.com/wp-content/uploads/2022/08/vnstat.png
[44]: https://itsfoss.com/wp-content/uploads/2022/08/vnstat-l.png
[45]: https://itsfoss.com/deprecated-linux-commands/
[46]: https://linuxhandbook.com/man-pages/

View File

@ -1,595 +0,0 @@
[#]: subject: "21 Basic Linux Networking Commands You Should Know"
[#]: via: "https://itsfoss.com/basic-linux-networking-commands/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
21 Basic Linux Networking Commands You Should Know
======
Its not every day at Its FOSS that we talk about the “command line side” of Linux. But as some of you readers pointed out in the internal survey (exclusive for Its FOSS newsletter subscribers), you would also like to learn some command line tricks.
So I compiled a list of essential Linux networking commands that helped me during my college days and gave me a firm overview of how you can use Linux on the networking side.
These commands will help you set-up as well as troubleshoot various networking issues you may encounter with your Linux system.
### Essential networking commands in Linux
This compilation includes CLI utilities that will help you with troubleshooting network issues, monitoring packets, connected devices, and much more.
Before I show the commands with some details, let me share a brief overview of all the commands which Im going to discuss today:
| Command | Description |
| :- | :- |
| ip | Manipulating routing to assigning and configuring network parameters |
| traceroute | Identify the route taken by packets to reach the host |
| tracepath | Gets maximum transmission unit while tracing the path to the network host |
| ping | Often used to check the connectivity between the host and the server |
| ss | Gets details about network sockets |
| dig | Gives all the necessary information about the DNS name server |
| host | Prints IP address of a specific domain and viscera |
| hostname | Mostly used to print and change the hostname |
| curl | Transfers data over the network by supporting various protocols |
| mtr | A combination of ping and traceroute is used to diagnose the network |
| whois | Gets info about registered domains, IP addresses, name servers, and more |
| ifplugstatus | Detects the link status of a local Ethernet device |
| iftop | Monitors stats related to bandwidth |
| tcpdump | Packet sniffing and analyzing utility used to capture, analyze and filter network traffic |
| ethtool | Allows users to configure Ethernet devices |
| nmcli | Troubleshooting utility for network connections |
| nmap | Primarily used to audit network security |
| bmon | An open-source utility to monitor real-time bandwidth |
| firewalld | CLI tool to configure rules of Firewall |
| iperf | Utility to measure network performance and tuning |
| speedtest-cli | CLI utility of speedtest.net to check internet speeds |
| vnstat | Mostly used to monitor network traffic and bandwidth consumption |
Now, lets discuss them with examples and more depth.
Please note that not all the commands here will come preinstalled. I have added instructions for Debian/Ubuntu. For other distributions, please use your package manager.
#### 1. IP command
IP (Internet Protocol) is one of the most basic yet essential enough that youd often find it being used by sysadmins, and its use cases can be ranging from manipulating routing to assigning and configuring network parameters.
While the use cases may be endless, let me show you the most basic use case of Ip command (finding an IP address):
```
ip address
```
![ip address][1]
Similarly, you can also use the Ip command to continuously monitor the state of devices by using `monitor` option instead of `address` that we used to get IP addresses previously.
```
ip monitor
```
![ip monitor][2]
#### 2. traceroute
Using the traceroute command, you can identify the route taken by packets to reach the host. And it can be quite useful when you want to interrogate the transmission of data packets and hops taken by packets.
By default, your system may not have traceroute installed and if youre on Debian-derivative (including Ubuntu), installation is single command ahead:
```
sudo apt install traceroute
```
For example, Id be tracerouting packets to google.com
```
traceroute google.com
```
![traceroute google.com][3]
By default, traceroute will utilize IPv4 but you can change this behavior by using `-6` option that will indicate traceroute to use IPv6. Let me show you how:
![traceroute 6 google.com][4]
#### 3. tracepath
The tracepath command is used to discover MTU (Maximum Transmission Unit) while tracing the path to the network host. Its quite similar to what I discussed above but it does require sudo privileges and also has no fact functions like traceroute.
But what is MTU in the first place?
MTU is nothing but the largest frame or packet that can be transmitted or received over the network.
Now, lets have a look at the basic example of tracepath with google.com
```
tracepath google.com
```
![tracepath google.com][5]
Similarly, you can print both IP address and hostname using `-b` option.
```
tracepath -b google.com
```
![tracepath b google.com][6]
#### 4. ping
[The ping (Packet Internet Groper) command][7] can be considered one of the most important commands while troubleshooting your network, as it is the most common way to check the connectivity between the host and the server.
For example, Id be pinging google:
```
ping google.com
```
![ping google.com][8]
Here, the last line (min/avg/max) indicates the time to get a response from the specified server.
And if youre getting an error saying **“bash: ping: command not found”**, you can check out our guide on [how to install Ping on Ubuntu][9].
#### 5. ss
The ss (socket statistics) command is used to detail about network socket (endpoint for sending and receiving data across the network).
To list all the listening and non-listening TCP connection, you have to use `-at` option as shown below:
```
ss -at
```
![ss at][10]
Similarly, you can do the same with UDP ports using `-au` option:
```
ss -au
```
![ss au][11]
#### 6. dig
The [dig (Domain Information Groper) command][12] is used to fetch all the necessary information about the DNS name server.
To install the dig utility on Ubuntu-based distros, follow the given command:
```
sudo apt install dnsutils
```
Now, let me show you how to get info from a specific DNS, and for this example, Id be using itsfoss.com as DNS.
```
dig itsfoss.com
```
![dig itsfoss.com][13]
#### 7. host
The host command is mainly used to get the IP address of a specific domain, or you can get the domain name from a specific IP address. In other words, its just a DNS lookup utility.
To find the IP of the domain, you just have to append the domain name with the host command. Let me show you how:
```
host itsfoss.com
```
![host itsfoss.com][14]
Similarly, you can use an IP address to fetch the domain name:
```
host 8.8.4.4
```
![host 8.8.4.4][15]
#### 8. hostname
You must be familiar with this command if youve been using Linux for a while, as this is mostly used to [change the hostname of your system][16] and NIS (Network Information System) domain name.
When used without any options, it gets the current hostname of the system:
```
hostname
```
![hostname][17]
Changing the hostname from a file containing the desired hostname is yet another interesting feature of this utility.
```
sudo hostname -F <filename>
```
![sudo hostname f][18]
#### 9. curl
The curl (Client URL) command is mostly used to transfer data over the network and supports various protocols including HTTP, FTP, IMAP, and many others.
This tool is preferred in automation as it is built to work without any human interaction and can also be used in endpoint testing, Debugging, and error logging.
The curl utility does not come pre-installed and if youre on any Debian-derivative, you just have to use the following command for installation:
```
sudo apt install curl
```
It is quite easy to download files [using the curl command][19], You just have to use `-O` option with the URL, and youd be good to go!
```
curl -O [URL]
```
![curl o url][20]
While downloading large files, the progress bar can be quite convenient, and you can do the same with curl using `-#` option.
![curl # o][21]
#### 10. mtr
It is a combination of ping and traceroute utilities and is mainly used for network diagnostics and gives live look at network response and connectivity.
The simplest way to use mtr is to append a domain name or IP address with it, and it will give a live traceroute report.
```
mtr [URL/IP]
```
![mtr google.com][22]
And if you want mtr to show both hostnames and IP addresses, you can pair it with `-b` option as shown below:
```
mtr -b [URL]
```
![mtr b][23]
#### 11. whois
The whois can help you find info about registered domains, IP addresses, name servers, and a lot more as it is the client for the whois directory service.
This utility may not be pre-installed on your device and for installation in Ubuntu-based distro, you can use the given command:
```
sudo apt install whois
```
Generally, the whois command is paired with the domain name as given:
```
whois [DomainName]
```
![whois google.com][24]
Alternatively, you can also use an IP address instead of a domain and youd get the same details.
#### 12. ifplugstatus
The ifplugstatus is one of the most basic yet useful enough to troubleshoot connectivity at the basic level. And is used to detect the link status of a local ethernet and works similarly to mii-diag, mii-tool, and ethtool by supporting APIs for all 3.
For installation on Ubuntu-based distros, you can follow the given command:
```
sudo apt install ifplugd
```
This utility does not have any fancy options and often used without being paired with any:
```
ifplugstatus
```
![ifplugstatus][25]
#### 13. iftop
The iftop (Interface TOP) is often used by admins to monitor stats related to bandwidth and can also be used as a diagnostic tool when youre having issues with the network.
This utility requires manual installation and can be easily installed on machines running Ubuntu by the given command:
```
sudo apt install iftop
```
When iftop is used without any options, it shows bandwidth stats of the default interface:
```
sudo iftop
```
![iftop][26]
And you can also specify the network device by appending the device name with `-i` option.
```
sudo iftop -i <DeviceName>
```
In my case its, `enp1s0` so my output will be as follows:
![sudo iftop i enp1s0][27]
#### 14. tcpdump
The tcpdump is a packet sniffing and analyzing utility used to capture, analyze and filter network traffic. It can also be used as a security tool because it saves captured data in pcap file which can be [accessed through Wireshark][28].
Like many other tools, tcpdump does not come pre-installed, and you can follow the given command for installation if youre on Ubuntu base.
```
sudo apt install tcpdump
```
Once youre done with the installation, you can get capture packets for the current interface as given below:
```
sudo tcpdump
```
![sudo tcpdump][29]
So how about saving captured packets in pcap file? Let me show you how:
```
sudo tcpdump -w Captured_Packets.pcap -i <networkdevice>
```
![sudo tcpdump w][30]
To access the saved file, you need to use `-r` option by appending file name:
```
sudo tcpdump -r Captured_Packets.pcap
```
![sudo tcpdump r filename][31]
#### 15. ethtool
As its name suggests, the ethtool utility is primarily concerned with managing ethernet devices. Using this utility allows you to tweak network card speed, auto-negotiation, and much more.
But it may not be pre-installed on your machine and can be installed on a Ubuntu-powered machine by utilizing the given command:
```
sudo apt install ethtool
```
To fetch the interface details, you just have to append the device name with the command as shown below:
```
sudo ethtool <InterfaceName>
```
![sudo ethtool enp1s0][32]
#### 16. nmcli
Being a simple yet powerful network troubleshooting tool, it is one of the first utilities that any sysadmin would use for troubleshooting the network and can also be used in scripts.
You can use nmcli command as given to monitor the connectivity status of devices:
```
nmcli dev status
```
![nmcli dev status][33]
When used without any options, it will bring info about all the present devices in your system.
```
nmcli
```
![nmcli][34]
#### 17. nmap
The nmap is a tool to explore and audit network security. It is often used by hackers and security enthusiasts as it allows you to get real-time info on the network, IPs connected to your network in a detailed manner, port scanning, and much more.
For installation of nmap utility on Ubuntu-based distros, utilize the given command:
```
sudo apt install nmap
```
Lets start scanning with hostname:
```
nmap itsfoss.com
```
![nmap itsfoss.com][35]
#### 18. bmon
The bmon is an open-source utility to monitor real-time bandwidth and debug issues by presenting stats in a more human-friendly way. The best part of this tool is the graphical presentation and can even get your output in HTML!
Installation is quite simple as bmon is present in default repos of popular Linux distros and that also includes Ubuntu.
```
sudo apt install bmon
```
Now, you just have to launch bmon and youd be able to monitor bandwidth in eye pleasant way:
```
bmon
```
![bmon][36]
#### 19. firewalld
Managing firewalls can be considered the core part of network security and this tool allows you to add, configure and remove rules on firewall.
But the firewalld requires manual installation, and you can utilize the given command for installation if youre using an Ubuntu-based distro:
```
sudo apt install firewalld
```
For example, Id show you, how you can open port 80 permanently for the public zone:
```
sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
```
![sudo firewall cmd permanent zone=public][37]
Similarly, to remove the recently added rule, you have to use `-remove` option as shown below:
```
sudo firewall-cmd --zone=public --remove-port=80/tcp
```
![sudo firewall cmd zone=public remove][38]
#### 20. iperf
The iperf is an open-source utility written in C allowing users to perform network performance measurement and tuning.
This tool is present in the default repository of Ubuntu and can be installed from the given command:
```
sudo apt install iperf
```
To start monitoring the network, users must initiate this client on the server by given command:
```
iperf -s -u
```
Where, `-s` option indicates server and `-u` option is for UDP format.
![iperf s u][39]
Now, you can connect to your server (using `-c` option indicating client side) by providing an IP address payload for the preferred protocol. For this example, I went with UDP (using `-u` option) with a payload of 100.
```
iperf -c 10.0.2.15 -u 100
```
![iperf c][40]
#### 21. speedtest-cli
As the name suggests, this is the CLI utility for the speedtest.net website. This open-source utility released under Apache 2.0 license can be quite helpful when you want a reliable source for [checking internet speeds][41] from cli.
Installation is quite straightforward and can easily be installed utilizing the given command if youre on an Ubuntu base:
```
sudo apt install speedtest-cli
```
Once youre done with the installation part, you just have to use a single command to get your speeds tested:
```
speedtest-cli
```
![speedtest cli][42]
#### 22. vnstat
The vnstat utility is mostly used by sysadmins to monitor network traffic and bandwidth consumption (for the most part) as this tool monitors traffic on network interfaces of your system.
As with any other networking tool, you can find vnstat in the default repositories, and if youre on Ubuntu, the installation can be done through the given command:
```
sudo apt install vnstat
```
You can use vnstat command without any options, and it will bring basic stats of all available interfaces of your system:
```
vnstat
```
![vnstat][43]
For live monitoring, you can pair vnstat command with `-l` option:
how to get the most out of man pages
![vnstat l][44]
### A long List, right?
This compilation is not even the tip of the iceberg and only shares the purpose and basic examples of each command because adding more would have made this even longer.
Popular but [deprecated Linux commands][45] like ipconfig have been deliberately left out of this list.
And if youre curious, you can learn [how to get the most out of man pages][46]which will teach you how you can use any utility at its max potential.
And if I forgot to mention any of your favorites, please let me know in the comments.
--------------------------------------------------------------------------------
via: https://itsfoss.com/basic-linux-networking-commands/
作者:[Sagar Sharma][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lkxed
[1]: https://itsfoss.com/wp-content/uploads/2022/08/ip-address-1.png
[2]: https://itsfoss.com/wp-content/uploads/2022/08/ip-monitor.png
[3]: https://itsfoss.com/wp-content/uploads/2022/08/traceroute-google.com_.png
[4]: https://itsfoss.com/wp-content/uploads/2022/08/traceroute-6-google.com_.png
[5]: https://itsfoss.com/wp-content/uploads/2022/08/tracepath-google.com_.png
[6]: https://itsfoss.com/wp-content/uploads/2022/08/tracepath-b-google.com_.png
[7]: https://linuxhandbook.com/ping-command-ubuntu/
[8]: https://itsfoss.com/wp-content/uploads/2022/08/ping-google.com_.png
[9]: https://linuxhandbook.com/ping-command-ubuntu/
[10]: https://itsfoss.com/wp-content/uploads/2022/08/ss-at.png
[11]: https://itsfoss.com/wp-content/uploads/2022/08/ss-au.png
[12]: https://linuxhandbook.com/dig-command/
[13]: https://itsfoss.com/wp-content/uploads/2022/08/dig-itsfoss.com_.png
[14]: https://itsfoss.com/wp-content/uploads/2022/08/host-itsfoss.com_.png
[15]: https://itsfoss.com/wp-content/uploads/2022/08/host-8.8.4.4.png
[16]: https://itsfoss.com/change-hostname-ubuntu/
[17]: https://itsfoss.com/wp-content/uploads/2022/08/hostname.png
[18]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-hostname-f.png
[19]: https://linuxhandbook.com/curl-command-examples/
[20]: https://itsfoss.com/wp-content/uploads/2022/08/curl-o-url.png
[21]: https://itsfoss.com/wp-content/uploads/2022/08/curl-o.png
[22]: https://itsfoss.com/wp-content/uploads/2022/08/mtr-google.com_.png
[23]: https://itsfoss.com/wp-content/uploads/2022/08/mtr-b.png
[24]: https://itsfoss.com/wp-content/uploads/2022/08/whois-google.com_.png
[25]: https://itsfoss.com/wp-content/uploads/2022/08/ifplugstatus.png
[26]: https://itsfoss.com/wp-content/uploads/2022/08/iftop.png
[27]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-iftop-i-enp1s0.png
[28]: https://itsfoss.com/install-wireshark-ubuntu/
[29]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-tcpdump.png
[30]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-tcpdump-w-.png
[31]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-tcpdump-r-filename.png
[32]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-ethtool-enp1s0.png
[33]: https://itsfoss.com/wp-content/uploads/2022/08/nmcli-dev-status.png
[34]: https://itsfoss.com/wp-content/uploads/2022/08/nmcli.png
[35]: https://itsfoss.com/wp-content/uploads/2022/08/nmap-itsfoss.com_.png
[36]: https://itsfoss.com/wp-content/uploads/2022/08/bmon-800x591.png
[37]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-firewall-cmd-permanent-zonepublic.png
[38]: https://itsfoss.com/wp-content/uploads/2022/08/sudo-firewall-cmd-zonepublic-remove.png
[39]: https://itsfoss.com/wp-content/uploads/2022/08/iperf-s-u.png
[40]: https://itsfoss.com/wp-content/uploads/2022/08/iperf-c-.png
[41]: https://itsfoss.com/network-speed-monitor-linux/
[42]: https://itsfoss.com/wp-content/uploads/2022/08/speedtest-cli.png
[43]: https://itsfoss.com/wp-content/uploads/2022/08/vnstat.png
[44]: https://itsfoss.com/wp-content/uploads/2022/08/vnstat-l.png
[45]: https://itsfoss.com/deprecated-linux-commands/
[46]: https://linuxhandbook.com/man-pages/