Skip to content

Instantly share code, notes, and snippets.

@msnodderly
Created July 29, 2012 06:07
Show Gist options
  • Save msnodderly/3196336 to your computer and use it in GitHub Desktop.
Save msnodderly/3196336 to your computer and use it in GitHub Desktop.
dev tun
ifconfig 10.8.0.2 10.8.0.1
secret /Users/username/path/to/static.key
redirect-gateway def1
## Setup IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
dev tun
ifconfig 10.8.0.1 10.8.0.2
secret /etc/openvpn/static.key
@msnodderly
Copy link
Author

NOTE: this config will route ALL your traffic through the VPN tunnel. If this isn't what you want, you'll need to add static routes in your openvpn config.

Launch AMI instance

  • After it finishes launching, scroll down to "Public DNS name" and note the name
    eg: ec2-X.X.X.X.compute.amazonaws.com

Setup a security group

  • Click "Security Groups" and choose the "quicklaunch-1" group.

  • Create a new Custom UDP rule for port 1194

  • Apply rule changes

    TCP
    Port (Service) Source Action
    22 (SSH) 0.0.0.0/0 Delete

    UDP
    Port (Service) Source Action
    1194 0.0.0.0/0 Delete

Save your key in /Users/[username]/.ssh/aws.pem

  • From the mac terminal:
    $ cd ~/.ssh
    $ cp ~/Downloads/aws.pem .
    $ chmod 600 ./aws.pem

Log in to your new EC2 machine

$ ssh -i ~/.ssh/aws.pem [email protected]

(substitute the public DNS name of your instance noted above)

Install openvpn (on EC2 machine)

$ sudo -i
$ yum -y install openvpn
$ cd /etc/openvpn
$ openvpn --genkey --secret static.key
$ cat > server.cfg
dev tun
ifconfig 10.8.0.1 10.8.0.2
secret /etc/openvpn/static.key
^D

Setup IP forwarding

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

Install Tunnelblick on your Mac

  • Download and install: http://code.google.com/p/tunnelblick/downloads/detail?name=Tunnelblick_3.2.6.dmg

  • Launch it, click I have configuration files, and create a configuration

  • Create a file config.ovpn in the folder that opens

    • replace the contents of the file with this (replace with the public DNS of your EC2 instance):

    remote ec2-X.X.X.X.compute.amazonaws.com
    dev tun
    ifconfig 10.8.0.2 10.8.0.1
    secret /Users/username/path/to/static.key
    redirect-gateway def1

  • Save and quit

  • Copy the secret key to your mac in the location you specified

  • Connect Tunnelblick and go.

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