vol29. SIOCADDRT: File exists/RTNETLINK answers: File exists エラー

$sudo systemctrl restart networking 

を実行すると、以下のエラー

Job for networking.service failed because the control process exited with error code.
See "systemctl status networking.service" and "journalctl -xe" for details.

ログ通りに

$journalctl -xe

を実行すると、

May 15 16:24:12 pc-linux avahi-daemon[598]: Joining mDNS multicast group on interface enp5s0.IPv4 with address 192.168.0.63
May 15 16:24:12 pc-linux avahi-daemon[598]: New relevant interface enp5s0.IPv4 for mDNS.
May 15 16:24:12 pc-linux avahi-daemon[598]: Registering new address record for 192.168.0.63 on enp5s0.IPv4.
May 15 16:24:12 pc-linux dhclient[12150]: bound to 192.168.0.63 -- renewal in 241 seconds.
May 15 16:24:12 pc-linux ifup[12133]: bound to 192.168.0.63 -- renewal in 241 seconds.
May 15 16:24:12 pc-linux ifup[12133]: SIOCADDRT: File exists
May 15 16:24:12 pc-linux ifup[12133]: ifup: failed to bring up enp5s0
May 15 16:24:15 pc-linux avahi-daemon[598]: Joining mDNS multicast group on interface enp8s0.IPv4 with address 192.168.101.2
May 15 16:24:15 pc-linux avahi-daemon[598]: New relevant interface enp8s0.IPv4 for mDNS.
May 15 16:24:15 pc-linux avahi-daemon[598]: Registering new address record for 192.168.100.20 on enp8s0.IPv4.
May 15 16:24:15 pc-linux ifup[12133]: RTNETLINK answers: File exists
May 15 16:24:15 pc-linux kernel: IPv6: ADDRCONF(NETDEV_UP): enp8s0: link is not ready
May 15 16:24:15 pc-linux ifup[12133]: ifup: failed to bring up enp8s0
May 15 16:24:15 pc-linux systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
May 15 16:24:15 pc-linux systemd[1]: Failed to start Raise network interfaces.

どうやら以下のログのとおり、ネットワークインターフェース enp5s0 と enp8s0 のifup で失敗している模様だ。

ifup[12133]: SIOCADDRT: File exists
ifup[12133]: ifup: failed to bring up enp5s0 

ifup[12133]: RTNETLINK answers: File exists                  
kernel: IPv6: ADDRCONF(NETDEV_UP): enp8s0: link is not ready 
ifup[12133]: ifup: failed to bring up enp8s0                    

ifup は/etc/network/interfaces の設定ファイルに基づいて、 ネットワークインターフェースの立ち上げを行うコマンド。

/etc/network/interfaces の設定は、

auto enp5s0
iface enp5s0 inet dhcp
    post-up route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.3.254

auto enp7s0
iface enp7s0 inet static
    address 192.168.101.2
    netmask 255.255.255.0
    gateway 192.168.101.1

auto enp8s0
iface enp8s0 inet static                                                                                                        
    address 192.168.100.20
    netmask 255.255.255.0
    gateway 192.168.100.1

ifup は -v オプションで詳細なログが表示される。 まずは、enp5s0が失敗する原因について調査。

$sudo ifdown --force enp5s0 
$sudo ifup -v  enp5s0      

ifup: configuring interface enp5s0=enp5s0 (inet)
/bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
run-parts: executing /etc/network/if-pre-up.d/ethtool
run-parts: executing /etc/network/if-pre-up.d/wpasupplicant

/sbin/dhclient -4 -v -pf /run/dhclient.enp5s0.pid -lf /var/lib/dhcp/dhclient.enp5s0.leases -I -df /var/lib/dhcp/dhclient6.enp5s0.leases enp5s0
....
DHCPDISCOVER on enp5s0 to 255.255.255.255 port 67 interval 6
DHCPREQUEST of 192.168.0.63 on enp5s0 to 255.255.255.255 port 67
DHCPOFFER of 192.168.0.63 from 192.168.3.254
DHCPACK of 192.168.0.63 from 192.168.3.254
bound to 192.168.0.63 -- renewal in 275 seconds.
route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.3.254
SIOCADDRT: File exists
ifup: failed to bring up enp5s0

なるほど、 route add コマンドの実行結果が、SIOCADDRT: File exists につながっているのね。

route add コマンドの直前まで、マニュアルでコマンドを実行して、routing table を表示してみると、

$sudo route -n 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.3.254   0.0.0.0         UG    0      0        0 enp5s0
192.168.0.0     0.0.0.0         255.255.248.0   U     0      0        0 enp5s0
192.168.100.0   0.0.0.0         255.255.255.0   U     0      0        0 enp8s0
192.168.101.0   0.0.0.0         255.255.255.0   U     0      0        0 enp7s0

route add コマンドで実施したいdefault gatewayがすでに追加されている。dhclient コマンドで設定されるみたいだ。

よって、/etc/network/interfaces から以下の行を削除。

post-up route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.3.254

同様の手順で、enp8s0 のerror の原因を調査してみると、以下の行が問題だったため、 削除。

gateway 192.168.100.1

最後にもう一度動作確認。

$sudo systemctrl restart networking 

よし。エラーなし!!


ちなみに、以下のようにifdown コマンドでinteface not configured エラーになる場合は、 /run/network/ifstate が壊れている。 ifconfig コマンドを使ってネットワークを立ち上げたり、ifup/ifdown コマンドが失敗したりして、ifstate ファイルの更新が失敗して、 実際のネットワークインターフェースの状態と不整合が起きた時に発生する。

その場合は、--force option をifup/ifdown コマンドに渡してあげれば、ifstate ファイルの状態を無視してコマンドを実行してくれる。

$sudo ifdown -v  enp5s0                                                                      
ifdown: interface enp5s0 not configured  

ネットワーク立ち上げ後は、以下が正常な状態

$ cat /run/network/ifstate
lo=lo
enp5s0=enp5s0
enp7s0=enp7s0
enp8s0=enp8s0

以下はネットワークがダウンしている状態

$ cat /run/network/ifstate
lo=lo