This tutorial will demonstrate how to set the static fixed IP address of Ubuntu 16.04 Server and Ubuntu 18.04 Server.
First confirm the number of the network card you want to modify, assuming your server has multiple network cards:
ubuntu1804:~$ ip addr
My server configuration is as follows:
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
By default, the network uses DHCP
ubuntu1804:~$ cat /etc/netplan/50-cloud-init.yaml
The content of the configuration file is as follows
network:
ethernets:
ens33:
dhcp4: yes
addresses:[]
version:2
The configuration file needs to be modified as follows:
ubuntu1804:~$ sudo vi /etc/netplan/50-cloud-init.yaml
Suppose that the IP address is changed to 192.168.1.100, the subnet mask is 24 bits or 255.255.255.0, the gateway is set to 192.168.1.1, DNS1: 223.5.5.5, DNS2: 223.6.6.6
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
ubuntu1804:~$ sudo netplan apply
Use ip addr
to check the new address
ubuntu1804:~$ ip addr
ubuntu1804:~$ ping 192.168.1.100
Recommended Posts