How to configure a fixed IP based on Ubuntu 18.04

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

How to configure a fixed IP based on Ubuntu 18.04
How to set a fixed IP based on Ubuntu 16.04
How to configure Redis cluster on Ubuntu 14.04
How to configure Redis replication on Ubuntu 16.04
How to install and configure NATS on Ubuntu 16.04
How to install and configure Gogs on Ubuntu 18.04
How to install and configure Cyberpanel on Ubuntu 18.04
ubuntu16.0.4 method to set a fixed IP address
How to set static IP on Ubuntu 18.04 Server
How to install and configure ownCloud on Ubuntu 16.04
Explain how to set static IP on ubuntu14.04
How to install and configure GitLab on Ubuntu 18.04
How to install and configure Ansible on Ubuntu 18.04
How to install and configure Elasticsearch on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
How to install and configure VNC on Ubuntu 18.04
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
How to configure Apache content caching on Ubuntu 14.04
How to install and configure AppScale on Ubuntu 12.04
How to install and configure PostGIS on Ubuntu 14.04
How to set up a DNS server on Ubuntu 18.04
How to start a blog with Hexo on Ubuntu 14.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to upgrade to PHP 7 on Ubuntu 14.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to deploy Django on Ubuntu 14.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04