Ubuntu 18.04 单网卡多 IP 设置

文章作者:技术宅 | 2022-05-20
字体大小:

Ubuntu 17.04 和18.04系统版本启用了新的网络工具netplan,对于命令行配置网络参数跟之前的版本有比较大的差别

之前的版本是在/etc/network/interfaces中修改
新版本使用/etc/netplan/*.yaml

查看系统版本命令

lsb_release -a

网卡配置详细举例

1.使用vi 编辑配置网卡文件

vim /etc/netplan/*.yaml

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eno1: #配置的网卡名称
      addresses: [ 192.168.0.1/27 ] #设置本机IP及掩码
      gateway4: 192.168.0.254 #设置网关
      nameservers:
          addresses: [8.8.8.8] #设置DNS

若要添加IP:192.168.0.2, 192.168.0.3, 192.168.0.4

修改上述内容为:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eno1: #配置的网卡名称
      addresses: [ 192.168.0.1/27, 192.168.0.2/28, 192.168.0.3/29, 192.168.0.4/30 ] #设置本机IP及掩码
      gateway4: 192.168.0.254 #设置网关
      nameservers:
          addresses: [8.8.8.8] #设置DNS

2.执行命令使网卡配置文件生效

netplan apply

实在不行重启服务器

暂时关闭评论!
Copyright © 2019 技术宅 版权所有 关于我们| 法律声明| 免责声明| 广告服务| 联系我们| 投稿| 充值| 豫ICP备2023024979号