How to set static IP on Ubuntu 18.04 Server

1. Background

Netplan is a new command line network configuration utility introduced in Ubuntu 17.10 for easy management and configuration of network settings in Ubuntu systems. It allows you to use YAML abstraction to configure network interfaces. It can be used as an interface to the kernel together with NetworkManager and systemd-networkd network daemons (called renderers, you can choose which one to use).

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 the Netplan utility to configure a network static or dynamic IP address for a network interface in Ubuntu 18.04.

Two, the solution

List all active network interfaces 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.

Ubuntu set static IP 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: If the YAML file was not created by the release installer, 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 under /etc/netplan/*.yaml All the files 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 attribute of the IPV4 interface
•Dhcp6: receive the dhcp attributes of the IPV6 interface
• addresses: static address sequence of the interface
•Gateway4: IPV4 address of the default gateway
•Nameservers: DNS server addresses, 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 all the available network interfaces again, the ens33 Ethernet interface should now be connected to the local network and have an IP address as shown in the screenshot below.

ifconfig -a

Verify network interface in Ubuntu

Ubuntu set dynamic IP address

To configure the ens33 Ethernet interface to dynamically receive an IP address via DHCP, you only need to use the 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 an IP address from the router.

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 Ubuntu server.

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, and the editor will reply to you in time. Thank you very much for your support to the 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 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 Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx 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
How to secure Nginx on Ubuntu 14.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04