Rocky Linux is rapidly gaining popularity as a reliable, enterprise-ready, and community-driven Linux distribution. One of the essential tasks when configuring a Rocky Linux server is adding IP addresses. In this blog post, we will discuss how to add IPs on Rocky Linux using various methods, such as IP aliasing and configuring a network interface with multiple IPs.
1. Understanding IP Aliasing
IP aliasing is a technique that allows you to assign multiple IP addresses to a single network interface. This is particularly useful for running multiple services on a single server, each bound to a separate IP address. For instance, you may want to run a LAMP stack and a PowerDNS server on the same machine.
2. Adding IPs using IP Aliasing
Here’s a step-by-step guide to adding IPs using IP aliasing:
- Identify the network interface: Use the
ip addr
command to list all network interfaces and their associated IP addresses. - Create a new configuration file: Copy the existing network interface configuration file to a new file, replacing
eth0
with your network interface name and:0
with the desired alias number. For example:
sudo cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
- Modify the new configuration file: Edit the newly created configuration file using a text editor, such as
vi
ornano
. Update theDEVICE
,NAME
,IPADDR
, andNETMASK
parameters to reflect the new IP address and alias number. For example:
vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
NAME=eth0:0
IPADDR=192.168.1.2
NETMASK=255.255.255.0
- Restart the network service: Restart the network service to apply the changes:
sudo systemctl restart NetworkManager
- Verify the new IP address: Use the
ip addr
command again to verify that the new IP address has been added.
3. Configuring a Network Interface with Multiple IPs
Another approach to adding IPs on Rocky Linux is by configuring a network interface with multiple IP addresses. This method is commonly used with KVM virtualization and Proxmox VE. Follow these steps:
- Identify the network interface: Use the
ip addr
command to list all network interfaces and their associated IP addresses. - Edit the network interface configuration file: Open the network interface configuration file with a text editor, such as
vi
ornano
. For example:
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
- Add the new IP addresses: Add the new IP addresses using the
IPADDR#
andPREFIX#
parameters, where#
is a unique number for each additional IP address. For example:
IPADDR1=192.168.1.3
PREFIX1=24
IPADDR2=192.168.1.4
PREFIX2=24
- Restart the network service: Restart the network service to apply the changes:
sudo systemctl restart NetworkManager
- Verify the new IP addresses: Use the
ip addr
command again to verify that the new IP addresses have been added.
4. Managing IP Addresses with NetworkManager
Rocky Linux comes with NetworkManager, a dynamic network control and configuration system that can manage IP addresses more efficiently. NetworkManager supports various network devices, including Ethernet, Wi-Fi, and mobile broadband devices. Here’s how to use NetworkManager to add IPs:
- Install NetworkManager: If NetworkManager is not already installed, install it using the following command:
sudo dnf install NetworkManager
- Enable and start NetworkManager: Enable and start the NetworkManager service using:
sudo systemctl enable --now NetworkManager
- Add IP addresses: Use the
nmcli
command to add IP addresses to the network interface. For example:
sudo nmcli connection modify eth0 +ipv4.addresses "192.168.1.3/24"
sudo nmcli connection modify eth0 +ipv4.addresses "192.168.1.4/24"
- Restart NetworkManager: Restart the NetworkManager service to apply the changes:
sudo systemctl restart NetworkManager
- Verify the new IP addresses: Use the
nmcli
command to verify that the new IP addresses have been added:
nmcli connection show eth0
Conclusion
Adding IPs on Rocky Linux is a crucial step in configuring your server for various purposes, such as hosting multiple services, virtualization, and more. In this blog post, we’ve discussed three different methods to add IPs on Rocky Linux: IP aliasing, configuring a network interface with multiple IPs, and using NetworkManager. Each method has its advantages, so choose the one that best suits your needs.
For more information on managing your Rocky Linux server, check out our tutorials on how to set up RAID 1, how to install Ansible server, and how to install VirtualBox. These guides will help you enhance your server management skills and make the most out of your Rocky Linux experience.