Ubuntu 20.04 sets a static IP address (including different versions)

Ubuntu 20.04 sets a static IP address (including different versions)

Because Ubuntu 20.04 manages the network through netplan, which is slightly different from previous versions, Ubuntu 18.04 seems to need to edit /network/interfaces to set up a static network

Because it is a virtual machine, I first change it to bridge mode



Next edit the file:

sudo vim /etc/netplan/01-network-manager-all.yaml

Modify the file content to:

I have always wondered whether I need to make modifications for different IP addresses?

But since I haven't reached that level yet, I'm not very clear about it. It should be modifiable.

But there is no problem typing the following code directly into the file

Enter: wq to save and exit, then enter

sudo netplan --debug apply

You can


Now the static IP is set up, and you can view the current IP address through ifconfig.

12.x Version

$ cat /etc/network/interfaces
 auto lo
 iface lo inet loopback
 
 auto eth0
 iface eth0 inet static
 address 20.20.20.102
 netmask 255.255.255.0
 gateway 20.20.20.102
 dns-nameservers 20.20.20.2

14.x Version

$ cat /etc/network/interfaces
 auto lo
 iface lo inet loopback
 
 auto eth0
 iface eth0 inet static
 address 20.20.20.102
 netmask 255.255.255.0
 gateway 20.20.20.102
 dns-nameservers 20.20.20.2
 
$ cat /etc/NetworkManager/NetworkManager.conf
 [main]
 plugins=ifupdown,keyfile,ofono
 dns=dnsmasq
 
 no-auto-default=00:0C:29:D7:43:29,
 
 [ifupdown]
 managed=true

16.x version

$ cat /etc/network/interfaces
 auto lo
 iface lo inet loopback
 
 auto ens32
 iface ens32 inet static
 address 20.20.20.102
 netmask 255.255.255.0
 gateway 20.20.20.102
 
$ cat /etc/NetworkManager/NetworkManager.conf
 [main]
 plugins=ifupdown,keyfile,ofono
 dns=dnsmasq
 
 no-auto-default=00:0C:29:D7:43:29,
 
 [ifupdown]
 managed=true
 
$ cat /etc/resolv.conf
 nameserver 127.0.1.1
 nameserver 20.20.20.2

18.x version:

1. First check the network card name

$ ip a /ifconfig

2. cp a yaml file and change its name

$ sudo cp /etc/netplan/*.yaml /etc/netplan/network card name.yaml

3. Modify the contents of the yaml file as follows:

# Let NetworkManager manage all devices on this system
network:
 version: 2
 renderer: NetworkManager
 ethernets:
 Network card name:
  dhcp4: no
  addresses: [ip/prefix]
  gateway4: gateway
  nameservers:
  addresses: [dns]

4. Start

$ sudo netplan apply

5. Verification

$ ip a /ifconfig

This is the end of this article about setting a static IP address for Ubuntu 20.04 (including different versions). For more information about setting a static IP address for Ubuntu 20.04, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to set static IP for Ubuntu 18.04 Server
  • How to set static IP address in Ubuntu 14.04 under VMware
  • Detailed explanation of how to set static IP in Ubuntu 14.04
  • Ubuntu16.04 static IP address setting (NAT method)
  • How to set static IP in ubuntu

<<:  Introduction to MySql table, database, sharding and partitioning knowledge points

>>:  MySQL DML language operation example

Recommend

The main idea of ​​​​dynamically setting routing permissions in Vue

I have seen some dynamic routing settings on the ...

Simple usage examples of MySQL custom functions

This article uses examples to illustrate the usag...

Solve the problem of forgetting password in MySQL 5.7 under Linux

1. Problem Forgot password for mysql5.7 under lin...

Summary of using MySQL online DDL gh-ost

background: As a DBA, most of the DDL changes of ...

How to use negative margin technology to achieve average layout in CSS

We usually use float layout to solve the compatib...

CSS3 animation to achieve the effect of streamer button

In the process of learning CSS3, I found that man...

MySQL 5.7.19 (tar.gz) installation graphic tutorial under Linux

The first tutorial for installing MySQL-5.7.19 ve...

JavaScript to achieve a simple page countdown

This article example shares the specific code of ...

Basic knowledge of HTML: a preliminary understanding of web pages

HTML is the abbreviation of Hypertext Markup Langu...

How to create a Pod in Kubernetes

Table of contents How to create a Pod? kubectl to...

HTML multimedia application: inserting flash animation and music into web pages

1. Application of multimedia in HTML_falsh animat...