--- title: Ubuntu Bionicでstatic ipの設定メモ tags: ["Ubuntu"] categories: ["Dev", "OS", "Linux", "Ubuntu"] date: 2020-11-29T10:49:50Z updated: 2020-12-30T04:17:36Z --- いつも忘れるのでメモ 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の設定になっている。 ```yaml 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`を設定する例。 ```yaml 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 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 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 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 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 ```