やっぱり Sun がスキ! : Weblog やっぱり Sun がスキ!

やっぱり Sun がスキ!

http://blogs.sun.com/yappri/date/20080828 2008年 8月 28日 木曜日

route -p による静的経路の設定

今回は、Solaris における静的経路設定(static routing)方法について書いてみたいと思います。

長年、Solaris で static route を設定する方法としては、/etc/rc2.d などに、route コマンド
を書いた rc script を配置し、起動時に実行させる方法で設定していました。
いまでもこの方法は、有効な方法となっています。

しかし、Solaris 10 から、新しい設定方法が提供されているという事実がありました・・・

/lib/svc/method/net-routing-setup ファイルに、/etc/inet/static_routes なるファイルを読み込むエントリがあります。
これは、どうみてみも static route を設定するファイルにしか見えないですね。
しかし、/etc/inet/static_routes というファイルについての情報を、マニュアルなどから見つけ出すことができません。
いろいろと調べてみると、正体は、/usr/sbin/route コマンドの -p オプションで作成されるファイルであることがわかりました。



$ strings /usr/sbin/route | grep static
/etc/inet/static_routes
/etc/inet/static_routes.tmp

OpenSolaris の source も参考になります。
http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/cmd/cmd-inet/usr.sbin/route.c#perm_file_sfx


オンラインマニュアルでは、下記のように記載されています。


man route からの引用:

-p

Make changes to the network route tables persistent
across system restarts. The operation is applied to the
network routing tables first and, if successful, is then
applied to the list of saved routes used at system
startup. In determining whether an operation was suc-
cessful, a failure to add a route that already exists or
to delete a route that is not in the routing table is
ignored. Particular care should be taken when using host
or network names in persistent routes, as network-based
name resolution services are not available at the time
routes are added at startup.


なるほど。-p オプションは、perpsistent routes を設定する為のオプションだということがわかります。
また、static route に限定されたものではなく、永続的(persistent)に利用したい経路設定情報を格納できますね。

そして、早速、実行してみました。
ここでは、host 192.168.11.180 へ到達するために、192.168.11.177 を経由するように
route コマンドを実行してみました。



# route -p add host 192.168.11.180 192.168.11.177
add host 192.168.11.180: gateway 192.168.11.177
add persistent host 192.168.11.180: gateway 192.168.11.177

見慣れない、add persistent host なるものが出力されていますね。
そして、netstat -nr で参照できる routing table にエントリーが追加されると共に
/etc/inet ディレクトリをみてみると static_routes ファイルが作成されていました。
内容は、このようになっていました。



# cat /etc/inet/static_routes
# File generated by route(1M) - do not edit.
host 218.44.192.180 218.44.192.177

どうみても、route コマンドに渡すオプションそのままです。
route -p により、/etc/inet/static_route が作成され、次回起動時からは、/lib/svc/method/net-routing-setup
によりこのファイルが読み取られ、routing table に追加されます。

ちなみに、設定された経路情報を削除をするには、下記のように実行します。



# route -p delete host 192.168.11.180 192.168.11.177
delete host 192.168.11.180: gateway 192.168.11.177
delete persistent host 192.168.11.180: gateway 192.168.11.177

これで、/etc/inet/static_routes と routing table から指定されたエントリが削除されます。

ただし、/etc/inet/static_routes は、route コマンドが管理するファイルとなるため、基本は手動で編集してはいけないファイルとなります。(ファイルの中にも、File generated by route(1M) - do not edit.とコメントに書かれていますね。)

また、もう少し、調べてみると下記のパッチにて追加されていることがわかりました。



118833-36 (sparc)
118855-36 (x86)

だいぶ昔に追加されていたのですね・・・