Dev > OS > Linux > Ubuntu
Nov 29, 2020
Dec 30, 2020
N/A Views
MD
warning
この記事は2年以上前に更新されたものです。情報が古くなっている可能性があります。

いつも忘れるのでメモ

https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.ova からイメージを作った場合の例。

/etc/netplan/50-cloud-init.yamlをコピーして/etc/netplan/99-static-ip.yamlを作成し、次のように編集する。

デフォルトはDHCPの設定になっている。

network:
    ethernets:
        ens192:
            dhcp4: true
            match:
                macaddress: 00:50:56:a8:bb:07
            set-name: ens192
    version: 2

static ipにする場合。192.168.11.230/24を設定する例。

network:
    ethernets:
        ens192:
            dhcp4: false
            addresses:
                - 192.168.11.230/24
            gateway4: 192.168.11.1
            nameservers:
                addresses: [8.8.8.8, 8.8.4.4]
            match:
                macaddress: 00:50:56:a8:bb:07
            set-name: ens192
    version: 2

設定を反映。

sudo netplan apply

変更後のIPでSSHログインし直し。

$ ifconfig
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.230  netmask 255.255.255.0  broadcast 192.168.11.255
        inet6 fe80::250:56ff:fea8:bb07  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:a8:bb:07  txqueuelen 1000  (Ethernet)
        RX packets 6449  bytes 1244266 (1.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1507  bytes 275611 (275.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 158  bytes 11706 (11.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 158  bytes 11706 (11.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
Found a mistake? Update the entry.
Share this article: