Leif160519的blog Leif160519的blog

——————

目录
ubuntu 20.04 server版设置静态IP地址
/  

ubuntu 20.04 server版设置静态IP地址

前言

ubuntu从17.10开始,已放弃在/etc/network/interfaces里固定IP的配置,interfaces文件不复存在,即使配置也不会生效,而是改成netplan方式 ,配置写在/etc/netplan/01-netcfg.yaml或者类似名称的yaml文件里

1.查看网卡设备号

ip a

image.png

2.修改yaml文件

sudo nano /etc/netplan/00-installer-config.yaml

image.png

network:
  ethernets:
    ens160:     #配置的网卡的名称
      addresses: [192.168.0.105/24]    #配置的静态ip地址和掩码
      dhcp4: no    #关闭DHCP,如果需要打开DHCP则写yes
      optional: true
      gateway4: 192.168.0.1    #网关地址
      nameservers:
         addresses: [114.114.114.114,180.76.76.76]    #DNS服务器地址,多个DNS服务器地址需要用英文逗号分隔开
  version: 2
  renderer: networkd    #指定后端采用systemd-networkd或者Network Manager,可不填写则默认使用systemd-workd

根据自己的需要配置好之后保存文件

3.让配置生效

sudo netplan apply

4注意事项:

  • ip地址和DNS服务器地址需要用[]括起来,但是网关地址不需要
  • 注意每个冒号后边都要先加一个空格
  • 注意每一层前边的缩进,至少比上一层多两个空格

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill

标  题ubuntu 20.04 server版设置静态IP地址
作  者Leif160519
出  处https://github.icu/articles/2020/07/05/1593929877123.html
关于博主:坐标南京,运维工程师,如有问题探讨可以直接下方留言。
声援博主:如果您觉得文章对您有帮助,可以评论、订阅、收藏。您的鼓励是博主的最大动力!