Linux 网络命令

The ip and ifconfig commands are similar. They list and configure current network interfaces on the device. ifconfig is the older of the two and may not be present on all machines.

使用 ip a 将列出无线硬连线/以太网连接,而 ifconfig 将仅列出以太网。另一个可用于列出无线连接的命令是 iwconfig

ARP(地址解析协议)

地址解析协议是第 3 层(/networking/OSI/network-layer.md) 协议,可帮助主机将 IP 地址解析为关联设备的 MAC 地址。

arp -aip nn 代表 neighbor)命令可在 Linux 中使用来列出与网络中本地 IP 地址关联的 MAC 地址。

您还可以使用带有 -r 标志的 netdiscover 来执行实时 ARP 数据包捕获:

1
2
3
4
5
6
sudo netdiscover -r 10.0.2.11
Currently scanning: Finished! | Screen View: Unique Hosts
3 Captured ARP Req/Rep packets, from 3 hosts. Total size: 180 __________________________________________________________________________
IP At MAC Address Count Len MAC Vendor / Hostname
--------------------------------------------------------------------------
10.0.2.2 52:54:00:12:35:02 1 60 Unknown vendor 10.0.2.3 52:54:00:12:35:03 1 60 Unknown vendor 10.0.2.4 52:54:00:12:35:04 1 60 Unknown vendor

Routing Tables

When you’re on a network, it’s good to know the routing tables. The routing tables of a network can tell you about the topology of the network.

For example, if you’re IP Address is a /24, you expect 256 possible addresses in that subnet. Checking the routing table, you may find additional addresses, outside your subnet meaning you may be able to access those other networks.

Both of the following commands will show you the routing table of the network you’re on:

  • route 命令
  • ip r 命令
  • netstat -rn 命令

Networks can also be added to a routing table allowing you to gain access to it.

ICMP (Internet Control Message Protocol)

A layer 3 protocol used between IP addressable devices to check the status of a host/ device.

在 Linux 或 Windows 计算机上使用 ping 命令 将告诉您该设备是否已连接并能够响应。在 Windows 上,ping 只会向目标发送一定数量的数据包,而在 Linux 上 ping 将连续发送数据包,除非您使用 SIGINT 或告诉命令要发送多少数据包。

Use the -c <number> flag to tell ping how many requests to send:

1
2
3
ping -c 1 69.69.69.69
PING 69.69.69.69 (69.69.69.69) 56(84) bytes of data.
64 bytes from 69.69.69.69: icmp_seq=1 ttl=64 time=0.016 ms

ping 还将为您提供从目标获取响应所需的时间(以毫秒为单位),以及在目标响应中接收到的字节数。

[!我以前的笔记(在文本中链接)]