# This is the network config written by 'subiquity'
network:
ethernets:
enp0s3:
dhcp4: false
addresses: [10.16.0.194/16]
optional: true
gateway4: 10.16.255.254
version: 2
sudo netplan apply
--------------------
参考:https://www.cnblogs.com/kehoudaanxianjie/p/13139636.html
ubuntu20.04设置配置静态ip方法
1. 前言
本教程将会演示如何设置Ubuntu16.04 Server版和Ubuntu18.04 Server版系统的静态固定IP地址。
2. 确认你要修改的网卡号
先确认你要修改的网卡号,假设你的服务器有多张网卡:
1
|
ubuntu2004:~$ ip addr |
我的服务器配置如下:
1
2
3
4
5
6
7
8
9
10
11
12
|
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:f1:b5:e1 brd ff:ff:ff:ff:ff:ff inet 172.16.87.140/24 brd 172.16.87.255 scope global dynamic ens33 valid_lft 1500sec preferred_lft 1500sec inet6 fe80::20c:29ff:fef1:b5e1/64 scope link valid_lft forever preferred_lft forever |
3. 默认的网卡配置文件
默认情况下,网络使用DHCP
1
2
3
4
5
6
7
8
9
10
|
ubuntu1804:~$ cat /etc/netplan/50-cloud-init.yaml 配置文件内容如下 network: ethernets: ens33: dhcp4: yes addresses: [] version: 2 |
4. ubuntu20.04设置静态IP
需要把配置文件修改为以下内容:
1
|
ubuntu1804:~$ sudo vi /etc/netplan/50-cloud-init.yaml |
假设IP地址修改为192.168.1.100,子网掩码24位即255.255.255.0,网关设置为192.168.1.1,DNS1:223.5.5.5,DNS2:223.6.6.6
1
2
3
4
5
6
7
8
9
10
11
|
network: ethernets: ens33: dhcp4: no addresses: [192.168.1.100/24] optional: true gateway4: 192.168.1.1 nameservers: addresses: [223.5.5.5,223.6.6.6] version: 2 |
5. 应用新配置
1
|
ubuntu1804:~$ sudo netplan apply |
使用ip addr
检查新地址
1
|
ubuntu2004:~$ ip addr |
6. 测试网络连通性
ubuntu1804:~$ ping 192.168.1.100