操作系统:
查看系统版本信息的命令 lsb_release -a
root@iZuf639Z:~# lsb_release -a
LSB Version: core-9.20170808ubuntu1-noarch:security-9.20170808ubuntu1-noarch
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
root@iZuf639Z:~#
查看使用的ip
root@iZuf639Z:~# ip addr
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
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:16:3e:02:26:29 brd ff:ff:ff:ff:ff:ff
inet 172.24.59.34/18 brd 172.24.63.255 scope global dynamic eth0
valid_lft 284109946sec preferred_lft 284109946sec
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:de:35:29:b0 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
root@iZuf639Z::~#
2.1、首先修改网卡配置文件;
sudo vi /etc/netplan/00-installer-config.yaml
然后修改其中的addresses、gateway4;
修改后查看如下:
上述的名称说明:
eth0:网卡名称;
dhcp4:动态ipv4;
dhcp6:动态ipv6;
addresses:自定义固定ip,其中172.24.59.34/18,其中18表示掩码位数是18位, 对应的子网掩码:255.255.192.0;
gateway4: 网关;
nameservers:DNS服务器配置,可以不设置;
注意:
网卡配置文件为yaml文件,要注意格式对齐,如用2个空格为单位递进对齐,就要始终如一的用2个空格为单位;
配置文件的名称不一定是00-installer-config.yam;
例如博主的配置文件名称是99-netcfg.yaml:
root@iZuf639Z:~# cat /etc/netplan/00-installer-config.yaml
cat: /etc/netplan/00-installer-config.yaml: No such file or directory
root@iZuf639Z:~# cd /etc/netplan/
root@iZuf639Z:/etc/netplan# ls
99-netcfg.yaml
root@iZuf639Z:/etc/netplan# cat 99-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
dhcp6: no
root@iZuf639Z:/etc/netplan#
2.2、生效配置。
netplan apply