Skip to content

Instantly share code, notes, and snippets.

@bbl
Last active March 20, 2018 18:22
Show Gist options
  • Save bbl/8e492d2e9ad683fe14e4f3d5e958a850 to your computer and use it in GitHub Desktop.
Save bbl/8e492d2e9ad683fe14e4f3d5e958a850 to your computer and use it in GitHub Desktop.
How to setup elastic interface on AWS instance.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment