Introduction:
This guide is tailored to provide step-by-step instructions on IP Configuration for Ubuntu 22.04 LTS and Debian 12 using Netplan in use with BinaryLane's Virtual Private Servers. In this guide, you'll find instructionals on various aspects including how to statically configure the network on your server, adding additional IP addresses, and setting up your server for VPC connectivity.
Prerequisites:
- A BinaryLane Account
- A Virtual Private Server (VPS) running Ubtuntu 22.04 or Debian 12
- Access to the server you're configuring
- Knowledge of the IP Addresses you're intending to set up
- Familiarity with basic Linux command-line operations and usage
TABLE OF CONTENTS
- Enable/Disable DHCP
- Disable/Enable the cloud-init network configuration file
- Adding additional IP Addresses to an Ubtuntu server:
- Virtual IP Addressing (Load Balancers Only)
- Adding additional nameservers to an Ubtuntu Server
- Configuring Static IP Addresses
- Defining Custom Routing with Netplan
- Monitoring and Debugging Netplan Configurations
Enable/Disable DHCP:
DHCP (Dynamic Host Configuration Protocol) is essential for managing network configurations automatically. It simplifies the process of configuring IP addresses, subnet masks, gateways, and other network parameters. This is especially useful in large networks where manually configuring each machine would be time-consuming. All our Ubtuntu servers are pre-configured with DHCP enabled by default. Usually, you shouldn't need to disable this function.
There could be scenarios where you might want to disable DHCP, for instance:
- To assign static IP addresses for specific server roles.
- To reduce network traffic caused by DHCP discovery/offer/request/acknowledge packets, particularly in networks with a large number of transient clients.
- To have more control over network configurations.
Prerequisites:
- Ensure you have sudo or root privileges to the server.
- Access to a terminal or command line interface.
Important
Without disabling the cloud-init network config, the netplan configuration will revert upon restarting your server. To disable the network configuration file, create a new network-config disabling configuration in `/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg` with the following content:network: {config: disabled}
Locate Existing Configuration:
Firstly, find the existing netplan configuration files. They are generally located in `/etc/netplan/`. Use the following command to list all YAML configuration files:
ls /etc/netplan/
Backup Existing Configuration:
Before making changes, it's a good practice to backup the existing configuration file(s):
sudo cp /etc/netplan/*.yaml /etc/netplan/backup/
Create/Edit Netplan Configuration:
Edit (or create) the netplan configuration file using a text editor like nano. Replace the value `xx` with the actual values of your netplan configuration file:
sudo nano /etc/netplan/xx-netcfg.yaml
Configure DHCP:
To Enable DHCP:
For enabling DHCP on a specific interface, say `eth0`, your configuration should look like this:
. . . network: version: 2 ethernets: eth0: dhcp4: true . . .
To Disable DHCP:
For disabling DHCP and setting a static IP on `eth0`, your configuration should look like this:
. . . network: version: 2 ethernets: eth0: dhcp4: false addresses: - 192.168.1.10/24 gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8, 8.8.4.4] . . .
Replace `192.168.1.10` with the desired static IP address, `192.168.1.1` with your gateway, and `8.8.8.8, 8.8.4.4` with your DNS servers. For information on the BinaryLane name servers, see here: Nameservers | BinaryLane
Apply Configuration:
After saving the configuration file, apply the new settings with the following command:
sudo netplan apply
Verify Configuration:
Verify the new configuration with the following command:
ip addr show eth0
You should now see the updated IP configuration for `eth0`.
Disable/Enable the cloud-init network configuration file:
cloud-init is a key system initialiser for cloud instances and is automatically enabled for Virtual Private Servers on BinaryLane, automatically managing network configurations, particularly during events like server transitions into a VPC. This automation ensures a hassle-free and accurate network setup.
Some users might opt to disable cloud-init to gain manual control over network settings via netplan, which might be preferred in scenarios requiring custom configurations. We advise keeping cloud-init enabled unless you have a strong grasp of network management, as disabling it could lead to potential misconfigurations and increased management overhead.
Prerequisites:
- Ensure you have sudo or root privileges to the server.
- Access to a terminal or command line interface.
Locate cloud-init Network Configuration:
Check if cloud-init's network configuration is active by listing the contents of the cloud.cfg.d directory:
ls /etc/cloud/cloud.cfg.d/
Backup Existing Configuration:
Before making any changes, it's prudent to backup the existing configuration files:
sudo cp -r /etc/cloud/cloud.cfg.d/ /etc/cloud/cloud.cfg.d.backup/
Create/Edit cloud-init Disabling Configuration:
To disable cloud-init's network configuration:
Create a configuration file named `99-disable-network-config.cfg` in the `/etc/cloud/cloud.cfg.d/` directory with the following content:
echo "network: {config: disabled}" | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
To enable cloud-init's network configuration:
If you need to re-enable cloud-init's network configuration, simply remove the `99-disable-network-config.cfg` file:
sudo rm /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Apply Configuration:
The changes will take effect upon the next boot. Reboot your server:
sudo reboot
Verify Configuration:
After rebooting, verify that cloud-init's network configuration is disabled (or enabled) by checking the cloud-init output:
sudo cat /var/log/cloud-init.log | grep -i network
Look for lines indicating that network configuration is disabled.
Adding additional IP Addresses:
Additional IP addresses can be useful in various scenarios, such as hosting multiple websites on a single server, separating network traffic, or ensuring redundancy. They can be assigned to the same network interface or to virtual interfaces, depending on your network setup and requirements.
Prerequisites:
- Ensure you have sudo or root privileges to the server.
- Access to a terminal or command line interface.
Important
Without disabling the cloud-init network config, the netplan configuration will revert upon restarting your server. To disable the network configuration file, create a new network-config disabling configuration in `/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg` with the following content:network: {config: disabled}
1. Adding Additional IPs with the same gateway address:
This method is straightforward and involves adding extra IP addresses directly to the primary network interface. This method is easy to configure and manage. Please note: if your additional IP address does not use the same gateway address as your Primary IP address, you would need to use `routes` instead of `gateway4`: Jump to ☛ Routes
List Current Netplan Configuration Files:
Locate the existing netplan configuration files to know which file to edit:
sudo ls /etc/netplan
Backup Existing Configuration:
It's a good practice to back up the current configuration before making changes:
sudo cp /etc/netplan/*.yaml /etc/netplan/backup/
Edit Netplan Configuration:
Edit the netplan configuration file using a text editor like nano. Replace the value `xx` with the actual values of your netplan configuration file:
sudo nano /etc/netplan/xx-netcfg.yaml
Update Configuration:
Add the additional IP addresses to the same network interface in the configuration file:
. . . eth0: addresses: - 110.233.116.189/24 # Primary IP (Public/Primary IP Addr.) - 119.216.36.3/24 # Additional IP(s) - 104.34.1... # ... - ... gateway4: 110.233.116.1 # Gateway for your Public/Primary IP Addr. . . .
Apply Configuration:
Apply the new configuration to make the changes effective:
sudo netplan apply
2. Adding Additional IPs using Individual (Virtual) Interfaces:
Virtual interfaces allow you to assign multiple IP addresses to a single physical interface. Each virtual interface appears as a unique interface with its own IP addresses, subnets, and routes, offering a more organised or granular control over the network configurations.
List Current Netplan Configuration Files:
Locate the existing netplan configuration files to know which file to edit:
sudo ls /etc/netplan
Backup Existing Configuration:
It's a good practice to back up the current configuration before making changes:
sudo cp /etc/netplan/*.yaml /etc/netplan/backup/
Edit Netplan Configuration:
Edit the netplan configuration file using a text editor like nano. Replace the value `xx` with the actual values of your netplan configuration file:
sudo nano /etc/netplan/xx-netcfg.yaml
Update Configuration:
Create virtual interfaces for each additional IP in the configuration file:
. . . eth0: addresses: - 110.232.112.180/24 # Primary IP (Public/Primary IP Addr.) gateway4: 110.232.112.1 # Gateway for your Public/Primary IP Addr. eth0:1: addresses: - 112.213.36.2/24 # Additional IP(s) eth0:2: addresses: - 104.34.1.../24 # ... . . .
Apply Configuration:
Apply the new configuration to make the changes effective:
sudo netplan apply
3. Verifying the Additional IP Addresses:
After configuring the additional IP addresses, it's essential to verify that they are active and reachable. A simple way to do this is by using the `ping` command to check for a response from the newly configured IP addresses. Alternatively, you can listen for traffic on your VPS from that IP address.
Virtual IP Addressing (Load Balancers Only):
A Load Balancer efficiently distributes network traffic across multiple servers to ensure no single server becomes overwhelmed with too much traffic. This is crucial for maintaining fast, reliable, and robust service delivery. Virtual IP Addresses (VIPs) are central to this as they act as a single entry point to the cluster of servers. When a client sends a request, the VIP decides which server in the cluster will handle the request based on the load balancing algorithm.
For a general guide on how to set up an Anycast Load Balancer on Ubuntu 22.04 LTS using Apache, please review the helpdesk article we have on the matter here: Setting Up An Anycast Load Balancer on Ubuntu 22.04 LTS using Apache | BinaryLane
Prerequisites:
- Ensure you have sudo or root privileges to the server.
Access to a terminal or command line interface
A BinaryLane Load Balancer Plan: Add Load Balancer | BinaryLane Australia
Important
Without disabling the cloud-init network config, the netplan configuration will revert upon restarting your server. To disable the network configuration file, create a new network-config disabling configuration in `/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg` with the following content:network: {config: disabled}
Locate Existing Configuration:
Firstly, find the existing netplan configuration files. They are generally located in `/etc/netplan/`. Use the following command to list all YAML configuration files:
ls /etc/netplan/
Backup Existing Configuration:
Before making changes, it's a good practice to backup the existing configuration file(s):
sudo cp /etc/netplan/*.yaml /etc/netplan/backup/
Edit Netplan Configuration:
Edit the netplan configuration file using a text editor like nano. Replace the value `xx` with the actual values of your netplan configuration file:
sudo nano /etc/netplan/xx-netcfg.yaml
Update Netplan Configuration:
Update the file with the following configuration changes, replacing IP addresses and other values with your own:
. . . eth0: addresses: - 112.213.38.164/24 # Primary IP (Public/Primary IP Addr.) - 103.17.56.142/32 # Virtual IP (Anycast IP of your Load Balancer) - 172.22.27.250/16 # LAN IP gateway4: 112.213.38.1 # Gateway for your Public/Primary IP Addr. . . .
Appy Configuration:
Apply the new network configurations. This will activate the virtual IP on your machine along with any other changes made:
sudo netplan apply
Verification:
It’s crucial to ensure that the new configuration works as expected. One method to verify the setup is by listening for traffic on your web server while browsing your newly configured site. This can help confirm that the Virtual IP and Load Balancer are functioning correctly. You can do this by listening for traffic on a specific IP Address using tcpdump:
sudo tcpdump -i eth0 -n host 103.17.56.x
Replace `103.17.56.142` with your Virtual IP address, and `eth0` with your network interface. This command will capture and display the network traffic to and from your Virtual IP. Now, from a different machine, browse to your site using the Virtual IP, and observe the traffic on your server console.
Adding additional nameservers to an Ubtuntu Server:
Nameservers translate domain names into IP addresses. Having multiple nameservers ensures that your server can resolve domain names even if one nameserver is unavailable. This is crucial for maintaining reliable network communication.
The nameservers provided by BinaryLane are as follows:
- ns1.binarylane.com.au
- ns2.binarylane.com.au
- ns3.binarylane.com.au
For more information or to manage your DNS settings through BinaryLane, kindly review this link: Nameservers | Binarylane
Prerequisites:
- Ensure you have sudo or root privileges to the server.
- Access to a terminal or command line interface.
Important
Without disabling the cloud-init network config, the netplan configuration will revert upon restarting your server. To disable the network configuration file, create a new network-config disabling configuration in `/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg` with the following content:network: {config: disabled}
Locate Existing Configuration:
Firstly, find the existing netplan configuration files. They are generally located in `/etc/netplan/`. Use the following command to list all YAML configuration files:
ls /etc/netplan/
Backup Existing Configuration:
Before making changes, it's a good practice to backup the existing configuration file(s):
sudo cp /etc/netplan/*.yaml /etc/netplan/backup/
Edit Netplan Configuration:
Edit the netplan configuration file using a text editor like nano. Replace the value `xx` with the actual values of your netplan configuration file:
sudo nano /etc/netplan/xx-netcfg.yaml
Update Netplan Configuration
Update the file with the following configuration changes, replacing the nameserver addresses with your own:
. . . network: version: 2 ethernets: eth0: nameservers: addresses: [8.8.8.8, 8.8.4.4, 1.1.1.1] # Add desired nameservers here . . .
Apply Configuration
Apply the new network configurations to activate the additional nameservers on your VPS:
sudo netplan apply
Verify Configuration
Verify the new nameserver configuration by checking the resolv.conf file or using a `dig` command to resolve a domain name:
cat /etc/resolv.conf
or
dig example.com
The `dig` command should use the newly added nameservers to resolve the domain name, and the `cat` command should display the updated nameservers.
Configuring Static IP Addresses:
Static IP addresses are crucial for services that require a consistent address to be accessible, such as web servers or databases. Unlike dynamic IP addresses, which can change over time, static IPs remain constant, ensuring reliable connections to your services.
Prerequisites:
- Ensure you have sudo or root privileges to the server.
- Access to a terminal or command line interface.
- DHCP has been disabled
Important
Without disabling the cloud-init network config, the netplan configuration will revert upon restarting your server. To disable the network configuration file, create a new network-config disabling configuration in `/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg` with the following content:network: {config: disabled}
Locate Existing Configuration:
Firstly, find the existing netplan configuration files. They are generally located in `/etc/netplan/`. Use the following command to list all YAML configuration files:
ls /etc/netplan/
Backup Existing Configuration:
Before making changes, it's a good practice to backup the existing configuration file(s):
sudo cp /etc/netplan/*.yaml /etc/netplan/backup/
Edit Netplan Configuration:
Edit the netplan configuration file using a text editor like nano. Replace the value `xx` with the actual values of your netplan configuration file:
sudo nano /etc/netplan/xx-netcfg.yaml
Update Netplan Configuration
Update the file with the following configuration changes, replacing the nameserver addresses with your own:
. . . network: version: 2 ethernets: eth0: dhcp4: false addresses: - 192.168.1.10/24 gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8, 8.8.4.4] . . .
Apply Configuration
Apply the new network configurations to activate the static IP address on your server:
sudo netplan apply
Verify Configuration
Verify the new static IP configuration by checking the active network interfaces:
ip addr show eth0
You should now see the updated IP configuration for eth0, reflecting the static IP address you configured.
Defining Custom Routing with Netplan:
Custom routing is essential for directing network traffic along specified paths, which is crucial in complex network setups or for optimising traffic flow. It also enables you to logically segment IP traffic on the same NIC with different gateway addresses.
Prerequisites:
- Ensure you have sudo or root privileges to the server.
- Access to a terminal or command line interface.
Important
Without disabling the cloud-init network config, the netplan configuration will revert upon restarting your server. To disable the network configuration file, create a new network-config disabling configuration in `/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg` with the following content:network: {config: disabled}
Locate Existing Configuration:
Firstly, find the existing netplan configuration files. They are generally located in `/etc/netplan/`. Use the following command to list all YAML configuration files:
ls /etc/netplan/
Backup Existing Configuration:
Before making changes, it's a good practice to backup the existing configuration file(s):
sudo cp /etc/netplan/*.yaml /etc/netplan/backup/
Edit Netplan Configuration:
Edit the netplan configuration file using a text editor like nano. Replace the value `xx` with the actual values of your netplan configuration file:
sudo nano /etc/netplan/xx-netcfg.yaml
Update Netplan Configuration
Update the file with the following configuration changes, replacing the routes with your own:
. . . network: version: 2 ethernets: eth0: addresses: - 192.168.1.10/24 routes: - to: 192.168.2.0/24 via: 192.168.1.1 - to: 192.168.3.0/24 via: 192.168.1.1 . . .
For additional IP addresses, it would look something like this:
. . . addresses: - 175.45.181.125/24 <-- Primary IP address and netmask - 112.213.37.71/24 <-- Secondary IP address and netmask nameservers: addresses: - 8.8.8.8 - 8.8.4.4 routes: - to: 0.0.0.0/0 via: 175.45.181.1 <-- Gateway for primary IP metric: 100 <-- Priority of this route (Lower metric means higher priority) - to: 0.0.0.0/0 via: 112.213.37.1 <-- Gateway for secondary IP metric: 200 . . .
Note: You don't need to apply route priority preferences using `metric`, but it is possible to use this as a gateway fallback.
Apply Configuration
Apply the new network configurations to activate the custom routing on your server:
sudo netplan apply
Verify Configuration
Verify the new routing configuration by checking the routing table:
ip route
You should now see the updated routing table reflecting the custom routes you configured.
Monitoring and Debugging Netplan Configurations:
Netplan configurations are crucial for ensuring smooth network operations on your server. However, errors or misconfigurations can occur. This section provides steps to monitor and debug your Netplan configurations effectively. It's advisable to follow these steps methodically to identify and resolve potential issues.
Prerequisites:
- Ensure you have sudo or root privileges to the server.
- Access to a terminal or command line interface.
Enable DHCP and Review Configuration:
Enabling DHCP and reviewing the active configuration is a beneficial starting point. It aids in comprehending the existing network setup before initiating any modifications. Post applying your Netplan with DHCP enabled, reviewing the configuration can provide insights for setting up your Netplan file appropriately.
Review your VPS Firewall Settings:
Ensure there are no firewall rules on your VPS obstructing connectivity to your server. If there's an internal (software) firewall in place, verify it's not interfering with your connectivity.
Ensure Network-Config Disabling Configuration File Exists:
Confirm the creation of the network-config disabling configuration file to avert reversion of the Netplan configuration upon server restart:
cat /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Apply and Review Configurations:
Execute the configurations and review them to ascertain they have been applied correctly:
sudo netplan apply ip addr show
Refer to official documentation for further guidance and support:
For further guidance and support, you may refer to the official Ubuntu documentation on Configuring networks: Configuring networks | Ubuntu or the Debian documentation on Network Setup: Chapter 5. Network setup (debian.org)
If you require assistance, feel free to submit a support ticket at our helpdesk here: Submit a ticket | BinaryLane