mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
translated
This commit is contained in:
parent
e0615fa11c
commit
2090f9d9dd
@ -1,24 +1,21 @@
|
||||
translating---geekpi
|
||||
|
||||
|
||||
Examining network connections on Linux systems
|
||||
检查 Linux 系统上的网络连接
|
||||
============================================================
|
||||
|
||||
### Linux systems provide a lot of useful commands for reviewing network configuration and connections. Here's a look at a few, including ifquery, ifup, ifdown and ifconfig.
|
||||
### Linux 系统提供了许多有用的命令来检查网络配置和连接。下面来看几个,包括 ifquery、ifup、ifdown 和 ifconfig。
|
||||
|
||||
|
||||
There are a lot of commands available on Linux for looking at network settings and connections. In today's post, we're going to run through some very handy commands and see how they work.
|
||||
Linux 上有许多可用于查看网络设置和连接的命令。在今天的文章中,我们将会通过一些非常方便的命令来看看它们是如何工作的。
|
||||
|
||||
### ifquery command
|
||||
### ifquery 命令
|
||||
|
||||
One very useful command is the **ifquery** command. This command should give you a quick list of network interfaces. However, you might only see something like this —showing only the loopback interface:
|
||||
一个非常有用的命令是 **ifquery**。这个命令应该会显示一个网络接口列表。但是,你可能只会看到类似这样的内容 - 仅显示回环接口:
|
||||
|
||||
```
|
||||
$ ifquery --list
|
||||
lo
|
||||
```
|
||||
|
||||
If this is the case, your **/etc/network/interfaces** file doesn't include information on network interfaces except for the loopback interface. You can add lines like the last two in the example below — assuming DHCP is used to assign addresses — if you'd like it to be more useful.
|
||||
如果是这种情况,那么你的 **/etc/network/interfaces** 不包括除了回环接口之外的网络接口信息。在下面的例子中,假设你使用 DHCP 来分配地址,且如果你希望它更有用的话,你可以添加例子最后的两行。
|
||||
|
||||
```
|
||||
# interfaces(5) file used by ifup(8) and ifdown(8)
|
||||
@ -28,15 +25,16 @@ auto eth0
|
||||
iface eth0 inet dhcp
|
||||
```
|
||||
|
||||
### ifup and ifdown commands
|
||||
### ifup 和 ifdown 命令
|
||||
|
||||
可以使用相关的 **ifup** 和 **ifdown** 命令来打开网络连接并根据需要将其关闭,只要该文件具有所需的描述性数据即可。请记住,“if” 在这里意思是“接口” (interface),这与 **ifconfig** 命令中的一样,而不是“如果我只有一个大脑” (if I only had a brain) 中的 “if”。
|
||||
|
||||
The related **ifup** and **ifdown** commands can be used to bring network connections up and shut them down as needed provided this file has the required descriptive data. Just keep in mind that "if" means "interface" in these commands just as it does in the **ifconfig** command, not "if" as in "if I only had a brain".
|
||||
|
||||
<aside class="nativo-promo smartphone" id="" style="overflow: hidden; margin-bottom: 16px; max-width: 620px;"></aside>
|
||||
|
||||
### ifconfig command
|
||||
### ifconfig 命令
|
||||
|
||||
The **ifconfig** command, on the other hand, doesn't read the /etc/network/interfaces file at all and still provides quite a bit of useful information on network interfaces -- configuration data along with packet counts that tell you how busy each interface has been. The ifconfig command can also be used to shut down and restart network interfaces (e.g., ifconfig eth0 down).
|
||||
另外,**ifconfig** 命令完全不读取 /etc/network/interfaces,但是在网络接口上仍然提供了相当多的有用信息 - 配置数据以及数据包计数可以告诉你每个接口有多忙。ifconfig 命令也可用于关闭和重新启动网络接口(例如:ifconfig eth0 down)。
|
||||
|
||||
```
|
||||
$ ifconfig eth0
|
||||
@ -51,13 +49,13 @@ eth0 Link encap:Ethernet HWaddr 00:1e:4f:c8:43:fc
|
||||
Interrupt:21 Memory:fe9e0000-fea00000
|
||||
```
|
||||
|
||||
The RX and TX packet counts in this output are extremely low. In addition, no errors or packet collisions have been reported. The **uptime** command will likely confirm that this system has only recently been rebooted.
|
||||
输出中的 RX 和 TX 数据包计数很低。此外,没有报告错误或数据包冲突。**uptime** 命令可能会确认此系统最近才重新启动。
|
||||
|
||||
The broadcast (Bcast) and network mask (Mask) addresses shown above indicate that the system is operating on a Class C equivalent network (the default) so local addresses will range from 192.168.0.1 to 192.168.0.254.
|
||||
上面显示的广播 (Bcast) 和网络掩码 (Mask) 地址表明系统运行在 C 类等效网络(默认)上,所以本地地址范围从 192.168.0.1 到 192.168.0.254。
|
||||
|
||||
### netstat command
|
||||
### netstat 命令
|
||||
|
||||
The **netstat** command provides information on routing and network connections. The **netstat -rn** command displays the system's routing table.
|
||||
**netstat** 命令提供有关路由和网络连接的信息。**netstat -rn** 命令显示系统的路由表。
|
||||
|
||||
<aside class="nativo-promo tablet desktop" id="" style="overflow: hidden; margin-bottom: 16px; max-width: 620px;"></aside>
|
||||
|
||||
@ -70,7 +68,7 @@ Destination Gateway Genmask Flags MSS Window irtt Iface
|
||||
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
|
||||
```
|
||||
|
||||
That **169.254.0.0** entry in the above output is only necessary if you are using or planning to use link-local communications. You can comment out the related lines in the **/etc/network/if-up.d/avahi-autoipd** file like this if this is not the case:
|
||||
上面输出中的 **169.254.0.0** 条目仅在你正在使用或计划使用本地链路通信时才有必要。如果不是这样的话,你可以在 **/etc/network/if-up.d/avahi-autoipd** 中注释掉相关的行:
|
||||
|
||||
```
|
||||
$ tail -12 /etc/network/if-up.d/avahi-autoipd
|
||||
@ -87,9 +85,9 @@ $ tail -12 /etc/network/if-up.d/avahi-autoipd
|
||||
#fi
|
||||
```
|
||||
|
||||
### netstat -a command
|
||||
### netstat -a 命令
|
||||
|
||||
The **netstat -a** command will display **_all_** network connections. To limit this to listening and established connections (generally much more useful), use the **netstat -at** command instead.
|
||||
**netstat -a** 命令将显示 **_所有_** 网络连接。为了将其限制为正在监听和已建立的连接(通常更有用),请改用 **netstat -at** 命令。
|
||||
|
||||
```
|
||||
$ netstat -at
|
||||
@ -105,9 +103,9 @@ tcp6 0 0 ip6-localhost:ipp [::]:* LISTEN
|
||||
tcp6 0 0 ip6-localhost:smtp [::]:* LISTEN
|
||||
```
|
||||
|
||||
### netstat -rn command
|
||||
### netstat -rn 命令
|
||||
|
||||
The **netstat -rn** command displays the system's routing table. The 192.168.0.1 address is the local gateway (Flags=UG).
|
||||
**netstat -rn** 展示系统的路由表。192.168.0.1 是本地网关 (Flags=UG)。
|
||||
|
||||
```
|
||||
$ netstat -rn
|
||||
@ -117,9 +115,9 @@ Destination Gateway Genmask Flags MSS Window irtt Iface
|
||||
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
|
||||
```
|
||||
|
||||
### host command
|
||||
### host 命令
|
||||
|
||||
The **host** command works a lot like **nslookup** by looking up the remote system's IP address, but also provides the system's mail handler.
|
||||
**host** 命令就像 **nslookup** 一样,用来查询远程系统的 IP 地址,但是还提供系统的邮箱处理地址。
|
||||
|
||||
```
|
||||
$ host world.std.com
|
||||
@ -127,9 +125,9 @@ world.std.com has address 192.74.137.5
|
||||
world.std.com mail is handled by 10 smtp.theworld.com.
|
||||
```
|
||||
|
||||
### nslookup command
|
||||
### nslookup 命令
|
||||
|
||||
The **nslookup** also provides information on the system (in this case, the local system) that is providing DNS lookup services.
|
||||
**nslookup** 还提供系统中(本例中是本地系统)提供 DNS 查询服务的信息。
|
||||
|
||||
```
|
||||
$ nslookup world.std.com
|
||||
@ -141,9 +139,9 @@ Name: world.std.com
|
||||
Address: 192.74.137.5
|
||||
```
|
||||
|
||||
### dig command
|
||||
### dig 命令
|
||||
|
||||
The **dig** command provides quitea lot of information on connecting to a remote system -- including the name server we are communicating with and how long the query takes to respond and is often used for troubleshooting.
|
||||
**dig** 命令提供了很多有关连接到远程系统的信息 - 包括与我们通信的名称服务器以及查询需要多长时间进行响应,并经常用于故障排除。
|
||||
|
||||
```
|
||||
$ dig world.std.com
|
||||
@ -168,9 +166,9 @@ world.std.com. 78146 IN A 192.74.137.5
|
||||
;; MSG SIZE rcvd: 58
|
||||
```
|
||||
|
||||
### nmap command
|
||||
### nmap 命令
|
||||
|
||||
The **nmap** command is most frequently used to probe remote systems, but can also be used to report on the services being offered by the local system. In the output below, we can see that ssh is available for logins, that smtp is servicing email, that a web site is active, and that an ipp print service is running.
|
||||
**nmap** 经常用于探查远程系统,但是同样也用于报告本地系统提供的服务。在下面的输出中,我们可以看到登录可以使用 ssh、smtp 用于电子邮箱、web 站点也是启用的,并且 ipp 打印服务正在运行。
|
||||
|
||||
```
|
||||
$ nmap localhost
|
||||
@ -188,14 +186,14 @@ PORT STATE SERVICE
|
||||
Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds
|
||||
```
|
||||
|
||||
Linux systems provide a lot of useful commands for reviewing their network configuration and connections. If you run out of commands to explore, keep in mind that **apropos network** might point you toward even more.
|
||||
Linux 系统提供了很多有用的命令用于查看网络配置和连接。如果你都探索完了,请记住 **apropos network** 或许会让你了解更多。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3230519/linux/examining-network-connections-on-linux-systems.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user