ubuntu18.04 如何通过命令行固定IP

ubuntu18.04 如何通过命令行固定IP呢?

本帖最后由 闫涛 于 2020-3-16 16:25 编辑

ubuntu版本:Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic

sudo apt-get install netplan.io
然后自己建一个01-netcfg.yaml 文件
内容为:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.203/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8,8.8.8.8]
ip信息,网关,dns,网卡信息根据自己的情况改。
然后把这个文件防到 /etc/netplan 下
执行sudo netplan try 或者sudo netplan apply 就可以了
sudo netplan try 会 检查你的01-netcfg.yaml文件是不是有问题如果没有问题就会生效。

格式调整
arm ubuntu18.04LTS

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
     dhcp4: no
     addresses: [192.168.1.222/24]
     gateway4: 192.168.1.1
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]