Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring Multiple IP Addresses on a Single Network Interface in CentOS

Tech May 1 20

Note: The multiple IP addresses must be in the same subnet to avoid multi-gateway issues. For example, if the subnet is 192.168.1.0/24 with gateway 192.168.1.1, you can assign IP addresses like 192.168.1.2 through 192.168.1.254.

To configure multiple IP addresses on a single network interface in CentOS, follow these steps:

1. Check Current Network Configuration

First, view the current network configuration to identify your interface name (e.g., eth0, ens33).

ip addr

2. Edit Network Configuration

CentOS 7 and later use nmcli (NetworkManager command-line tool) or direct editing of configuration files (e.g., /etc/sysconfig/network-scripts/ifcfg-<interface>). For newer versions, nmcli is recommended.

Using nmcli to Configure Multiple IPs

  1. View existing connecsions:

    nmcli con show
    
  2. Add an IP address to an existing connection:

    nmcli con mod <connection-name> +ipv4.addresses <IP-address>/<prefix>
    

    For example, to add IP 192.168.1.100/24 to connection ens33:

    nmcli con mod ens33 +ipv4.addresses 192.168.1.100/24
    
  3. Apply the changes:

    nmcli con up <connection-name>
    

    Example:

    nmcli con up ens33
    

Editing Configuration Files (Traditional Method)

For CentOS 7 and earlier, or if you prefer direct editing:

  1. Edit the interface configuration file, e.g., /etc/sysconfig/network-scripts/ifcfg-ens33.
  2. Add multiple IP addresses using the following syntax:
    DEVICE=eth0
    BOOTPROTO=static
    ONBOOT=yes
    IPADDR0=192.168.1.101
    NETMASK0=255.255.255.0
    GATEWAY0=192.168.1.1
    IPADDR1=192.168.1.102
    NETMASK1=255.255.255.0
    GATEWAY1=192.168.1.1
    IPADDR2=192.168.1.103
    NETMASK2=255.255.255.0
    GATEWAY2=192.168.1.1
    
  3. Save the file and restart the network service or reboot:
    systemctl restart network
    # or reboot: systemctl reboot
    
    Alternatively, restart the interface:
    ifdown eth0 && ifup eth0
    

3. Verify Configuration

Use ip addr or ifconfig to verify that the new IP addresses are active.

Notes:

  • For CentOS 7 and later, prefer nmcli or NetworkManager over manual configuration files to avoid issues.
  • For newer distributions like CentOS Stream or Fedora, refer to the latest documentation and use modern tools like nmcli.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Comprehensive Guide to Hive SQL Syntax and Operations

This article provides a detailed walkthrough of Hive SQL, categorizing its features and syntax for practical use. Hive SQL is segmented into the following categories: DDL Statements: Operations on...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.