Managing Network Configurations in Ubuntu with Netplan
Netplan has simplified network configuration management in Ubuntu. This tutorial will guide you through setting up multiple IP addresses on a single network interface using Netplan.
Prerequisites
- An Ubuntu 24.04 system with Netplan installed (default in Ubuntu installations).
- Administrative (root) privileges or sudo access.
- A network interface name (e.g., ens192).
Step-by-Step Configuration
1. Edit the Netplan Configuration File
Create or modify a Netplan configuration file, typically located in `/etc/netplan/`. Here, we’ll use `00-Public_network.yaml`.
Run:
sudo nano /etc/netplan/00-Public_network.yaml
Add the following configuration:
network:
version: 2
renderer: networkd
ethernets:
ens192:
addresses:
- 77.68.48.229/32
- 77.68.13.96/32
- 77.68.115.25/32
nameservers:
addresses: [212.227.123.16, 212.227.123.17]
routes:
- to: default
via: 10.255.255.1
on-link: true
2. Apply the Configuration
After saving the file, apply the changes using the following command:
sudo netplan --debug apply
The `–debug` flag provides detailed logs for troubleshooting.
3. Verify the Configuration
Check the IP addresses and routing table to ensure the configuration is applied correctly.
Verify IP addresses:
ip a
Expected output:
inet 77.68.48.229/32 scope global ens192
inet 77.68.13.96/32 scope global ens192
inet 77.68.115.25/32 scope global ens192
Verify routing table:
ip route show
Expected output:
default via 10.255.255.1 dev ens192 proto static onlink
Understanding Key Network Configuration Components
Nameservers
These are DNS (Domain Name System) servers responsible for translating domain names (e.g., example.com) into IP addresses.
In the configuration:
nameservers:
addresses: [212.227.123.16, 212.227.123.17]
These are the DNS servers provided by your hosting provider.
If the provider does not specify DNS servers, you can use public options such as:
- Google: 8.8.8.8, 8.8.4.4
- Cloudflare: 1.1.1.1, 1.0.0.1
- OpenDNS: 208.67.222.222, 208.67.220.220
Default Gateway
The default gateway routes traffic from your system to other networks, such as the internet.
In the configuration:
routes:
- to: default
via: 10.255.255.1
on-link: true
`via 10.255.255.1`: The gateway IP provided by the server/hosting provider.
`on-link: true`: Indicates the gateway is directly reachable on the local link.
Always use the gateway provided by your hosting provider.
Troubleshooting
If changes are not applied, check the configuration syntax:
sudo netplan generate
Look for error messages in `/var/log/syslog` for additional details.
Conclusion
Using Netplan, you can easily assign multiple IP addresses to a single network interface in Ubuntu 24.04. This setup is ideal for scenarios like hosting multiple websites or services requiring distinct public IPs. Ensure you use the nameservers and default gateway provided by your hosting provider for proper network connectivity. Public DNS servers can be used as an alternative if needed.
Leave a Reply