在 Ubuntu 18.04 LTS 服务器 增加 IP 地址 (含 ipv6)

下面是一个默认的示例 名称不唯一, VPS 会显示 eth0 ( 独服 kvm 等 )

Sample

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            addresses: []
            dhcp4: true
    version: 2

运行下面命令保存更改并生效

sudo netplan apply

Ubuntu 18.04 配置文件在 /etc/netplan/*.yaml (所有 yaml 结尾的文件)

如我的 VPS (BuyVM ) 文件在 /etc/netplan/01-netcfg.yaml

DigitalOcean 在 /etc/netplan/50-cloud-init.yaml

完整示例:

 # This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      addresses: [ '209.141.1x.x/24', '209.141.4x.x/24', '2605:6400:0020:x/48' ]
      gateway4: 209.141.1x.1
      gateway6: 2605:6400:0020::1
      nameservers:
        addresses: [ '205.185.112.68', '205.185.112.69' ]

Link: https://websiteforstudents.com/configure-static-ip-addresses-on-ubuntu-18-04-beta/

Leave a Reply

Your email address will not be published. Required fields are marked *