Christoph's 2 Cents

A Backup for My Brain!

CloudLinuxOracle Cloud InfrastructrureOracle LinuxUncategorized

OCI Instance: Secondary VNIC Routing

After adding a secondary VNIC to your compute instance, you’ll need to enable the OCID service which checks for changes in VNIC (and iSCSI) devices. It also makes sure that the network interface uses the secondary VNIC.

In instances based on Oracle-provided images, this OCI Utilities are already installed.

Adding a Static Route

You may want to add a different static route for the second VNIC. You can do this with

ip route add x.x.x.x/x via y.y.y.y dev ens5

Where x.x.x.x/16 is the CIDR block you want to route to, and x.x.x.x the gateway you wish to use.

The secondary VNIC on a standard OEL7 instance will be named ens5. To double check the name run:

ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9000 qdisc mq state UP group default qlen 1000
    link/ether 02:00:17:07:d0:eb brd ff:ff:ff:ff:ff:ff
    inet brd scope global dynamic ens3
       valid_lft 61023sec preferred_lft 61023sec
3: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9000 qdisc mq state UP group default qlen 1000
    link/ether 00:00:17:01:2b:56 brd ff:ff:ff:ff:ff:ff
    inet 123.456.32.4/24 scope global ens5
       valid_lft forever preferred_lft forever

Line 3 above shows the secondary VNIC with device name ens5.

To make the route persistent after startup, you can create a service like this (I use ens5 as the device name for the second VNIC):

if [ "$EUID" -ne 0 ]
  then echo "Please run as root"

# Edit as neccessary

mkdir /opt/secondary_vnic

# Script that adds secondary route
cat > /opt/secondary_vnic/ <<EOF
ip route add $ROUTECIDR via $GATEWAYIP dev ens5

chmod +x /opt/secondary_vnic/

# Service to execute script on boot  
cat > /etc/systemd/system/secondary_vnic_route.service <<EOF
     Description=Add route to the secondary VNIC at boot



systemctl enable secondary_vnic_route
systemctl start secondary_vnic_route

echo "Done"

Now make sure that the services is started, or else start it with.

systemclt start secondary_vnic_route

Validate the route with

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    0      0        0 ens3   U     0      0        0 ens3
123.456.0.0     123.456.32.1     UG    0      0        0 ens5