In AlmaLinux, you can bind additional IP addresses to your network interface by creating additional configuration files or by adding them directly in the primary interface configuration. Here’s how you can do it:
1. Using ifcfg Files (Persistent Configuration)
-
Navigate to the network-scripts directory:
cd /etc/sysconfig/network-scripts/
-
Create a new configuration file for the additional IP.
If your main interface iseth0
, create a file likeifcfg-eth0:1
.nano ifcfg-eth0:1
-
Add the following configuration:
DEVICE=eth0:1 BOOTPROTO=static ONBOOT=yes IPADDR=192.168.1.101 NETMASK=255.255.255.0
-
Replace
192.168.1.101
with your desired additional IP address. -
Adjust
NETMASK
according to your network configuration.
-
-
Restart the network service:
sudo systemctl restart NetworkManager
-
Verify the IP address:
ip addr show eth0
2. Adding Additional IP Using nmcli
(NetworkManager CLI)
If you prefer using NetworkManager’s CLI tool, nmcli
, you can add an additional IP address like this:
nmcli connection modify eth0 +ipv4.addresses 192.168.1.102/24
nmcli connection up eth0
-
Replace
192.168.1.102/24
with your desired IP address and subnet mask.
3. Temporary Method (Without Reboot)
If you want to add an IP address temporarily (it will be lost after reboot):
sudo ip addr add 192.168.1.103/24 dev eth0
-
Replace
192.168.1.103/24
with your desired IP address and subnet.
To remove it later, use:
sudo ip addr del 192.168.1.103/24 dev eth0
4. Verify the Configuration
You can use the following command to verify that the IP address has been added.
ip a
Or check the status of your network interface:
nmcli device status
5. Updating Firewall Rules (if needed)
If you are using firewalld
, you might need to allow traffic for the new IP:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.101" accept'
sudo firewall-cmd --reload
Tips:
-
Use the
ifcfg-eth0:X
approach for persistent configurations. -
Use
ip addr add
for temporary changes, which are useful for testing or one-off needs.