Administrator
发布于 2023-09-28 / 67 阅读 / 0 评论 / 0 点赞

Ubuntu设置IP

第1步: 查看当前主机的网卡名,当前ip, 子网掩码,网关地址

ifconfig
route -n

如果ifconfig命令无法使用, 请运行以下命令安装net-tools

sudo apt update -y 
sudo apt install net-tools -y


查看当前主机的网卡名,当前ip, 子网掩码,网关地址

如上图所示:网卡名为 enp0s5, 当前ip 10.211.55.6, 子网掩码 255.255.255.0, 网关地址 10.211.55.1

第2步: 修改配置文件

  • 进入配置文件夹

cd /etc/netplan

复制

  • 备份旧配置文件内容为 00-installer-config.yaml_before

sudo cp 00-installer-config.yaml  00-installer-config.yaml_before

复制

00-installer-config.yaml 的内容为:

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s5:
      dhcp4: true
  version: 2
  • 修改配置文件

sudo vim 00-installer-config.yaml

更新后的00-installer-config.yaml内容为:

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s5:   # 网卡名称
      dhcp4: no     # 关闭dhcp
      dhcp6: no
      addresses: [10.211.55.10/24]  # 静态ip
      gateway4: 10.211.55.1     # 网关
      nameservers:
        addresses: [8.8.8.8, 114.114.114.114] #dns

第3步: 使配置生效

sudo netplan apply

复制

  • 查看修改效果

IP修改成功并顺利联网


评论