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