Foreword
Ubuntu 18.04 no longer uses ifupdown to configure the network, but instead uses netplan. It is invalid to configure a fixed IP in /etc/network/interfaces, and the command services network restrart or /etc/init.d/networking restart to restart the network is also invalid.
This article mainly introduces you to the related content of configuring fixed IP on Ubuntu 18.04, share it for your reference and study, let’s not say much, let’s take a look at the detailed introduction.
1. Use ifupdown to configure the network
If you want to use the previous method to configure the network, you need to reinstall ifupdown:
sudo apt install ifupdown
Modify the configuration file /etc/network/interfaces:
sudo vim /etc/network/interfaces
The configuration file is modified as follows:
iface ens160 inet static
address 210.72.92.25
gateway 210.72.92.254
netmask 255.255.255.0
dns-nameservers 8.8.8.8
Restart the network service for the configuration to take effect
sudo services network restrart
2. Use netplan to configure the network
Ubuntu 18.04 uses netplan to configure the network, and its configuration file is in yaml format. After installing Ubuntu 18.04, the default configuration file name in the /etc/netplan/ directory is 50-cloud-init.yaml, we modify it through VIM:
sudo vim /etc/netplan/50-cloud-init.yaml
The configuration file is modified as follows:
network:
ethernets:
ens160:
addresses:
– 210.72.92.28/24 # IP and mask
gateway4: 210.72.92.254 # Gateway
nameservers:
addresses:
– 8.8.8.8 # DNS
version: 2
Whether it is ifupdown or netplan, the configuration ideas are the same. Fill in the IP, mask, gateway, DNS and other information in the configuration file according to the rules. Note that yaml is a hierarchical structure and needs to be indented. A colon (:) means a dictionary, and a hyphen (-) means a list.
Restart the network service to make the configuration effective:
sudo netplan apply
to sum up
The above is the entire content of this article. I hope that the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message and exchange. Thank you for your support to ZaLou.Cn.
Recommended Posts