ゲートウェイを設定しても外に出られない
はじめに
ホームネットワークをいじくり回していたらインターネットに出られなくなった.
MacBookのOSXでの話だがIPの勉強になったので記述する.
事象
Linuxの無線LANブリッジ経由で無線接続したMacBookが別セグメントと通信を行えない.
条件は下記の通り
- ゲートウェイ自体へのpingは行える
- デフォルトゲートウェイもGUIで設定している
件のブリッジに関する設定は後述(の予定)
原因
netstat -nr
でルーティングテーブルを確認したところ, 下記のエントリを確認.
outing tables Internet: Destination Gateway Flags Refs Use Netif Expire default 192.168.0.254 UGScI 3 3 en0 以下省略
ゲートウェイ(192.168.0.254) へのエントリは存在する.
ここで注目すべきは Flags の UGScI
という記述である.
ここで man netstat
の Flags で設定され得る値の一覧を引用抜粋する.
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
フラグより,対象のルートは下記の属性を持っていることが分かる.
さて, 今回の問題の諸悪の根源は I フラグで有効になっている IF_SCOPE
というものである.
この IF_SCOPE
フラグは route
コマンドでルートを追加する際に -ifscope インターフェイス名
のオプションを指定すると入る.
なぜこのオプションが入ってしまったのかは不明(ブリッジを再起動して試行したが再現に至らず).
解決策
pingを飛ばしたいだけならインターフェイスをバインドして送るか, 送信元IPアドレスを指定して送れば良い.
> ping -b en0 8.8.8.8 > ping -S 192.168.0.1 8.8.8.8
ただ, この状態では他アプリケーションが利用できないのでゲートウェイを新しく追加しなおす方が良い.
> sudo route delete default 192.168.0.254 > sudo route add default 192.168.0.254
この後の挙動が不思議なもので, netstat -nr
を watch
で定期的に見てみた結果を以下に示す.
なお, 別プロセスで外部セグメントにpingを送り続けている.
> netstat -nr Routing tables Internet: Destination Gateway Flags Refs Use Netif Expire default 192.168.202.254 UGSc 1 0 en0 default 192.168.202.254 UGScI 79 769 en0 -------------------------------------------------------------------------------- Routing tables Internet: Destination Gateway Flags Refs Use Netif Expire default 192.168.202.254 UGSc 1 0 en0 default 192.168.202.254 UGScI 79 1783 en0
追加した IF_SCOPE
が有効でない通常のゲートウェイを使わずに,
既存の問題だったルートを用いているのである.
この状態で追加したばかりのゲートウェイを削除すると, pingはピタっと通らなくなってしまう.
参考文献
https://superuser.com/questions/441075/what-traffic-uses-an-interface-bound-route-rtf-ifscope-flag