Floating IP addresses provide high availability and seamless failover capabilities for Linux servers. This comprehensive guide demonstrates how to configure floating IPs on Ubuntu and Debian systems using Netplan, enabling automatic IP migration between servers for improved reliability and redundancy.
Prerequisites for Floating IP Configuration
Before configuring floating IPs on your Ubuntu or Debian server, ensure you have the following requirements for successful implementation:
- Ubuntu 18.04+ or Debian 9+: Modern distributions with Netplan support
- Root or Sudo Access: Administrative privileges for network configuration
- Available Floating IP: A secondary IP address allocated by your hosting provider
- Network Interface Access: Understanding of your server’s network interface names
- Backup Configuration: Always backup existing network configs before changes
⚠️ Important Network Safety Notice
Always backup your network configuration before making changes. Incorrect network settings can disconnect you from your server, requiring console access to fix.
Best Practice: Test configurations in a development environment first, and ensure you have console access to your server before applying network changes.
Understanding Floating IPs and Netplan
Floating IPs are virtual IP addresses that can be moved between servers without changing DNS records or requiring manual reconfiguration. Netplan is Ubuntu’s network configuration tool that uses YAML files to define network settings.
What Are Floating IPs?
- High Availability: Enable automatic failover between servers
- Load Balancing: Distribute traffic across multiple instances
- Zero Downtime: Switch services without DNS propagation delays
- Disaster Recovery: Quick recovery from server failures
Netplan Configuration Benefits
- Declarative Configuration: YAML-based, human-readable format
- Backend Agnostic: Works with NetworkManager and systemd-networkd
- Validation: Built-in configuration validation before applying
- Consistent: Standardized across Ubuntu distributions
Step-by-Step Floating IP Configuration
Follow this comprehensive guide to configure floating IPs using Netplan on Ubuntu and Debian systems. Each step includes validation commands to ensure proper setup.
Step 1: Identify Your Network Interface
First, identify your primary network interface name and current IP configuration.
# List all network interfaces
ip addr show
# Check current network configuration
ip route show
# View existing Netplan configuration
ls -la /etc/netplan/
cat /etc/netplan/*.yaml
Step 2: Create Floating IP Netplan Configuration
Create a new Netplan configuration file specifically for your floating IP address. This keeps the configuration organized and easily manageable.
# Create a new Netplan configuration file
sudo nano /etc/netplan/01-floating.yaml
Add the following configuration to the file:
network:
version: 2
ethernets:
eth0: # Replace with your actual interface name
dhcp4: true # Keep main IP from DHCP
addresses:
- 10.0.0.8/32 # Your floating IP address
routes:
- to: 10.0.0.8/32
via: 0.0.0.0
scope: link
💡 Netplan Configuration Best Practices
Important configuration notes:
- Interface Names: Use
ip addr
to find your actual interface name (eth0, ens3, etc.) - CIDR Notation: Use /32 for single floating IP addresses
- DHCP Preservation: Keep dhcp4: true to maintain your primary IP
- File Naming: Use numeric prefixes (01-, 02-) to control application order
Step 3: Validate and Apply Netplan Configuration
Before applying the configuration, validate it to prevent network connectivity issues.
# Test the Netplan configuration
sudo netplan try
# If validation passes, apply the configuration
sudo netplan apply
# Verify the floating IP is configured
ip addr show eth0
ip route show
Step 4: Manual IP Configuration Method (Alternative)
For temporary or testing purposes, you can also configure floating IPs manually using ip commands.
# Add floating IP to interface
sudo ip addr add 5.161.24.41/32 dev eth0
# Add route for the floating IP
sudo ip route add 5.161.24.41/32 dev eth0
# Verify configuration
ip addr show eth0
ip route show | grep 5.161.24.41
⚠️ Manual Configuration Limitations
Manual configurations are not persistent. They will be lost after a system reboot. Use Netplan for permanent configuration.
Use Cases: Manual configuration is useful for testing, temporary setups, or emergency situations.
Step 5: Enable IP Forwarding (Optional)
If your server acts as a router or gateway, enable IP forwarding to allow traffic routing between interfaces.
# Enable IP forwarding temporarily
sudo sysctl net.ipv4.ip_forward=1
# Make IP forwarding permanent
echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf
# Apply sysctl changes
sudo sysctl -p
# Verify IP forwarding is enabled
cat /proc/sys/net/ipv4/ip_forward
Advanced Floating IP Configuration
Learn advanced techniques for managing multiple floating IPs and complex network setups.
Multiple Floating IPs Configuration
Configure multiple floating IP addresses on a single interface for high-availability setups.
# Advanced Netplan configuration with multiple floating IPs
network:
version: 2
ethernets:
eth0:
dhcp4: true
addresses:
- 10.0.0.8/32 # First floating IP
- 10.0.0.9/32 # Second floating IP
- 10.0.0.10/32 # Third floating IP
routes:
- to: 10.0.0.8/32
via: 0.0.0.0
scope: link
- to: 10.0.0.9/32
via: 0.0.0.0
scope: link
- to: 10.0.0.10/32
via: 0.0.0.0
scope: link
VLAN-Based Floating IP Configuration
Configure floating IPs on VLAN interfaces for network segmentation.
# VLAN configuration with floating IP
network:
version: 2
ethernets:
eth0:
dhcp4: true
vlans:
eth0.100:
id: 100
link: eth0
addresses:
- 192.168.100.10/24
- 192.168.100.50/32 # Floating IP on VLAN
Floating IP with Static Routes
Add custom routing rules for floating IP traffic management.
# Advanced routing configuration
network:
version: 2
ethernets:
eth0:
dhcp4: true
addresses:
- 10.0.0.8/32
routes:
- to: 10.0.0.8/32
via: 0.0.0.0
scope: link
- to: 10.0.0.0/24
via: 10.0.0.1
metric: 100
Troubleshooting Floating IP Issues
Comprehensive solutions for common problems encountered when configuring floating IPs.
Common Issues and Solutions
- Netplan Apply Fails: Check YAML syntax and indentation
- IP Not Accessible: Verify routing and firewall rules
- Configuration Lost After Reboot: Ensure Netplan files are properly saved
- Interface Not Found: Confirm correct interface name with
ip addr
- DHCP Conflicts: Check for IP address conflicts with DHCP range
Diagnostic Commands
# Check Netplan configuration syntax
sudo netplan --debug try
# View detailed network information
ip addr show
ip route show table all
# Test connectivity to floating IP
ping -I eth0 10.0.0.8
# Check ARP table
arp -a
# Monitor network traffic
sudo tcpdump -i eth0 host 10.0.0.8
# Check systemd-networkd status
sudo systemctl status systemd-networkd
# View network logs
journalctl -u systemd-networkd
Emergency Recovery Procedures
If network configuration causes connectivity issues, use these recovery methods:
# Reset to DHCP-only configuration
sudo rm /etc/netplan/01-floating.yaml
sudo netplan apply
# Manually restore network connectivity
sudo dhclient eth0
# Restart networking services
sudo systemctl restart systemd-networkd
sudo systemctl restart systemd-resolved
# Emergency network reset
sudo ip addr flush dev eth0
sudo dhclient eth0
Monitoring and Automation
Implement monitoring and automation for floating IP management in production environments.
Floating IP Health Check Script
#!/bin/bash
# floating-ip-monitor.sh
FLOATING_IP="10.0.0.8"
INTERFACE="eth0"
LOG_FILE="/var/log/floating-ip-monitor.log"
# Function to log messages
log_message() {
echo "$(date): $1" >> "$LOG_FILE"
}
# Check if floating IP is configured
if ip addr show "$INTERFACE" | grep -q "$FLOATING_IP"; then
log_message "Floating IP $FLOATING_IP is configured on $INTERFACE"
# Test connectivity
if ping -c 1 -W 5 "$FLOATING_IP" > /dev/null 2>&1; then
log_message "Floating IP $FLOATING_IP is reachable"
exit 0
else
log_message "WARNING: Floating IP $FLOATING_IP is not reachable"
exit 1
fi
else
log_message "ERROR: Floating IP $FLOATING_IP is not configured"
exit 2
fi
Automated Floating IP Assignment
#!/bin/bash
# assign-floating-ip.sh
FLOATING_IP="10.0.0.8"
INTERFACE="eth0"
# Check if IP is already assigned
if ! ip addr show "$INTERFACE" | grep -q "$FLOATING_IP"; then
echo "Assigning floating IP $FLOATING_IP to $INTERFACE"
# Add IP address
sudo ip addr add "$FLOATING_IP/32" dev "$INTERFACE"
# Add route
sudo ip route add "$FLOATING_IP/32" dev "$INTERFACE"
# Verify assignment
if ip addr show "$INTERFACE" | grep -q "$FLOATING_IP"; then
echo "Successfully assigned floating IP $FLOATING_IP"
else
echo "Failed to assign floating IP $FLOATING_IP"
exit 1
fi
else
echo "Floating IP $FLOATING_IP is already assigned"
fi
Security Considerations
Implement security best practices when configuring floating IPs to protect your infrastructure.
🔒 Security Best Practices
Essential security measures:
- Firewall Rules: Configure iptables or ufw to control floating IP access
- Access Control: Limit floating IP usage to authorized services only
- Monitoring: Log all floating IP assignment and usage activities
- Network Segmentation: Use VLANs to isolate floating IP traffic
- Regular Audits: Review floating IP configurations and access logs
Firewall Configuration for Floating IPs
# UFW firewall rules for floating IP
sudo ufw allow in on eth0 to 10.0.0.8 port 80
sudo ufw allow in on eth0 to 10.0.0.8 port 443
sudo ufw allow in on eth0 to 10.0.0.8 port 22
# iptables rules for floating IP
sudo iptables -A INPUT -d 10.0.0.8 -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -d 10.0.0.8 -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -d 10.0.0.8 -p tcp --dport 22 -j ACCEPT
# Save iptables rules
sudo iptables-save > /etc/iptables/rules.v4
Additional Resources for Network Management
- Official Netplan Documentation – Comprehensive Netplan configuration reference
- Ubuntu Network Configuration Guide – Ubuntu-specific networking documentation
- Debian Network Configuration – Debian networking setup and management
- Linux IP Command Manual – Complete reference for the ip command
Conclusion: Mastering Floating IP Configuration
Floating IP configuration using Netplan provides a robust foundation for high-availability infrastructure on Ubuntu and Debian systems. By understanding both persistent Netplan configurations and manual IP management techniques, you can implement reliable network failover solutions.
The combination of Netplan’s declarative configuration model and manual IP commands gives you flexibility for both permanent infrastructure and temporary testing scenarios. Whether you’re implementing load balancing, disaster recovery, or simple service migration, floating IPs provide the network agility needed for modern server management.
🚀 Implementation Checklist
Complete these steps for successful floating IP deployment:
- ✅ Backup existing network configuration
- ✅ Create Netplan floating IP configuration
- ✅ Test configuration with netplan try
- ✅ Apply configuration and verify connectivity
- ✅ Configure firewall rules for floating IP
- ✅ Implement monitoring and health checks
- ✅ Document configuration for team reference
Ready to implement floating IPs in your infrastructure? Start with a test environment to familiarize yourself with Netplan configuration, then gradually deploy to production systems with proper monitoring and backup procedures in place.