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