LoginSignup
11
11

More than 5 years have passed since last update.

ifconfig -a に要注意

Last updated at Posted at 2015-01-28

普段Linuxを使っている方は、ネットワーク設定を確認するときにifconfig -aを躊躇なく(時にはrootで!)実行しているのではないでしょうか。

ifconfig -aの持つ意味

SunOS/Solarisではifconfig -aは若干違う意味を持つので注意が必要です。

-a

Apply the command to all interfaces of the specified address family. If no address family is supplied, either on the command line or by means of /etc/default/inet_type, then all address families will be selected.

Oracle社のマニュアルより

上記にあるように、commandをすべてのinterfaceにapplyするということだけを意味しています。interfaceのステータスを表示する、ということに限定はしていません。

つまり、例えば以下のようなcommandを入力した場合、

ifconfig -a down

そのホストのすべてのinterfaceがダウンすることになってしまいます。-aの後ろにcommandを追加した途端に、危険なcommandへと変貌してしまうのです。

やってしまいそうなミス

また、SunOS/SolarisではIPv4アドレスが設定されているinterfaceのステータスを確認する際に以下のようなcommandを実行しますが、

ifconfig -a4

これを間違って、

ifconfig -a 4

と入力してしまうと、すべてのinterfaceのアドレスが、0.0.0.4というIPv4アドレスに設定されることになってしまいますIPアドレス表記

MacやLinuxではどうか

一方、MacOSXやLinuxのmanでは以下のように書かれています。

if a single -a argument is given, it displays the status of all interfaces, even those that are down. Otherwise, it configures an interface.

ここでは明示的に、すべてのinterfaceのステータスを表示する、ということが書かれており、間違って全てのinterfaceの設定を変更してしまう、ということは無さそうです。

どう対策するか

そもそも、interfaceのステータス表示させるためにはroot権限は不要ですので、不用意にrootで作業をしないという基本ルールでこのようなミスは防ぐことができます。


IPアドレス表記
このように数値をIPアドレスとして解釈してしまうのは、IPv4アドレスを192.168.0.1のようなRFC3986で規定されたドット表記だけではなく、3232235521という数値表記であっても許容するように、gethostbyname()inet_aton()といった関数で実装されているためです。SunOS/Solarisだけではなく、LinuxやMacOSXでも数値表記は可能となっています。

$ ping 3232235521
PING 3232235521 (192.168.0.1): 56 data bytes
64 bytes from 192.168.0.1: icmp_seq=0 ttl=64 time=3.197 ms
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=1.590 ms
^C
11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11