AR ホームベーカリー

オイラのアウトプット用ホームベーカリー!

netstat のルーティング出力が macOS 11.3 以前で違うっぽい

VPN 接続がうまくいかない、という話で OpenVPN 側のプロセス追ったりしていた際に気づきました。

ちなみにその VPN 接続がうまくいかない件は、macOS を再起動したら治ったそうです。 Windows と比べてあまり再起動必要ないと言われますが、何かあったらマー再起動なりが安牌ですね。

ルーティング情報の出力

macOS 環境では netstat -rn で表示することができます。

macOS 11.3

user@localhost ~ $ netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags        Netif Expire
default            192.168.0.1        UGScg          en0

# snip #

(たぶん) macOS 11.3 以前

user@localhost ~ $ netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.0.1        UGSc            0        0     en0 

# snip #

Flags 出力が違う

UGSc はともかくとして、 UGScg とは? って感じですね。 ググっても G が代わりに表示されるので謎。 というわけでこういう時は man netstat ですね、確認してみましょう。

user@localhost ~ $ man netstat

# snip #

     1       RTF_PROTO1       Protocol specific routing flag #1
     2       RTF_PROTO2       Protocol specific routing flag #2
     3       RTF_PROTO3       Protocol specific routing flag #3
     B       RTF_BLACKHOLE    Just discard packets (during updates)
     b       RTF_BROADCAST    The route represents a broadcast address
     C       RTF_CLONING      Generate new routes on use
     c       RTF_PRCLONING    Protocol-specified generate new routes on use
     D       RTF_DYNAMIC      Created dynamically (by redirect)
     G       RTF_GATEWAY      Destination requires forwarding by intermediary
     H       RTF_HOST         Host entry (net otherwise)
     I       RTF_IFSCOPE      Route is associated with an interface scope
     i       RTF_IFREF        Route is holding a reference to the interface
     L       RTF_LLINFO       Valid protocol to link address translation
     M       RTF_MODIFIED     Modified dynamically (by redirect)
     m       RTF_MULTICAST    The route represents a multicast address
     R       RTF_REJECT       Host or net unreachable
     r       RTF_ROUTER       Host is a default router
     S       RTF_STATIC       Manually added
     U       RTF_UP           Route usable
     W       RTF_WASCLONED    Route was generated as a result of cloning
     X       RTF_XRESOLVE     External daemon translates proto to link address
     Y       RTF_PROXY        Proxying; cloned routes will not be scoped
     g       RTF_GLOBAL       Route to a destination of the global internet (policy hint)

# snip #

こちらですね。

g RTF_GLOBAL Route to a destination of the global internet (policy hint)

へぇーっ、グローバルに出てる経路を明示してくれてるのか? こんなフラグあったっけ。

しらべるマン

github.com

and I noticed there is a bunch of new routing flags that are being actively used starting with macOS 11.3

(ワイ訳:macOS 11.3 では、新しいルーティングフラグが積極的に利用されている)

とのことなので、新規に追加されたフラグのようです。 たしかに意味がわかると、この g フラグは便利ですね。

参考

qiita.com www.ibm.com