Assigning Multiple IPs in AlmaLinux 8 Manual Fix

Joseph Matino
Assigning Multiple Ips In Almalinux 8 Manual Fix

Using multiple IPs, facilitated by tools like Cloud-init or WHMCS, is often seen as a reliable setup approach across various operating systems like Ubuntu and Debian.

Recently, though, I’ve run into some challenges with this setup in AlmaLinux 8, where the expected functionality wasn’t there. It’s unclear whether this is due to my server’s specific configuration or a broader issue.

Addressing A Frequent Network Configuration Challenge

When setting up an AlmaLinux server with the anticipation of smooth functionality thanks to Cloud-init, the reality of only one active IP address out of many can be disappointing. This scenario is not unusual, underscoring the limits of Cloud-init’s automation in certain contexts.

Although Cloud-init aims to make the setup process more efficient, it doesn’t guarantee that all aspects, such as IP address activation, will be handled perfectly.

Consequently, there may be instances where manual intervention is required to get all IP addresses up and running as they should.

Note! Before you proceed, make sure you have root access or enough privileges on your AlmaLinux server. Familiarity with basic networking concepts and command-line operations is also assumed.

Step 1: create custom routing tables

Routing tables direct network packets to their destinations. Custom routing tables allow granular control over how different IP addresses interact with the network.

This is essential for servers with multiple IPs.

  • Open a terminal session and edit the rt_tables file to add custom tables:
nano /etc/iproute2/rt_tables
  • Append the following lines, creating two custom routing tables named eth0 and eth1:
echo "100 eth0" >> /etc/iproute2/rt_tables
echo "200 eth1" >> /etc/iproute2/rt_table

Save your changes and exit the editor.

Why Link IPs to Tables?

Associating specific IP addresses with designated routing tables is crucial for ensuring that each IP uses the correct network path, particularly when dealing with multiple network interfaces.

Configuration Process

  • Assign each IP address to its respective routing table using the ip rule add command:
ip rule add from 192.0.2.10 table eth0
ip rule add from 198.51.100.10 table eth1

Replace 192.0.2.10 and 198.51.100.10 with your server’s IP addresses.

Step 3: Configure Default Routes

Default routes specify the primary path that network traffic should follow. Setting this up for each routing table ensures that traffic from each IP address follows the correct route.

Setting Up Routes

  • Define the default gateway for each routing table:
ip route add default via 203.0.113.1 dev eth0 table eth0
ip route add default via 203.0.113.1 dev eth1 table eth1

Replace 203.0.113.1 with your network’s gateway IP.

Step 4: Testing the Configuration

Testing each IP address individually by pinging an external server is a reliable way to confirm the effectiveness of your configuration.

  • Use the ping command to test connectivity for each IP:
ping -c 4 -I 192.0.2.10 8.8.8.8
ping -c 4 -I 198.51.100.10 8.8.8.8

Replace the IPs with those you configured.

Step 5: Creating a Delayed Custom-Routing Script

To make sure the network interfaces are fully initialized before applying the custom routing rules, it’s important to implement a delay. This is especially crucial during system boot.

Script Creation

  • Write a script that incorporates a delay before applying routing rules:
nano /usr/local/bin/slambo-routing.sh
  • Insert the following content, which includes the previously used ip commands:
#!/bin/bash
sleep 10
ip rule add from 192.0.2.10 table eth0
ip rule add from 198.51.100.10 table eth1
ip route add default via 203.0.113.1 dev eth0 table eth0
ip route add default via 203.0.113.1 dev eth1 table eth1

Save and close the file.

Step 6: Script Execution Permissions

For the script to run, it needs execution permissions.

  • Alter the script’s permissions:
chmod +x /usr/local/bin/slambo-routing.sh

Step 7: Automate with Systemd

Creating a systemd service ensures that the custom-routing script runs at each boot, maintaining your network configuration across restarts.

  • Create a new systemd service file:
nano /etc/systemd/system/slambo-routing.service
  • Populate the file with the following content:
[Unit]
Description=Slambo Custom Routing Service
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/slambo-routing.sh
[Install]
WantedBy=default.target

Save the file and exit.

Step 8: Enabling the Service

  • Reload systemd to recognize the new service:
systemctl daemon-reload
  • Enable the custom-routing service to ensure it starts on boot:
systemctl enable slambo-routing.service

Step 9: Finalizing the Configuration

A system reboot is necessary to apply all the changes and initialize the custom-routing script during startup.

reboot

Final Thoughts

This guide simplifies setting up multiple IP addresses in AlmaLinux 8. This is important when automated setups like WHMCS or Cloud-init are not enough. By following these steps, you will improve each IP setup.

This will make your server more efficient and flexible. The initial setup requires concentration. But, the rewards are worth it. You’ll get a high-performing, reliable network. Take this chance to improve your server management skills.

Share This Article
1 Comment