How to set static IP on Ubuntu 18.04 Server

1. Background

Netplan is a new command line network configuration utility program introduced in Ubuntu 17.10, used to easily manage and configure network settings in the Ubuntu system. It allows you to use YAML abstraction to configure network interfaces. It can be used with NetworkManager and systemd-networkd network daemon [program] (https://www.zalou.cn/tag/chengxu) (called rendering [program] (https://www.zalou.cn/tag/chengxu), you can choose which one to use) as the kernel interface.

It reads the network configuration described in /etc/netplan/*.ymal, and can store the configuration of all network interfaces in these files.

? in the text. We will explain how to use Netplan utility program to configure network static or dynamic IP address for network interface in Ubuntu 18.04.

Two, the solution

**List all **ActivitiesNetwork Interface on Ubuntu

First, you need to determine the network interface to be configured. You can use the ifconfig command to list all connected network interfaces in the system, as shown in the figure.

ifconfig -a

**Check the network interface in Ubuntu

? From the output of the above command, we have 2 interfaces connected to the Ubuntu system: 1 Ethernet interface and loopback interface.

UbuntuSet staticIP address

In this example, we configure a static IP for the ens33 Ethernet network interface. As shown in the figure, use vim to open the netplain configuration file.

Important note: If the YAML file was not created by the distribution installation program, you can use this command to generate the required configuration for the renderer.

sudo netplan generate

In addition, the automatically generated files may have different file names on the desktop, server, cloud instance, etc. (such as 01-network-manager-all.ymal or 01-netcfg.yaml), but /etc/netplan All files under /*.yaml will be read by netplan.

sudo vim /etc/netplan/xxxx.ymal

Then add the following configuration in the ethernet section.

network:
 ethernets:
 ens33:
  addresses:-192.168.4.254/24
  dhcp4:false
  gateway4:192.168.4.2
  nameservers:
  addresses:-8.8.8.8
  search:[]
 version:2

Description:

? ens33: network interface name
? dhcp4: receive the dhcp attributes of the IPV4 interface
? dhcp6: Receive the dhcp attributes of the IPV6 interface
? addresses: static address sequence of the interface
? gateway4: [default gateway] (https://www.zalou.cn/tag/morenwangguan) IPV4 address
? Nameservers:DNSserver address, separated by,

After the addition is complete, your configuration file should have the following content, as shown in the screenshot below.

? The address attribute of the interface is expected to have a sequence entry, such as [192.168.4.254/24, "20001: 1 :: 1/64"] or [192.168.1.254/24,] (for more information, please refer to the netplan man page) .

**Configure static IP in Ubuntu

Save the file and exit. Then use the following netplan command to apply the most recent network changes.

sudo netplan apply

Now verify again all available network interfaces, the ens33 Ethernet interface should now be connected to the local network and have IP address as shown in the following screenshot.

ifconfig -a

**Verify the network interface in Ubuntu

UbuntuSetting dynamicIP address

To configure the ens33 Ethernet interface to dynamically receive IP address via DHCP, you only need to use one configuration.

network:
 ethernets:
 ens33:
  dhcp6:true
  dhcp4:true
 version:2

Save the file and exit. Then use the following netplan command to apply the most recent network changes.

sudo netplan apply
ifconfig -a

From now on, your system will dynamically obtain [IP address] (https://www.zalou.cn/tag/ipdizhi) from [router] (https://www.zalou.cn/tag/luyouqi).

You can find more information and configuration options by looking at the netplan man page.

man netplan

At this time, you have successfully configured the network static IP address to your Ubuntuserver.

to sum up

The above is the method of setting static IP for Ubuntu 18.04 Server introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time. Thank you very much for your support to website matter (zalou.cn)website!

Recommended Posts

How to set static IP on Ubuntu 18.04 Server
How to set static IP on Ubuntu 18.04 Server
Explain how to set static IP on ubuntu14.04
How to set static IP in ubuntu14.04
How to set up Shiny Server on Ubuntu 14.04
How to set up a DNS server on Ubuntu 18.04
How to set a fixed IP based on Ubuntu 16.04
How to set up Gogs on Ubuntu 14.04
How to install Bacula Server on Ubuntu 14.04
How to use Samba server on Ubuntu 16.04
How to set up R on Ubuntu 14.04
How to set PostgreSQL startup on Ubuntu 16.04
ubuntu16.04 set static ip
How to install Zabbix on Ubuntu 16.04 Server
How to install Squid proxy server on Ubuntu 18.04
How to quickly deploy docker on ubuntu server
How to set up time synchronization on Ubuntu 18.04
How to run the parsing server on Ubuntu 14.04
ubuntu 18.04 set static ip method
How to configure a fixed IP based on Ubuntu 18.04
How to open https on nginx server under Ubuntu
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
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04