banner
Alexeisie

AlexEisie

啊?
github

Oracle Oracle Bone Script Example Multiple Public IP Allocation

Add multiple public IP addresses to a single instance
Experimental environment:
ARM (A1) instance
Ubuntu 22.04 (Debian Based)

Introduction: Note that different instance types have different limits on VNIC allocation, and there also seems to be a limit on the number of public IPs. Misoperations may cause the machine to become unreachable, so please ensure that the parameters are correct and complete when entering commands.

1. Adding VNIC to OCI#

Yes, one VNIC can have multiple IPv4 addresses in a VCN, but it can only be bound to one public IP. Therefore, we need to add a new VNIC (network card).
Why not create a new VNC? Adding a new VNC has no restrictions, but the public gateway does, so our new VNIC still needs to use the same VCN as the primary VNIC to use the same gateway.

Compute/Instances/Instance details/Attached VNICs

1.1 Create a new VNIC
Click on Create VNIC
VCN: Select the same VCN as the primary VNIC
Subnet: Select the same subnet as the primary VNIC
Create the VNIC without any special requirements.

1.2 Configure the VNIC
Click on the newly created VNIC, select IPv4 Addresses, and register a new IPv4 address.
Bind a public IP address to the newly created IPv4 address, which can be a temporary IP (Ephemeral public IP) or a reserved IP (Reserved public IP).

At this point, the OCI operation is complete. Please remember the MAC address and IPv4 private address of the new VNIC for the next step.

2. Instance network card configuration#

2.1 Check the network card
After adding the VNIC in OCI, if there are no exceptions, the instance should automatically add a new network interface.
Use ifconfig to check the network interfaces.
For A1 instances, the primary VNIC should correspond to enp0s3, and the new VNIC should correspond to enp1s0. Please differentiate based on the MAC address.

2.2 Add an IPv4 address to the network interface
In the author's experiment, the network interface did not automatically add a new IPv4 address, and using dhclient did not work either. Therefore, I chose to add it manually. If the new network interface already has the correct IPv4 address, please ignore this step.
ip addr add <private address> dev <network interface name>
EXP. ip addr add 10.0.0.10/24 dev enp1s0
Check the network interface again, and the new IPv4 address should appear.
To facilitate internal network broadcasting and ARP propagation, we need to modify the broadcast address. For the network 10.0.0.0/24, the broadcast address should be 10.0.0.255.
ifconfig enp1s0 <private address> netmask 255.255.255.0 broadcast <broadcast address>
EXP. ifconfig enp1s0 10.0.0.10 netmask 255.255.255.0 broadcast 10.0.0.255

2.3 Add a default gateway to the network interface
Since the new VNIC and the primary VNIC are in the same VCN, they should use the same gateway. First, obtain the gateway address by checking the gateway configuration for the primary VNIC through the routing table.
route -n

_Kernel IP routing table
Destination  Gateway      Genmask         Flags Metric Ref    Use Iface
(omitted)
0.0.0.0      10.0.0.1     0.0.0.0         UG    100    0        0 enp0s3
(omitted)

From this, it can be seen that for the enp0s3 network card, any destination address matching 0.0.0.0/0 will be routed to the gateway 10.0.0.1.

We can use the new network card to test access to this gateway.
ping 10.0.0.1 -I enp1s0

Then we configure the default gateway for the new network card.
route add default gw <gateway address> <network interface name>
EXP. route add default gw 10.0.0.1 enp1s0

Check the routing table again, and we will find that enp1s0 has a new route information.

Kernel IP routing table
Destination  Gateway      Genmask         Flags Metric Ref    Use Iface
0.0.0.0      10.0.0.1     0.0.0.0         UG    0      0        0 enp1s0
0.0.0.0      10.0.0.1     0.0.0.0         UG    100    0        0 e
(omitted)

At this point, the public IP address has been added.

3. (Optional) Test network connectivity#

The instance accesses the external network through the new address.
ping google.com -4 -I enp1s0
The external network accesses the new address of the instance.
'ping '

4. (Optional) Modify network interface MTU and priority#

The MTU used by the primary network card is 9000. If you need to reduce the frequency of network layer packet transmission, you can modify it to the same MTU.
ifconfig enp1s0 mtu 9000

If you need to modify the priority of the network interface output, you can configure the route priority by modifying the route hops.
ifmetric enp1s0 0

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.