Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure IP address in Ubuntu18.04 LTS

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to configure IP address in Ubuntu18.04 LTS", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to configure IP address in Ubuntu18.04 LTS".

Preface

The method of configuring IP addresses in Ubuntu 18.04 LTS is quite different from that used in the past. Unlike the previous version, Ubuntu 18.04 uses Netplan to configure IP addresses, and Netplan is a new command line network configuration tool. In fact, Ubuntu developers introduced Netplan in Ubuntu 17.10. The new IP configuration method to be introduced next will no longer use the / etc/network/interfaces file and will be replaced by a YAML file. The default Netplan configuration file is usually in the / etc/netplan directory.

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

Configure static IP addresses in Ubuntu 18.04 LTS

First find where the default network profile for Netplan is located:

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

As we can see, the default network profile is 50-cloud-init.yaml, which is a YAML file.

Then let's take a look at the contents of this file:

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

I have already configured the Nic to obtain the IP address from the DHCP server when I installed Ubuntu 18.04 before, so please see the following figure for detailed configuration:

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

Now that we configure both network cards with static IP addresses, edit the configuration file with either editor.

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

Next, we add configurations such as IP address, subnet mask, gateway, DNS server, etc. 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 servers, 8.8.8.8 and 8.8.4.4, to IP.

It is important to note that in Ubuntu 18.04, every line of this profile must be indented by spaces and cannot be replaced by TAB, otherwise the configuration will not work. The indentation of each line in the configuration file shown above is achieved by the spacebar.

At the same time, in Ubuntu 18.04, we did not divide the IP and subnet mask into two configurations as in the previous version. In the old version of Ubuntu, the general configuration of IP and subnet mask is as follows:

Address = 192.168.225.50netmask = 255.255.255.0

In netplan, we combine these two items 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 previous configuration:

$sudo netplan apply

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

$sudo netplan-debug apply

This command outputs this debug information:

* * (generate:1556): DEBUG: 09 etc/netplan/50-cloud-init.yaml..** 1447. 220: Processing input file / / etc/netplan/50-cloud-init.yaml..** (generate:1556): DEBUG: 09. 14 47. 221: starting new processing pass** (generate:1556): DEBUG: 09. 14. 47. 221: enp0s8: setting default backend to 1 instrument * (generate:1556): DEBUG: 0 9 charge 1447. 222: enp0s3: setting default backend to 1 seam * (generate:1556) : DEBUG: 09 definition enp0s8 is not for us 14 DEBUG 47.22 22: Generating output files..** (generate:1556): DEBUG: 09 14 backend 47.223: NetworkManager: definition enp0s8 is not for us (backend 1) * * (generate:1556): DEBUG: 09 DEBUG 14 14 backend 47.223: NetworkManager: definition enp0s3 is not for us (backend 1) DEBUG:netplan generated networkd configuration exists Restarting networkdDEBUG:no netplan generated NM configuration existsDEBUG:device enp0s3 operstate is up, not repluggingDEBUG:netplan triggering .link rules for enp0s3DEBUG:device lo operstate is unknown, not repluggingDEBUG:netplan triggering .link rules for loDEBUG:device enp0s8 operstate is up, not repluggingDEBUG:netplan triggering .link rules for enp0s8

If the configuration is normal and works, we can check the ip with the following command:

$ip addr

The output of executing the command after configuration in my Ubuntu 18.04 is as follows:

So far, we have successfully configured the static IP 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 addresses in Ubuntu 18.04 LTS

In fact, the initial configuration in the configuration file is the configuration of dynamic IP, so you don't have 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 above static IP configuration and restore the entire configuration file to the one shown in figure 1 above.

The above is all the contents of the article "how to configure IP addresses in Ubuntu18.04 LTS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report