vi /etc/netplan/01-network-manager-all.yaml

version: 2
  renderer: networkd
  ethernets:
    ens33:
      addresses: [192.168.0.55/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [223.5.5.5, 223.6.6.6] 

sudo netplan apply

22.04

version: 2
  renderer: networkd  #NetworkManager 桌面版  networkd:服务器和无头
  ethernets:
    ens33: #更改为ip a里的名称
      dhcp4: false
      addresses: [192.168.0.55/24]
      optional: true
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [223.5.5.5, 223.6.6.6]

ipv4和ipv6配置

vi /etc/netplan/01-installer-config.yaml #文件名可以定义

# This is the network config written by 'subiquity'
network:
  version: 2
  ethernets:
    ens3:
      dhcp4: no
      dhcp6: no
      addresses:
        - 202.119.197.216/24
        - 2001:DA8:100D:AD::942:216/116
      routes:
        - to: default
          via: 202.119.197.1
        - to: default
          via: "2001:DA8:100D:AD::942:1"
      nameservers:
          addresses:
        - 114.114.114.114 
        - 2400:3200::1
        #或者
        addresses: [114.114.114.114,8.8.4.4]

腾讯云ubuntu22 分配ipv6不完全,不能分配网关地址

  • 解决方案
    vi /etc/netplan/50-cloud-init.yaml 手工添加网关地址, 网关地址在 私有网络-子网-ipv6CIDR 中可以看到
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            match:
                macaddress: 52:54:00:45:b4:e8
            set-name: eth0
            routes:  # 从这里开始是新加的
                - to: default
                  via: "2402:4e00:1409:4a02::1"