AMI: ubuntu 16.04
Create and assign ENI
Assume additional interface name: eth1
Assume its private ip: 10.170.224.57
Assume mask: 255.255.0.0 (16)
Inside instance:
echo "200 out" >> /etc/iproute2/rt_tables
Get gateway from route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.170.0.1 0.0.0.0 UG 0 0 0 eth0
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 peervpn0
10.170.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
10.170.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
You can use this command: route -n |sed -n '3p'| awk '{print $2}'
So, now we have all necessary info:
Gateway = 10.170.0.1
Mask = 255.255.0.0
Interface ip = 10.170.224.57
Create file /etc/network/interfaces.d/eth1.cfg with the following content:
auto eth1
iface eth1 inet static
address 10.170.224.57
netmask 255.255.0.0
up ip route add default via 10.170.0.1 dev eth1 table out
up ip rule add from 10.170.224.57/32 table out
up ip rule add to 10.170.224.57/32 table out
up ip route flush cache
Brign up your interface: ifup eth1