Linuxのサーバーに複数のNICがあるとeth0やeth1などの名前が認識された順に振られていくと思いますが、時にはその名前を入れ替えたり、変更したりしたくなる時もあると思います。調べてみると、RedHat系ではifcfg-ethXにHWADDRを指定してあげるとその通りになってくれるという記事があるのでやってみた。
(この記事はScientificLinux6.1について書いてあります。CentOSやRHELでも同じだと思います)
例:eth2をconsole0という名前に変更
とりあえず/etc/sysconficg/network-scripts/ifcfg-console0というファイルを作成
DEVICE="console0" ONBOOT=yes HWADDR=1C:6F:65:E8:03:9A TYPE=Ethernet BOOTPROTO=none IPADDR=192.168.11.5 PREFIX=24
こうして再起動すると、なぜかDevice eth0 has different MAC address than expected, ignoring.だのDevice eth0 does not seem to be present, delaying initialization.だのと怒られる。さらにごちゃごちゃいじってるとifconfig -aをやった時にeth1-eth3などという謎のデバイスが出現したり意味不明。全く意図した動作をしてくれない。
うーむ。
という事で1時間程度ぐぐって調べるとudevが悪さをする事があるという記事を発見。早速udevの設定ファイルを確認してみると。
/etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules # program, run by the persistent-net-generator.rules rules file. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. # PCI device 0x8086:0x10d3 (e1000e) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1b:21:bf:66:be", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1" # PCI device 0x8086:0x10d3 (e1000e) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="1c:6f:65:e8:03:9a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2" (以下略)
あぁー、これっぽい。設定ファイルは自動的に生成してくれそうなので、とりあえず70-persistent-net.rules を70-persistent-net.rules~dist辺りにリネームして再起動すると、ちゃんとHDADDRの指定どおりの名前が振られた。
という事で原因はudevでした。