Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring Multiple IP Addresses on a Single Network Interface in CentOS

Tech 1

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...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

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