Configuring Linux to Use a Secondary Private IP Address

Configure Linux to use a secondary private IP address.

After assigning a secondary private IP to a VNIC, you must configure the OS to use it.

Basic Commands (Not Persistent Through a Reboot)

On the instance, run the following command. It works on all variants of Linux, for both bare metal and VM instances:
ip addr add <address>/<subnet_prefix_len> dev <phys_dev> label <phys_dev>:<addr_seq_num>
where:
  • <address>: The secondary private IP address.
  • <subnet_prefix_len>: The subnet's prefix length. For example, if the subnet is 192.168.20.0/24, the subnet prefix length is 24.
  • <phys_dev>: The interface to add the address to (for example, ens2f0).
  • <addr_seq_num>: The sequential number in the stack of addresses on the device (for example, 0).
For example:
ip addr add 192.168.20.50/24 dev ens2f0 label ens2f0:0

To delete the address, you can use:

ip addr del 192.168.20.50/24 dev ens2f0:0 

Also, delete the secondary IP from the VNIC. You can do that before or after executing the preceding command to delete the address from the OS configuration.

Note

If you assigned a secondary IP to a secondary VNIC, and you're using policy-based routing for the secondary VNIC, configure the route rules for the instance to look up the same route table for the secondary IP address, using the ip rule add from <source address> lookup <table name> command.

Configuration File (Persistent Through a Reboot)

You can make the configuration persistent through a reboot by adding the information to a configuration file.