Skip to content

Instantly share code, notes, and snippets.

@eagafonov
Created March 14, 2016 12:33
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save eagafonov/5c57bfbe353a9c93a94c to your computer and use it in GitHub Desktop.
Save eagafonov/5c57bfbe353a9c93a94c to your computer and use it in GitHub Desktop.
[DigitalOcean] Simple script to route outgoing traffic through Floating IP
#!/bin/bash -x
set -e
# https://www.digitalocean.com/community/tutorials/how-to-use-floating-ips-on-digitalocean
DESTINATION_IP=$1
shift || (echo "E: Destination IP is not provided. Aborting"; exit 1)
ANCHOR_GW=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/gateway)
route del $DESTINATION_IP || true
route add $DESTINATION_IP gw $ANCHOR_GW
@ijunaid8989
Copy link

what this exactly doing can you tell?

@guidolodetti
Copy link

Hi and thanks for the script!

Where do you suggest to put it? I tried running it at launch with rc.local but it seems that sometimes network interfaces restarts automatically and so the script should be run again.

Thanks again.

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