NetworkManager Command Line Interface (NMCLI) is a powerful tool for managing network connections in Linux-based systems like Rocky Linux. Configuring additional IP addresses on your server using NMCLI can be essential for hosting multiple websites, creating virtual machines, or setting up network services. This guide will walk you through the steps to configure additional IPs on your RockyLinux NMCLI server.
Why Configure Additional IPs?
Configuring additional IPs offers several benefits:
- Enhanced Network Flexibility: Manage multiple services or applications independently.
- Load Balancing: Distribute traffic across multiple IPs for better performance.
- Improved Security: Isolate services by assigning them separate IP addresses.
Prerequisites
Before you begin, ensure the following:
- You have root or sudo access to your Rocky Linux server.
- NMCLI is installed and functional (it comes pre-installed in most Rocky Linux setups).
- Additional IPs are allocated by your hosting provider.
Steps to Configure Additional IPs
Step 1: Identify Your Active Connection
To configure additional IPs, you first need to identify the active network connection.
nmcli connection show
This command will display a list of network connections. Note the name of the active connection, typically something like eth0 or ens33.
Step 2: Add an Additional IP to the Connection
To add a new IP, use the following command format:
sudo nmcli connection modify "<CONNECTION_NAME>" +ipv4.addresses <NEW_IP>/<SUBNET_MASK>
Replace <CONNECTION_NAME> with the name of your active connection and <NEW_IP>/<SUBNET_MASK> with the IP address and subnet mask provided by your hosting service. For example:
sudo nmcli connection modify "ens33" +ipv4.addresses 192.168.1.100/24
Step 3: Verify and Restart the Connection
After adding the new IP, restart the connection to apply the changes:
sudo nmcli connection up "<CONNECTION_NAME>"
To verify that the additional IP is configured correctly, run:
ip addr show
The output should display the new IP under the appropriate network interface.
Step 4: Set IP Configuration to Manual (Optional)
If the connection is using DHCP and you want to switch to a static IP configuration, use:
sudo nmcli connection modify "<CONNECTION_NAME>" ipv4.method manual
Step 5: Configure Multiple Additional IPs
You can add multiple IPs to the same connection by repeating Step 2 for each IP address:
sudo nmcli connection modify "ens33" +ipv4.addresses 192.168.1.101/24
sudo nmcli connection modify "ens33" +ipv4.addresses 192.168.1.102/24
Restart the connection after adding all IPs:
sudo nmcli connection up "ens33"
Troubleshooting
- Connection Errors: Ensure the IP address is not already in use and belongs to the correct subnet.
- Persistent Issues: Check the system logs for errors using:
journalctl -u NetworkManager - IP Not Displayed: Recheck the configuration or restart the network service:
sudo systemctl restart NetworkManager
Conclusion
Using NMCLI to configure additional IPs on Rocky Linux provides a robust way to manage multiple IP addresses efficiently. This setup is ideal for advanced networking needs, including web hosting, service isolation, and security enhancements. By following this guide, you can easily add and manage additional IPs, ensuring your server performs at its best.