Skip to content

Instantly share code, notes, and snippets.

@kolargol
Last active July 2, 2018 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolargol/47b91ea4b4d81390e9a2ce147aee2ff8 to your computer and use it in GitHub Desktop.
Save kolargol/47b91ea4b4d81390e9a2ce147aee2ff8 to your computer and use it in GitHub Desktop.
AWS EC2: setup high number of outgoing (persistent) connections from single instance (4 ENI) - 4 million connections
#!/bin/bash
# Juan Pablo and Zbyszek Zolkiewski (at) ProcessOne 2015-2018
#
# This script configures additional 3 ENI (+1 aliased eth0) on AWS ec2
# Following setup allow to generate around 4 milion outgoing connections from single instance
# If one need more, you need to add additional ENI and allocate max 15 IP per ENI (AWS limit)
# RPS:
# echo ff > /sys/class/net/eth0/queues/rx-0/rps_cpus
echo "<<<< Adding IP aliases on eth0 >>>>"
i=0
MAC_ADDR=$(ifconfig eth0 | sed -n 's/.*HWaddr \([a-f0-9:]*\).*/\1/p')
IP=($(curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC_ADDR/local-ipv4s -s))
for ip in ${IP[@]:1}; do
echo "Adding IP: $ip (eth0)"
ip addr add dev eth0 $ip/24
i=$(expr $i + 1)
done
echo "--> $i IP added on eth0"
# add 3 new NIC:
for eth in {1..3}; do
iseth=$(ip link show eth$eth|grep -c UP)
if [ ! $iseth ]; then
echo "No eth$eth!"
exit
fi
echo "<<<< Adding IP aliases on eth$eth >>>>"
i=0
# get default route
droute=$(ip route|grep "default via" | awk '{print $3}')
rnum=$(expr $eth + 1)
# add this table
echo "$rnum eth$eth"_"rt" >> /etc/iproute2/rt_tables
ip route add default via $droute dev eth$eth table eth$eth"_"rt
MAC_ADDR=$(ifconfig eth$eth | sed -n 's/.*HWaddr \([a-f0-9:]*\).*/\1/p')
IP=($(curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC_ADDR/local-ipv4s -s))
for ip in ${IP[@]:0}; do
echo "Adding IP: $ip (eth$eth)"
ip addr add dev eth$eth $ip/24
ip rule add from $ip lookup eth$eth"_"rt prio 1000
i=$(expr $i + 1)
done
echo "--> $i IP added on eth$eth"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment