Arch Linuxで固定IP設定にはまる

ようやく届いたCuBox-i4 ProにArch Linuxも無事インストールできて。一安心しましたが、僕らはこいつを固定IP運用したいのに、なかなかDHCPから離れてくれませんでした。調査結果をまとめておきます。

【まとめ】

2015-06現在では、おおまかに言って、

1. 既存のeth0のprofileを固定IP用に修正。
2. netctl-ifplugd@eth0.serviceを停止。
3. netctl@eth0を開始。

この3つのステップで固定IP設定できると思います。

1. eth0の修正

/etc/netctl/eth0

Description='A basic static ethernet connection'
Interface=eth0
Connection=ethernet
AutoWired=yes
IP=static
Address='xxx.xxx.xxx.xxx/yy'
Gateway='xxx.xxx.xxx.xxx'
DNS='xxx.xxx.xxx.xxx'
ExecUpPost='/usr/bin/ntpd -gq || true'

2. netctl-ifplugd@eth0.serviceの停止

systemctl stop netctl-ifplugd@eth0 
netctl stop-all
systemctl disable netctl-ifplugd@eth0.service

3. netctl@eth0の開始

systemctl start netctl@eth0

【調査経緯】
2014年5月現在のArch Linuxのネットワーク周りはnetctlで設定します。profileを用意してそれを切替えるイメージです。
Beginners’ Guide (日本語)(wiki.archlinux.org)
こちらの記事に、
ArchLinuxのnetctl設定 | ぽにっとブログ
「上記設定内にNTPの記載があり、これを消すと起動時に時刻が取得できない」と言う記述があり、確かにデフォルトのeth0のprofileには、
ExecUpPost=’/usr/bin/ntpd -gq || true’
とntpdについての記述があるので、eth0に対して修正して使うことにしました(バックアップはとります、もちろん)。
その上で、
systemctl stop dhcpcd.service
systemctl disable dhcpcd.service
としてDHCPクライアントサービスは停止して、rebootで再起動。

が、やはりDHCPからIPをとってきてしまいます。とほほ。
netctl status eth0
で状況を見てみると、
[bash]
netctl@eth0.service – A basic static ethernet connection
Loaded: loaded (/etc/systemd/system/netctl@eth0.service; enabled)
Active: failed (Result: exit-code)
Docs: man:netctl.profile(5)
[/bash]
と「failed」表示となっており、どうやら修正したeth0のprofileが読み込まれていない様子。さっそくググります。
Raspberry Pi • View topic – Static IP network config fails to load
Raspberry Piユーザの掲示板とは言え、症状がそっくりです。下の方まで読んでいくと、
[bash]
systemctl status netctl-ifplugd@eth0
[/bash]
で調べてみろ、と書いてあります。すると、ありました。
[bash]
* netctl-ifplugd@eth0.service – Automatic wired network connection using netctl profiles
Loaded: loaded (/usr/lib/systemd/system/netctl-ifplugd@.service; enabled)
Active: active (running)
Docs: man:netctl.special(7)
Main PID: 235 (ifplugd)
CGroup: /system.slice/system-netctl\x2difplugd.slice/netctl-ifplugd@eth0.service
|-235 /usr/bin/ifplugd -i eth0 -r /etc/ifplugd/netctl.action -bfIn…
`-366 dhcpcd -4qL -t 30 eth0
[/bash]
であれば、後はもう言う通りに(笑)、
[bash]
systemctl stop netctl-ifplugd@eth0
netctl stop-all
systemctl start netctl@eth0
[/bash]
と連続実行です。

いや〜見事に固定IP用のprofileが読み込まれました。

しかし、まだ終わりません。再起動するとまたDHCPでIP取得しています。
netctl (日本語)(wiki.archlinux.org)
ここをよく読んでみると、

netctl-ifplugd@interface.service は DHCP を使うプロファイルを優先します。固定 IP のプロファイルを優先させるために、AutoWired=yes を使うことができます。

という記述が!これか!と思って、eth0のprofileに、
AutoWired=yes
の1行を追加。ついにrebootしても固定IPになりました。

参考までに、最終的なeth0のprofileを(IPはxxxとしているので、その部分はそれぞれの環境にあわせてください)。
[bash]
Description=’A basic static ethernet connection’
Interface=eth0
Connection=ethernet
AutoWired=yes
IP=static
Address=’xxx.xxx.xxx.xxx/yy’
Gateway=’xxx.xxx.xxx.xxx’
DNS=’xxx.xxx.xxx.xxx’
ExecUpPost=’/usr/bin/ntpd -gq || true’
[/bash]

2015-06-29追記

サーバの更新をした後に、またも固定IP設定が有効にならなくなりました。
最終的には、netctl-ifplugd@interface.serviceは所詮、有線LANケーブルの抜き差し時によきに計らってくれるサービスのようなので、今回の環境では不要と判断し、停止してしまいました。

systemctl disable netctl-ifplugd@eth0.service

最初からこの対応で十分だったのかも知れません。

コメントを残す

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.