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

How to run Hadoop and create images in Docker

Reinventing the wheel, here we use repackaging to...

MySQL extracts Json internal fields and dumps them as numbers

Table of contents background Problem Analysis 1. ...

The reason why MySQL uses B+ tree as its underlying data structure

We all know that the underlying data structure of...

Detailed explanation of the solution to font blur when using transform in CSS3

This question is very strange, so I will go strai...

Detailed tutorial on installing mysql-8.0.20 under Linux

** Install mysql-8.0.20 under Linux ** Environmen...

Vue implements the countdown component for second kills

This article shares the specific code of Vue to i...

Implementation example of react project from new creation to deployment

Start a new project This article mainly records t...

Pure CSS to achieve cool neon light effect (with demo)

I have recently been following the CSS Animation ...

7 skills that great graphic designers need to master

1》Be good at web design 2》Know how to design web p...

Play mp3 or flash player code on the web page

Copy code The code is as follows: <object id=&...

How to add a disk in Vmware: Expand the disk

This article describes how to add or expand a dis...

Detailed explanation of the use of filter properties in CSS3

Recently, when I was modifying the intranet porta...

Summary of xhtml block level tags

* address - address * blockquote - block quote * c...

How to run Python script on Docker

First create a specific project directory for you...