Learn how to configure and assign a subnet to your Ubuntu server using "netplan".
Key points to consider
- Ubuntu uses "netplan" to configure network interfaces across all modern versions.
- Ensure you have root or sudo privileges before making changes to network configurations.
- A wrong configuration can result in losing remote access to the server. Always keep a backup of the original configuration file.
- After applying changes, the network service will restart, which may temporarily disconnect active connections.
Step-by-Step Instructions
Step 1: Access the Client Portal
- Log in to your client portal.
- Click on the "Network" button at the top of the menu bar (see Fig. 1).
Fig. 1. Access the ”Network” section in the client portal.
Step 2: Verify your subnet allocation and assign IP addresses
- In the "Network" section of the client portal, click on the "Subnets" button to view all available subnets (see Fig. 2).
Fig. 2. Access the subnets section. - You will now see a list of all available subnets. Locate the subnet you wish to configure.
- To assign individual IP addresses from the subnet, click on the subnet in the list. This will display all available IP addresses within that subnet (see Fig. 3).
Fig. 3. Viewing available public IP subnet list in the client portal. - Once you've identified the IP address you want to assign to your server, click the "Attach +" button next to that IP address. This action lets you associate the selected IP address with your server (see fig. 4).
Fig. 4. Verify and attach an IP address from the subnet in the client portal.
Step 3: Configure the subnet on the Ubuntu server
- Access the server via SSH:
- If you haven't already connected to your server, follow the tutorial on how to connect to a Linux server using SSH.
- Edit the "netplan" configuration:
- Open the "netplan" configuration file using the following command:
$ sudo nano /etc/netplan/50-cloud-init.yaml
- Update the configuration to include your subnet IPs as shown below (see Fig. 5):
Fig. 5. Editing the configuration file to add the IP addresses from the subnet. - Save the file and exit (
CTRL+X
, thenY
, andENTER
).
- Open the "netplan" configuration file using the following command:
- Apply the new configuration:
- Run the following command to apply the changes:
$ sudo netplan apply
- Run the following command to apply the changes:
- Verify the changes:
- Check if the new subnet has been successfully assigned by running (see Fig. 6):
$ ip a
Fig. 6. Output of ip a command showing the added subnet.
- Check if the new subnet has been successfully assigned by running (see Fig. 6):
- Test connectivity:
- Ping the new IP addresses from the subnet to test the connection:
$ ping -c 5 <new-ip-address>
Replace<new-ip-address>
with one of the IPs from the subnet. A successful response indicates that the IP addresses are correctly configured.
- Ping the new IP addresses from the subnet to test the connection:
Step 4: Ensure configuration persists through reboots
You must turn off Cloud-init's network configuration to ensure your changes stick after a reboot.
- Create the persistence configuration file and add the configuration:
$ echo "network: {config: disabled}" | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Summary
In this tutorial, you learned how to assign a subnet to your Ubuntu server by attaching the IP addresses in the Cherry Servers Client Portal, configuring them in the netplan file, applying the changes, and disabling "Cloud-init" to ensure they remain after a reboot. These steps help you set up and manage your server's subnet efficiently.