Routing for multi-homed public IP interfaces

Jasun -

Typically a Joyent VirtualMachine does not need more than one public interface.  You will have to request an additional public interface by contacting Joyent Support.

Public interfaces will be added on different subnets.  You will have to set routing rules so that packets are routed to appropriate gateways when you have multi-homed interfaces.  The following script can be updated and called from /etc/rc.local to set up the required routing:

 

NOTE: Do not place the script in your /etc/rc.local till you test it.  It is recommended that you test this script first by running it in a root shell on a test system.  The reason is that if your routing is not correct and you are unable to access your system. You can reboot the system from my.joyentcloud.com to regain access.

 

#!/bin/bash

# first subnet with \## notation for gateway
first_subnet='37.153.96.0/23'
# interface that the first subnet is on
first_interface='eth0'
# gateway for first subnet
first_gateway='37.153.96.1'


# second subnet with \## notation for gateway
second_subnet='37.153.98.0/23'
# interface that the second subnet is on
second_interface='eth2'
# gateway for second subnet
second_gateway='37.153.98.1'

#Set up the first subnet's routing table (we'll name it 70)

/sbin/ip route flush table 70
/sbin/ip route add table 70 to $first_subnet dev $first_interface
/sbin/ip route add table 70 to default via $first_gateway dev $first_interface

#Set up the second subnet's routing table (we'll call it 80)

/sbin/ip route flush table 80
/sbin/ip route add table 80 to $second_subnet dev $second_interface
/sbin/ip route add table 80 to default via $second_gateway dev $second_interface

#Create the rules to choose what table to use. Choose based on source IP
#We need to give the rules different priorities; for convenience name priority
#after the table

/sbin/ip rule add from $first_subnet table 70 priority 70
/sbin/ip rule add from $second_subnet table 80 priority 80

#Flush the cache to make effective
/sbin/ip route flush cache

# Test new routes

ping -c 3 -I $first_interface 8.8.8.8

ping -c 3 -I $second_interface 8.8.8.8

Have more questions? Submit a request

0 Comments

Article is closed for comments.