Configuring Static IPv4 Address using Netplan on Ubuntu 20.04
This guide is applicable only for KVM based VPSes, for OpenVZ based VPSes please click here.
From Ubuntu 18.04, a switch was made to configure network using NetPlan written in YAML. In this article, we will learn how to configure networking in newer versions of Ubuntu, such as Ubuntu 20.04 and up using Netplan.
To Find The Network Gateway and Netmask
To find out the IPv4 Address assigned to you, login to CrownPanel and navigate to Manage Network tab.
Configuring IPv4
First, we will find the Network interface name,
ip a
Example output:
root@vps:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 54:52:00:c5:68:33 brd ff:ff:ff:ff:ff:ff
inet 104.194.222.205/24 brd 104.194.222.255 scope global dynamic ens3
valid_lft 21599821sec preferred_lft 21599821sec
inet6 fe80::5652:ff:fec5:6833/64 scope link
valid_lft forever preferred_lft forever
Note
In this example, the system is configured with the network interface name as
ens3
, this might not be the case with your system, please verify the system network interface name with theip a
command as shown above before proceeding with the guide below!
We will see how we can configure the IPv4,
A side note on this, YAML is strict on indentation so we will use 2 spaces through out the guide.
vi /etc/netplan/00-installer-config.yaml
Initially, the network is configured to DHCP.
network:
ethernets:
ens3:
dhcp4: true
version: 2
We will make it Static by changing it to
network:
ethernets:
ens3:
dhcp4: false
addresses:
- 104.194.222.205/24
routes:
- to: default
via: 104.194.222.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
version: 2
Replace the IPv4 address 104.194.222.205/24
with the actual IPv4 that is allocated to your Server.
Along with Gateway IP 104.194.222.1
with the appropriate Gateway displayed in Manage Network tab in CrownPanel.
To learn more about routes, click on the following link: netplan.io.
For nameservers, we are using google's public DNS.
8.8.8.8
8.8.4.4
You can also try CloudFlare's public DNS as well.
1.1.1.1
After exiting the configuration, run the following command to apply the changes.
netplan apply
This should effectively configure the IPv4 from DHCP to Static and to test if the network is still up.
root@vps:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=57 time=0.515 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=57 time=0.537 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=57 time=0.522 ms
This concludes our topic of configuring static IPv4 on Ubuntu systems.
If you can not configure and facing technical difficulties, kindly reach out to us via Support Ticket.
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS