0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

netplanとは

Last updated at Posted at 2024-08-30

環境

Ubuntu 24.04

ipアドレスを設定したい

ipアドレスは/etc/network/interfacesファイルに設定を記述します。

それらしきディレクトリやファイルがなかったので調べた。

netplanに変更された

New since 17.10
...
ifupdown has been deprecated in favor of netplan.io and is no longer present on new installs.

これらの現代的なネットワーク設定ツールは旧来の "ifupdown" パッケージやその "/etc/network/interfaces" 設定ファイルとの競合を避けるように適正に設定する必要があります。

とりあえずifupdownが非推奨になったためnetplan.ioが使われるようになったのかもしれない。

netplanはどんなことをするのか?

Netplan reads network configuration from /etc/netplan/*.yaml which are written by administrators, installers, cloud image instantiations, or other OS deployments. During early boot, Netplan generates backend specific configuration files in /run to hand off control of devices to a particular networking daemon.

https://netplan.io/#:~:text=Netplan%20reads%20network,particular%20networking%20daemon.

yumファイルでネットワークを構成するのか。

netplan get

To show the current configuration

user01@user01-VirtualBox:~$ sudo netplan get
[sudo] user01 のパスワード: 
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s3:
      dhcp4: true

ネットワークの構成を確認することができる

netplan status --all

The command displays the current network configuration of the system.

root@user01-VirtualBox:/home/user01# netplan status
...
●  2: enp0s3 ethernet UP (NetworkManager: enp0s3)
      MAC Address: 08:00:27:00:f0:ff (Intel Corporation)
        Addresses: *********
                   ********************* (link)
           Routes: ******* from ******* metric 101 (link)
                   ******** metric 256
...

現在のシステムのネットワークの構成を映す

ネットワークを構成するファイルの位置

Netplan configuration is stored in YAML-formatted files in the /etc/netplan directory. To display the contents of the directory, run:

そこになかったらlib/netplanの中にあった

user01@user01-VirtualBox:~$ netplan get
Command failed: Cannot open /lib/netplan/00-network-manager-all.yaml: Permission denied
user01@user01-VirtualBox:~$ sudo netplan get
[sudo] user01 のパスワード: 
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s3:
      dhcp4: true

etc/netplanにyamlファイルを作成すると変わった

user01@user01-VirtualBox:~$ sudo netplan get

** (process:33196): WARNING **: 09:11:25.813: Permissions for /etc/netplan/second-interface.yaml are too open. Netplan configuration should NOT be accessible by others.
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s3:
      dhcp4: true

ipアドレスを設定する

To set a static IP address, use the addresses keyword, which takes a list of (IPv4 or IPv6) addresses along with the subnet prefix length (e.g. /24).

netplan set

ネットワーク構成を変更する

netplan set --origin-hint second-interface ethernets.enp0s3.addresses=10.0.3.17/24

--origin-hintは変更対象のファイル名

netplan try

Test the new configuration
Applies the new configuration temporarily (120 seconds by default) and waits for confirmation (within the specified time) to make it permanent.

エンターを押しつづける

netplan apply

Apply the new Netplan configuration

設定を適用させる

ping

pingでも通った

出典

感想

読めない英語を読むのは大変で時間もかかった。
これからも英語の記事を読むことを続けようと思う。
日本語の記事も同じようなこと書いてあったのでそれも参考にした。
間違えていることもありますので出典をよく呼んでください。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?