Home >System Tutorial >LINUX >How To Assign Multiple IP Addresses To A Single Network Interface Card In Linux

How To Assign Multiple IP Addresses To A Single Network Interface Card In Linux

Lisa Kudrow
Lisa KudrowOriginal
2025-03-21 11:10:09539browse

This tutorial explains how to assign multiple IP addresses to a single network interface in various Linux distributions. We'll cover different methods and address potential issues.

Table of Contents

  • Why Use Multiple IP Addresses?
  • Understanding IPv4 Address Classes and CIDR
  • Method 1: Netplan Configuration File (Modern Systems)
  • Method 2: nmcli Command (Modern Systems)
  • Method 3: nmtui Utility (Modern Systems)
  • Method 4: ip Command (Older DEB-based Systems)
    • 4.1: Making Changes Permanent
  • Method 5: Older RPM-based Systems (e.g., CentOS 7)
  • Method 6: Assigning Different Class IP Addresses (DEB-based)
  • Method 7: Assigning Different Class IP Addresses (RPM-based)
  • Why Avoid Mixing IP Address Classes on One NIC?
  • Conclusion

Why Use Multiple IP Addresses?

Multiple IP addresses offer several advantages:

  1. Network Segmentation: Isolate network segments for enhanced security. Different departments or services can have separate IP ranges.
  2. Hosting Multiple Services: Host multiple websites or services on a single server, each with its own IP address.
  3. Testing and Development: Simulate various network conditions and create isolated testing environments.
  4. Caching Proxy Servers: Optimize internet sharing across subnets with customized access control.
  5. Specific Network Services: Some services (like mail servers) require multiple IPs for different domains or protocols.

Understanding IPv4 Address Classes and CIDR

Before proceeding, familiarize yourself with IPv4 address classes (A, B, C, D, E) and CIDR notation. (A table illustrating IP address ranges would be beneficial here).

Method 1: Netplan Configuration File (Modern Systems)

(Instructions for editing the Netplan configuration file would be included here. This would involve modifying the .yaml file and restarting the networking service.)

Method 2: nmcli Command (Modern Systems)

(Instructions for using the nmcli command-line tool to add multiple IP addresses would be provided here. This would involve commands to add addresses, set gateway, and DNS servers.)

Method 3: nmtui Utility (Modern Systems)

(A step-by-step guide using the nmtui graphical utility would be included. This would involve screenshots showing the menu navigation to add multiple IP addresses, subnet masks, gateway, and DNS servers.) How To Assign Multiple IP Addresses To A Single Network Interface Card In Linux How To Assign Multiple IP Addresses To A Single Network Interface Card In Linux How To Assign Multiple IP Addresses To A Single Network Interface Card In Linux

Method 4: ip Command (Older DEB-based Systems)

This method uses the ip command (or ifconfig in very old systems).

  1. Temporary Assignment: Use sudo ip addr add <ip address>/<netmask> dev <interface></interface></netmask></ip> (e.g., sudo ip addr add 192.168.2.105/24 dev enp0s3).
  2. Verification: Use ip addr to check the assigned addresses.
  3. 4.1 Making Changes Permanent: Edit /etc/network/interfaces, adding lines like address 192.168.2.105/24 under the appropriate interface. Then run sudo ifdown <interface> && sudo ifup <interface></interface></interface>.

Method 5: Older RPM-based Systems (e.g., CentOS 7)

Edit the network interface configuration file (e.g., /etc/sysconfig/network-scripts/ifcfg-<interface></interface>). Add lines like IPADDR1="192.168.2.150", IPADDR2="192.168.3.150", etc., and restart the network service (systemctl restart network).

Method 6 & 7: Assigning Different Class IP Addresses

While possible, assigning different IP address classes to a single NIC is generally discouraged due to routing complexities. Instructions for both DEB-based and RPM-based systems would be similar to methods 4 and 5, but with the appropriate IP address and subnet mask for the desired class.

Why Avoid Mixing IP Address Classes on One NIC?

Mixing IP classes on a single NIC can lead to routing problems because different classes represent different network structures. Routers need to handle the traffic between these differently structured networks.

Conclusion

Assigning multiple IP addresses offers significant benefits, but careful planning is crucial, especially when considering different IP address classes. Remember to use the appropriate method for your Linux distribution and version. Always verify your network configuration after making changes.

The above is the detailed content of How To Assign Multiple IP Addresses To A Single Network Interface Card In Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn