dhcpdでMac OSXにスタティックルートを渡す

ども。こんばんは。

dhcpdでMacにスタティックルート(Static Route、静的ルート)を渡す話です。

普通にroute addをrc.ほにゃららに書いてもいいのですが、
それだと外に持って行った時にやられそうなので。

家にいる時だけ、DHCP経由でもらうというやり方を検討。
※試してはいないですが、Windowsでもできそうですね。Androidはどうかな?

DHCPのオプション121もしくは249を使います。

どちらがいいか?と言うのはよくわかりませんが、
何故かPaloAltoのサイトによさ気な情報が。

How to push static routes from the Palo Alto Networks DHCP Server

以下引用。

The Palo Alto Networks firewall introduced DHCP Options in PAN-OS 7.0

RFC 2132 defines DHCP Option 33: Static Route Option
RFC 3442 defines DHCP Option 121: Classless Static Route Option for DHCPv4
Microsoft introduced DHCP Option 249: Microsoft Classless Static Route Option

DHCP Option 33 vs DHCP Option 121 vs DHCP Option 249

DHCP option 33 is a simplistic option to define a /32 destination to a next hop router.
In DHCP Option 121 or 249, the length and the data format for both options are the same.
The main difference is that Windows XP and Windows Server 2003 will only work with DHCP Option 249.

Compatibility

All other versions of Windows (except XP and Server 2003) use both DHCP Option 121 and Option 249. If both are configured, Windows will prefer routes defined by DHCP Option 121.

Linux will accept routes learned through DHCP Option 121 and Option 249. if it doesn not, set option classless_static_routes in /etc/dhcpcd.conf. If both options are configured, Linux will prefer routes defined by DHCP Option 121.

Since the release of Mac OSX 10.11 (El Capitan), DHCP Option 121 is supported. Option 249 is ignored in Mac OSX.

んー。

Mac OSXは249は無視しますよ。と。まぁとりあえず121かな。

んで、dhcpd.confですがこんな書きます。
うーむ。赤字のところはHEXで書かないと行けない。
さほど難しい話でも無いが面倒。

option new-static-routes code 249 = string;
option new-static-routes 1a:c0:a8:14:40:c0:a8:0a:3e;

いいの見っけた!

HexRoute
A bash script to convert human readable static routes to the format required in dhcpd.conf for Windows® clients.

Bashで書かれているのでダウンロードして実行。

こんなかんじで。

bash-3.2$ ./hexroute 192.168.128.0/24 192.168.123.254
18:c0:a8:80:c0:a8:7b:fe

さてdhcpd.confを。

このへんを参考に

option mac-static-routes code 121 = string;
option mac-static-routes18:c0:a8:80:c0:a8:7b:fe;

こんな感じで。

おっと、エラーが・・・。どうやらこの設定はHost毎のスコープらしい。

んん?やっぱりうまくいかないと思ったら、まず、Subnetより前にCode121の定義が必要で、
それの具体的な値をHostの中で記述するらしい。
このへんからのこのへんを参照。配列になってるけどStringでもいいっぽいね。

最終的にこんな感じに

ddns-update-style interim;
ignore client-updates;

#追加、参考サイトだとArrayにしてるけどHEXで渡すならStringにしないとダメっぽい。そりゃそうか。
option rfc3442-classless-static-routes code 121 = string;

subnet 192.168.123.0 netmask 255.255.255.0 {

(後略、前略)

        host mba {

                hardware ethernet xx:xx:xx:xx:xx:xx;
                fixed-address 192.168.123.xxx;
                option routers  192.168.123.xxx;

# static route add@tomo 2016081
                option rfc3442-classless-static-routes 18:c0:a8:80:c0:a8:7b:fe;

        }

(後略)

}

さて、Wi-Fiを切入してみて・・・

(;゚∀゚)=3ムッハー

bash-3.2$ netstat -nr |grep 128

192.168.128        192.168.123.254    UGSc            1        0     en0

 きたきた。いい感じ。

再起動してもOK。こりゃ便利。

まだまだ知らないことがたくさんありますね。

でhでは。またの機会に。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください