LoginSignup
1
4

More than 5 years have passed since last update.

systemd-networkでstatic route設定

Posted at

概要

coreosでルーティング設定を行うときにstatic routeの設定に手間取ったので記載
固定IP設定しつつstatic route設定を行おうとする場合に注意が必要

環境

CoreOS 1632.2.1
systemd 235

設定

最初に行った設定

localhost ~ # cd /etc/systemd/network/
localhost network # cat 10-eth0.network
[Match]
Name=eth0

[Network]
Address=XXX.XXX.XXX.XXX/XX
Gateway=YYY.YYY.YYY.YYY
LinkLocalAddressing=no
IPv6AcceptRA=no


localhost network # cat 20-static.network
[Route]
Destination=xxx.xxx.xxx.xxx/xx
Gateway=yyy.yyy.yyy.yyy

再起動してip rしてみるも、static routeが設定されていないのでログを確認する

localhost ~ # journalctl -u systemd-networkd

-- Reboot --
Feb 06 11:55:46 localhost systemd[1]: Starting Network Service...
Feb 06 11:55:46 localhost systemd-networkd[599]: Enumeration completed
Feb 06 11:55:46 localhost systemd[1]: Started Network Service.
Feb 06 11:55:46 localhost systemd-networkd[599]: lo: Could not set route: Network is unreachable

loに対して設定しようとしてる!
ってことでデバイス指定するように修正

デバイス指定してみたver

localhost network # cat 20-static.network
[Match]
Name=eth0

[Route]
Destination=xxx.xxx.xxx.xxx/xx
Gateway=yyy.yyy.yyy.yyy

再起動後ip rしてみるが、やはりstatic routeが設定されていない。。。
ログを確認するとエラーは出なくなっており、設定ファイルの読み込み自体がスキップされたっぽい
gateway違うしファイル分けていたけど分けないように設定してみる

ファイル一緒にしてみたver

localhost ~ # cd /etc/systemd/network/
localhost network # cat 10-eth0.network
[Match]
Name=eth0

[Network]
Address=XXX.XXX.XXX.XXX/XX
Gateway=YYY.YYY.YYY.YYY
LinkLocalAddressing=no
IPv6AcceptRA=no

[Route]
Destination=xxx.xxx.xxx.xxx/xx
Gateway=yyy.yyy.yyy.yyy

再起動後ipコマンド叩く

localhost ~ # ip r
default via YYY.YYY.YYY.YYY dev eth0 proto static
XXX.XXX.XXX.XXX/XX dev eth0 proto kernel scope link src XXX.XXX.XXX.XXX
xxx.xxx.xxx.xxx/xx via yyy.yyy.yyy.yyy dev eth0 proto static

無事追加されました!

1
4
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
1
4