linux/ubuntu22一个网卡设置多ip

星野梦璃
2024-05-10 / 0 评论 / 338 阅读

配置文件路径

/etc/netplan/your_config_file.yaml

修改后保存提示权限问题,权限改成600

sudo chmod 600 /etc/netplan/your_config_file.yaml

默认配置

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  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:
    version: 2
    ethernets:
        enp1s0:
            dhcp4: true
            dhcp6: true
            match:
                macaddress: 56:00:04:e6:60:72
            set-name: enp1s0

修改后配置

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  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:
    version: 2
    ethernets:
        enp1s0:
            dhcp4: false
            dhcp6: true
            match:
                macaddress: 56:00:04:e6:60:72
            set-name: enp1s0
            addresses:
              - 108.61.163.120/24   ## set static IP
              - 207.148.96.242/24   ## set static IP
            routes:
              - to: default
                via: 108.61.163.1  ## gateway
            nameservers:
              addresses: [8.8.8.8,8.8.4.4,108.61.163.1,108.61.163.255]
0

评论 (0)

取消