Complete steps to configure IP address in Ubuntu 18.04 LTS

Foreword

The method of configuring the IP address in Ubuntu 18.04 LTS is very different from the previous configuration method. The difference from the old version is that Ubuntu 18.04 uses Netplan to configure the IP address. Netplan is a new command line network configuration tool. In fact, Ubuntu developers have already introduced Netplan in Ubuntu 17.10. The new IP configuration method to be introduced next will no longer use the /etc/network/interfaces file, instead it will be a YAML file. The default Netplan configuration file is generally in the /etc/netplan directory.

In this tutorial, we will learn to configure static IP and dynamic IP in the minimal server of Ubuntu 18.04 LTS.

Configure static IP address in Ubuntu 18.04 LTS

First find out where Netplan's default network configuration file is located:

$ ls /etc/netplan/50-cloud-init.yaml

We can see that the default network configuration file is 50-cloud-init.yaml, which is a YAML file.

Then we look at what the content of this file is:

$ cat /etc/netplan/50-cloud-init.yaml

When I installed Ubuntu 18.04 before, I had already done the relevant configuration of the network card in order to obtain the IP address from the DHCP server, so the detailed configuration directly looks at the following figure:

You can see that there are two network cards here, enp0s3 and enp0s8, and both of them are configured to obtain IP from the DHCP server.

Now we configure the two network cards as static IP addresses, first use any editor to edit the configuration file.

$ sudo nano /etc/netplan/50-cloud-init.yaml

Next we add IP address, subnet mask, gateway, DNS server and other configurations respectively. Use 192.168.225.50 as the IP address of the network card enp0s3, 192.168.225.51 as the IP address of the network card enp0s8, 192.168.225.1 as the gateway address, and 255.255.255.0 as the subnet mask. Then use the two DNS server IPs 8.8.8.8 and 8.8.4.4.

One thing to note is that in Ubuntu 18.04, each line of this configuration file must be indented by spaces and cannot be replaced by TAB, otherwise the configuration will not work. As shown in the figure above, the indentation of each line in the configuration file is achieved by the space bar.

At the same time, in Ubuntu 18.04, when we define the subnet mask, we do not divide the IP and subnet mask into two configurations like the old version. In the old version of Ubuntu, we generally configure the IP and subnet mask like this:

address =192.168.225.50
netmask =255.255.255.0

In netplan, we combine these two into one, like this:

addresses :[192.168.225.50/24]

Save and close the configuration file after the configuration is complete. Then use the following command to apply the configuration just now:

$ sudo netplan apply

If there is a problem when applying the configuration, you can use the following command to check what went wrong with the configuration just now.

$ sudo netplan --debug apply

This command will output these debug information:

**( generate:1556): DEBUG:09:14:47.220: Processing input file //etc/netplan/50-cloud-init.yaml..**(generate:1556): DEBUG:09:14:47.221: starting newprocessing pass
**( generate:1556): DEBUG:09:14:47.221: enp0s8: setting default backend to 1**(generate:1556): DEBUG:09:14:47.222: enp0s3: setting default backend to 1**(generate:1556): DEBUG:09:14:47.222: Generating output files..**(generate:1556): DEBUG:09:14:47.223: NetworkManager: definition enp0s8 is not forus(backend 1)**(generate:1556): DEBUG:09:14:47.223: NetworkManager: definition enp0s3 is not forus(backend 1)
DEBUG:netplan generated networkd configuration exists, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:device enp0s3 operstate is up, not replugging
DEBUG:netplan triggering .link rules for enp0s3
DEBUG:device lo operstate is unknown, not replugging
DEBUG:netplan triggering .link rules for lo
DEBUG:device enp0s8 operstate is up, not replugging
DEBUG:netplan triggering .link rules for enp0s8

If the configuration is normal and effective, we can use the following command to check the ip:

$ ip addr

After the configuration is completed in my Ubuntu 18.04, the output of the command output is as follows:

So far, we have successfully completed the static IP configuration with Netplan in Ubuntu 18.04 LTS.

More information about Netplan can be found in the manual with the man command:

$ man netplan

Configure dynamic IP address in Ubuntu 18.04 LTS

In fact, the initial configuration in the configuration file is the configuration of dynamic IP, so you don't need to do any configuration operations if you want to use dynamic IP. If you have configured a static IP address and want to restore the previous dynamic IP configuration, just delete the relevant configuration items added in the static IP configuration above, and restore the entire configuration file to the form shown in Figure 1 above. .

Now you have learned to configure static and dynamic IP addresses in Ubuntu 18.04. Personally, I don't really like this method. The old configuration method is simpler. what do y'all think?

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

Complete steps to configure IP address in Ubuntu 18.04 LTS
Complete steps to realize face recognition login in Ubuntu
Example of how to modify ip address in Ubuntu20.04
ubuntu modify and configure ip address
Steps to upgrade Laravel 5.4 to 5.6 in Ubuntu 16.04
Configure Java development environment in Ubuntu20.04 LTS
How to set static IP in ubuntu14.04
How to configure /var/log/messages in Ubuntu system log
ubuntu 14.04 configure 3-wire 3IP
Centos7 configure IP address
How to configure a fixed IP based on Ubuntu 18.04
Detailed steps to configure Ubuntu 16.04 and Apache virtual host
How to upgrade to Ubuntu 16.04 LTS
Detailed steps to automatically set the line number in ubuntu16.04
Ubuntu 18.04 uses elastic network card to configure multiple external network IP
Detailed steps to install and configure k8s cluster in centos 7
How to install Helm in Ubuntu
How to use hanlp in ubuntu
How to install mysql in Ubuntu 14.04
Install and configure Docker in Ubuntu
Windows10 update Ubuntu20.04 LTS method steps
Detailed steps to install MySQL to change the default password in Ubuntu
How to install mysql in Ubuntu 14.04
How to add swap partition in Ubuntu
How to easily compile openJDK in Ubuntu
ubuntu16.04 method steps to upgrade the kernel
How to install cuda10.1 driver in Ubuntu
How to add users to Sudoers in Ubuntu
How to delete redundant kernels in Ubuntu
Steps to build LNMP environment on ubuntu 20.04
Beautify Ubuntu 18.04 to Mac style in 5 minutes
How to configure Redis cluster on Ubuntu 14.04
How to install ROS Noetic in Ubuntu20.04
Ubuntu20.04 steps to install cuda10.1 (graphic tutorial)
How to modify software source in Ubuntu 7.10
How to open root account in Ubuntu20.04
How to configure Redis replication on Ubuntu 16.04
How to hide applications in Ubuntu Dash?
How to set static IP on Ubuntu 18.04 Server
How to install and configure Gogs on Ubuntu 18.04
How to modify time zone and time in ubuntu
How to install and configure Cyberpanel on Ubuntu 18.04
Detailed steps to install Anaconda on Linux (Ubuntu 18.04)
How to set static IP on Ubuntu 18.04 Server
How to install and configure ownCloud on Ubuntu 16.04
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 python in ubuntu server environment
Detailed steps to install Anaconda on Linux (Ubuntu 18.04)
How to use dpkg command in Ubuntu system
ubuntu20.04 set static ip address (including different versions)
How to open the ubuntu system in win10
CentOS 8 complete steps to set up automatic updates
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
Steps to add toolkit for Matlab_Linux under ubuntu
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
Remotely connect to MySQL database in Ubuntu environment