linux/unix 中的十大基本网络命令
网络是 Unix 的重要组成部分,它提供了许多工具和命令来诊断任何网络问题。 我们经常需要查看会话是否已连接。 由于很多协议使用套接字,我们可以使用 Linux 中可用的 netstat、telnet 和其他网络命令来查找问题并解决问题。 在本文中,我将向大家展示 Unix 中的基本网络命令以及它们的用途。 结合使用 grep 和 find 命令,我们可以解决大多数网络问题。
Unix 和 Linux 中的网络命令示例
这些是在 Linux 服务器上工作时我们经常用到的命令,这使我们能够快速解决连接问题,例如 无论另一个系统是否连接,另一个主机是否响应,以及在为高级交易系统进行连接时,此工具可节省大量时间
- 查找主机/域名和 IP 地址 - hostname
- 测试网络连接——ping
- 获取网络配置——ifconfig
- 网络连接、路由表、接口统计——netstat
- 查询 DNS 查找名称 – nslookup
- 与另一个主机名通信——telnet
- 数据包到达网络主机所采取的外出步骤——traceroute
- 查看用户信息——手指
- 检查目标主机的状态 - telnet
10 个 Unix 中的网络命令示例
让我们看看 Unix 和 Linux 中各种网络命令的一些示例。 其中一些是非常基本的,例如 ping 和 telnet,有些功能更强大,例如 nslookup 和 netstat。 当我们将这些命令结合使用 grep 和 find 时,我们可以获得任何我们正在寻找的东西,例如 主机名、连接端点、连接状态等。
1. hostname
没有选项的 hostname 显示机器的主机名
hostname –d
显示机器所属的域名
hostname –f
显示完全限定的主机名和域名
hostname –i
显示当前机器的IP地址
2. ping
它将信息包发送到用户定义的源。 如果接收到数据包,目标设备将发回数据包。 Ping 有两个用途
- 确保可以建立网络连接。
- 关于连接速度的时间信息。
如果我们执行 ping www.onmpw.com
,它将显示其 IP 地址。 使用 ctrl+C 停止测试。
3. ifconfig
查看网络配置,它显示当前网络适配器配置。 确定我们是否收到传输 (TX) 或接收 (RX) 错误很方便。
4. netstat
对于查找与主机的连接最有用且用途广泛。 我们可以通过使用 netstat -g
找出该主机订阅的所有多播组(网络)
-
netstat -nap | grep port
将显示正在使用该端口的应用程序的进程 ID -
netstat -a
或netstat –all
将显示所有连接,包括 TCP 和 UDP -
netstat --tcp
或netstat –t
将只显示 TCP 连接 -
netstat --udp
或netstat –u
将只显示 UDP 连接 -
netstat -g
将显示该主机订阅的所有多播网络。
5. nslookup
如果我们知道 IP 地址,它将显示主机名。 要查找给定域名的所有 IP 地址,可使用命令 nslookup
。 我们必须连接到互联网才能使用此实用程序,例如
$ nslookup onmpw.com
我们还可以使用 nslookup
将主机名转换为 IP 地址,以及从主机名转换为 IP 地址。
6. traceroute
traceroute
是一个方便的实用程序,用于查看到达远程系统或网站的跃点数和响应时间。 同样,我们需要互联网连接才能使用此工具。
7. finger
查看用户信息,显示用户的登录名、真实姓名、终端名称、写入状态。 这是非常古老的 Unix 命令,现在很少使用。
8. telnet
通过 telnet
协议连接目标主机,如果在任何端口上建立 telnet 连接意味着两台主机之间的连接工作正常。
$ telnet hostname port
将使用指定的端口 telnet 主机名。 通常用于查看主机是否存活以及网络连接是否正常。
相关文章
Installing MySQL Client in Linux
发布时间:2025/04/22 浏览次数:187 分类:MySQL
-
MySQL is an abbreviation for Structured Query Language which is a relational database management system. It is an open source database which is freely available and used for both large and small applications. The use cases are in school app
Network Interfaces in Linux
发布时间:2025/04/20 浏览次数:131 分类:OPERATING SYSTEM
-
/etc/network/interfaces This article will look at the complete syntax explanation in Debian and its derivatives . The file /etc/network/interfaces allows you to assign static and dynamic IP addresses to interfaces, configure routing informa
Wheels in Linux
发布时间:2025/04/20 浏览次数:99 分类:OPERATING SYSTEM
-
In this article, we will understand wheel groups the meaning of in Linux. On some Unix systems, wheel group a special user group that controls su access to commands and allows a user to clone another user, the superuser. Basic goals of the
Searching for files recursively in Linux
发布时间:2025/04/20 浏览次数:148 分类:OPERATING SYSTEM
-
In this Linux article, we will learn how to find files recursively in Linux. We will also see how to search files recursively in subdirectories in Linux systems. We will use different Linux commands in many ways. We will learn them one by o
Linux iptables: Incoming and Outgoing Rules Examples (SSH and HTTP)
发布时间:2025/04/20 浏览次数:121 分类:OPERATING SYSTEM
-
In our previous article in the iptables firewall series, we reviewed how to iptables -A add firewall rules using . We also explained how to allow incoming SSH connections. At a high level, it involves the following 3 steps. Delete all exist
Restart PostgreSQL in Ubuntu 18.04
发布时间:2025/04/09 浏览次数:72 分类:PostgreSQL
-
This short article shows how to restart PostgreSQL in Ubuntu. Restart PostgreSQL Server in Ubuntu You can restart Postgres server in Ubuntu using the following command. Order: sudo service postgres restart Sometimes the above command does n
Issues to note when installing Apache on Linux
发布时间:2025/04/08 浏览次数:78 分类:OPERATING SYSTEM
-
As the most commonly used web server, Apache can be used in most computer operating systems. As a free and open source Unix-like operating system, Linux and Apache are a golden pair. This article will introduce the installation and use of A
How to decompress x.tar.xz format files under Linux
发布时间:2025/04/08 浏览次数:186 分类:OPERATING SYSTEM
-
A lot of software found today is in the tar.xz format, which is a lossless data compression file format that uses the LZMA compression algorithm. Like gzip and bzip2, it supports multiple file compression, but the convention is not to compr
Summary of vim common commands
发布时间:2025/04/08 浏览次数:116 分类:OPERATING SYSTEM
-
In Linux, the best editor should be vim. However, the complex commands behind vim's powerful functions also make us daunted. Of course, these commands do not need to be memorized by rote. As long as you practice using vim more, you can reme