有馬総一郎のブログ

(彼氏の事情)

2023年12月23日 09:56:19 JST - 2 minute read - Comments - Linux

今更ながらUbuntu 22.04 LTSで`netplan`による固定IPアドレスの設定

家族に電源抜かれて、意図せず、再起動することとなり、起動コンソールを眺めていると、A start job is running for Wait for Network to be Configured (48s / no limit)な文字が…あれ?

起動が遅い。

[  OK  ] Started Disk Manager.
[  OK  ] Started cloudflared.
[  *   ] A start job is running for Wait for Network to be Configured (48s / no limit)

/etc/network/interfacessource /etc/network/interfaces.d/*を削除するも直らない。そういや、ネットワーク設定が変更になったようなことを聞いた覚えがあった、と調べると

2017年6月23日号 ネットワーク設定スタックの変更、Ubuntu Phoneの振り返り | gihyo.jp

新しいYAMLベースのネットワーク設定ユーティリティであるnetplanが、17.10ではデフォルトで利用されるようになります。

とあった。いやぁ、今までよく平気だったなぁ。18.04から20.04、22.04にここ1年ぐらい一気に上げたので気付かないままだった。

$ ls /etc/netplan/

何もない。 00-installer-config.yaml もない。なら作れば良いということで、

/etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp3s0
# mod 2016/04/24 start
#iface enp3s0 inet dhcp
iface enp3s0 inet static
address 192.168.0.10
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.2
dns-nameservers 127.0.0.1
# This is an autoconfigured IPv6 interface
iface enp3s0 inet6 auto

上記、過去の遺物から Ubuntu 20.04 LTSで固定IPアドレスの設定 #Linux - Qiitaを参考に

/etc/netplan/99_config.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: false
      dhcp6: false
      addresses: [192.168.0.10/24]
      gateway4: 192.168.0.2
      nameservers:
        addresses: [127.0.0.1, 8.8.8.8, 8.8.4.4]

で、早速sudo netplan applyすると** (generate:4378): WARNING **: 09:16:02.041: Permissions for /etc/netplan/99_config.yaml are too open. Netplan configuration should NOT be accessible by others.の警告が表示される。

networking - Need help with a Netplan configuration issue - Ask Ubuntu

の答えにあるとおり、sudo chmod 600 /etc/netplan/99_config.yamlすることで解決。

次に

** (generate:4378): WARNING **: 09:16:02.042: `gateway4` has been deprecated, use default routes instead.

とまさに Ubuntu22.04 netplanでgateway4は非推奨といわれた | ろっひーの警告が出たので、

/etc/netplan/99_config.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: false
      dhcp6: false
      addresses: [192.168.0.10/24]
      routes:
        - to: default
          via: 192.168.0.2
      nameservers:
        addresses: [127.0.0.1, 8.8.8.8, 8.8.4.4]

と修正した。

        - to: default
        via: 192.168.0.2

viaのインデントを-と揃えて書いたら、

ERROR:root:/etc/netplan/99_config.yaml:11:9: Invalid YAML: did not find expected '-' indicator:
        via: 192.168.0.2

と怒られた。yamlの書き方として駄目なのね。

それからも、WARNING:root:Cannot call Open vSwitch: ovsdb-server.service is not running.と警告が表示されたが

netplan apply で ovsdb-server.service is not running. – 手当たり次第に書くんだ

にあるとおり、必要としないものをインストールするのは、私も気が引けたがsudo apt install openvswitch-switchで警告は解消された。

再起動すると、こんどはネットワーク設定で待たされることなく起動した。

Tags: Ubuntu Server

アプリでなくブラウザからSend to Kindleしてパーソナル・ドキュメントに保存する NTFSでフォーマットしたHDDがLinux(Pop!_OS)で自動で認識された

comments powered by Disqus