如何查看mac的路由表和网关等信息

最近在研究headscale的多局域网互通,但是因为设备和网络知识不过关,所以还没完全走通,不过对于mac设备的路由和linux的路由这些知识稍微多了一点
在mac上可以通过

1
netstat -nr

查看路由表
命令参数的解析是

1
2
3
4
5
 -n    Show network addresses as numbers (normally netstat interprets addresses and attempts to display them symbolically).  This option may be used with any
of the display formats.
-r Show the routing tables. Use with -a to show protocol-cloned routes. When -s is also present, show routing statistics instead. When -l is also
present, netstat assumes more columns are there and the maximum transmission unit. More detailed information about the route metrics are displayed with
-ll for TCP round trip times -lll for all metrics. Use the -z flags to display only entries with non-zero RTT values. (“mtu”) are also displayed.

比如我的路由表里

1
2
3
4
5
Routing tables

Internet:
Destination Gateway Flags Netif Expire
default 192.168.xx.1 UGScg en0

这个表示是默认路由,走的网关转发,
这里的Gateway就是网关地址,一般是我们的路由器地址
Flags的意思是
U表示Up,表示路由是可用的,
G表示是Gateway,表示通过网关转发
S表示是Static,是静态路由,非动态生成,
c表示是Cloned,由父路由自动克隆生成
g表示是Global,全局的
比较全的

1
2
3
4
5
6
7
8
U = Up
G = Gateway
S = Static, e.g., default route added at boot time
H = Host-specific
C = Generate new (host-specific) routes on use
L = Valid link-layer (MAC) address
c = Cloned route
R = Reject route, known but unreachable route

表示我们的请求都是经过这个网关转发的,通过它把数据往外网或者局域网内其他设备发
至于这个Netif表示 network interface
就是网络接口也可以理解为网卡
比如我这里的en0,一般指物理网卡(通常是 Wi-Fi)
另外还可以通过

1
route get default

查看默认路由设置
可以这么理解网络连接过程

1
2
3
4
5
6
7
8
9
应用程序

路由表

netif(网络接口)

物理网卡 / 虚拟隧道

网络

原来的设置就是比如我可以在网关设备配置好tailscale节点,
然后让局域网内的设备都通过这个网关设备连接tailscale的网络,
对于非自建headscale应该就是subnet互联这样的逻辑
但是对于headscale中,可能因为我的网关设备是n1刷的openwrt,
对应的tailscale版本比较新,一直出现比较奇怪的问题
比如获取不到ipv4的地址,
启动tailscale就直接把本地局域网的地址全都走tailscale0虚拟网卡路由了
导致ipv4地址直接都不通了,
还得找下原因,可能是tailscale的客户端版本太高了,
一开始连接不上headscale的http地址,
高版本必须得用https才行,
结果就是用caddy套了一层https的壳
能连接上了又发现ipv4地址没了
而且还会出现一些很奇怪的问题
比如会出现局域网内的wifi也断连
是否是出现了局域网内的二层广播风暴或者arp冲突
应该是二层环路问题比较大
这一块还有待后续的研究