Try   HackMD

h1How to Configure Additional IPs Using NMCLI

Configuring additional IP addresses on your Linux server is essential for hosting multiple services or applications. For administrators using AlmaLinux, RockyLinux, or CentOS, NMCLI (NetworkManager Command Line Interface) provides a powerful and straightforward method to manage network connections. This guide explains how to use AlmaLinux NMCLI, ensuring your server is optimized for performance.

Why Use NMCLI for IP Configuration?

NMCLI is a command-line tool that interacts directly with the NetworkManager service. It eliminates the need for manual editing of network configuration files, allowing you to manage network interfaces, configure IPs, and troubleshoot connectivity issues in a streamlined manner.

By using NMCLI, you ensure:
Consistency: Uniform configuration across network interfaces.

Flexibility: Support for both static and dynamic IP assignments.

Ease of Use: Simplified syntax for quick network adjustments.

Steps to Configure Additional IPs Using NMCLI
Step 1: Verify Your Network Interface
Before adding IP addresses, determine the name of your active network interface. Run the following command:

nmcli device status

This command lists all network devices. Identify the active connection you wish to configure, typically labeled as ethernet or wifi under the DEVICE column.

Step 2: Add a New Connection

To assign additional IPs, you can create a new virtual interface linked to your primary network interface. Use the command below, replacing eth0 with your actual interface name:
nmcli connection add type ethernet ifname eth0 con-name eth0-secondary ipv4.addresses 192.168.1.2/24 ipv4.method manual

Explanation:

type ethernet: Specifies the interface type.
ifname eth0: Links the new connection to the primary interface.

con-name eth0-secondary: Sets a name for the secondary connection.

ipv4.addresses: Assigns the new IP address.
ipv4.method manual: Configures the IP statically.

Step 3: Activate the New Connection
Activate the connection to make it operational immediately:

nmcli connection up eth0-secondary
Verify the configuration with:

nmcli connection show eth0-secondary
Step 4: Add Multiple IP Addresses
For adding multiple IPs to the same interface, use the following approach:

nmcli connection modify eth0 +ipv4.addresses 192.168.1.3/24

nmcli connection modify eth0 +ipv4.addresses 192.168.1.4/24
Then, reactivate the interface:

nmcli connection up eth0
Step 5: Test the Configuration
Check if the new IPs are functional by pinging them from another machine:

ping 192.168.1.2
Ensure that your firewall and routing settings permit traffic to these IPs.

NMCLI and Popular Linux Distributions

NMCLI works seamlessly across various RHEL-based distributions, including AlmaLinux, RockyLinux, and CentOS. Each distribution has similar prerequisites and supports NMCLI commands out of the box, making it an excellent choice for administrators handling diverse environments.

Benefits of Configuring Additional IPs
Adding extra IP addresses to your server offers numerous advantages:

Service Isolation: Host separate applications on different IPs for improved security.
Load Distribution: Distribute traffic across multiple IPs to enhance performance.

Scalability: Prepare your server for future growth by allocating additional IP resources.

Top Tips for Using NMCLI
Backup Configurations: Before making changes, back up your network settings.

Test Incrementally: Apply and verify each IP address incrementally to avoid conflicts.
Stay Updated: Use the latest version of NetworkManager to benefit from bug fixes and new features.

For a more detailed guide, visit the First2Host blog.

By mastering NMCLI, you can configure additional IPs effortlessly, ensuring your server runs at its best while supporting complex network setups.