CentOS 7 Server Deployment Cookbook
上QQ阅读APP看书,第一时间看更新

Binding multiple addresses to a single Ethernet device

This recipe shows you how to bind multiple IP addresses to a single Ethernet device. The ability to assign more than one address to the same device can be useful-the most obvious benefit is that you don't need to procure multiple Ethernet cards. The cost of hardware has dropped substantially, but IT budgets still run tight. Perhaps a less obvious benefit, but one more valuable, is the greater flexibility it gives when configuring network services. Different services, such as e-mail and websites, can run on the same system but be accessed using different addresses.

Getting ready

This recipe requires a CentOS system with a working network connection. It assumes that your primary Ethernet device is enp0s3 and is configured with a static IP address. You'll also need administrative privileges provided by logging in with the root account.

How to do it...

Follow these steps to bind multiple addresses to the same Ethernet device:

  1. Make a copy of the device's configuration file:
    cp /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-enp0s3:1
    
  2. Open the new file with your text editor:
    vi /etc/sysconfig/network-scripts/ifcfg-enp0s3:1
    
  3. Delete the UUID entry entirely. If a HWADDR entry exists, delete that also.
  4. Update the NAME and DEVICE values:
    NAME="System enp0s3:1"
    DEVICE="enp0s3:1"
    
  5. Change the value of IPADDR to the IP address you wish to use:
    IPADDR="192.168.56.101"
    
  6. Save your changes and close the file.
  7. Restart the networking service for the configuration changes to take effect:
    systemctl restart network.service
    

How it works...

In this recipe, you learned how to assign multiple IP addresses to the same Ethernet device. We made a copy of one of the original network configuration files, taking care to name it appropriately to create a virtual adapter, and edited its configuration details. Since the name of the first device's configuration is ifcfg-enp0s3, the new file is named ifcfg-enp0s3:1 to create the first virtual adapter associated with that device. If you want to add more adapters (assign more IP addresses), repeat the steps using incrementing numbers, for example, enp0s3:2, enp0s3:3, and so on.

In the configuration file, we removed the HWADDR and UUID entries since they are not needed for a virtual adapter. Then we updated the DEVICE and NAME entries to give the adapter its own identify, and, of course, we updated the IPADDR entry to assign its IP address:

Multiple IP addresses are bound to an Ethernet device via a virtual adapter

See also

Refer to the following resources for more information on binding multiple addresses to the same Ethernet device: