Tag Archives: ios

How to set up a private L2TP VPN server for your iOS or MacOS devices on DigitalOcean

Step 1. Sign up for DigitalOcean

You can get free $10 in credits if you sign up through this link: https://m.do.co/c/ecbd53848776

Step 2. Create a new droplet

Choose the newest Ubuntu distribution. (currently 18.04)
You can choose the smallest standard droplet which costs $5/mo. It is perfectly enough for your private VPN server. You don’t need to change anything else, although you can choose which region you would like to use.

Step 3. Log in to the droplet

You can use your favourite ssh client or you can open the console directly through the web interface.

Step 4. Install Docker on Ubuntu

If you succesfully logged in to your droplet you need to run the following commands to install docker and the vpn container on your system.

# install neccessary packages and docker's gpg key
apt-get update
apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
# add docker repository
add-apt-repository \
   "deb https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
apt-get update
# install docker community edition
apt-get install docker-ce

Step 5. Install the vpn server Docker container

docker pull hwdsl2/ipsec-vpn-server

Step 6. Set up your password in an env file

Replace the words between brackets with your desired passwords. You can check your passwords later if your run “docker logs vpn-server”

cat << EOF >.env
VPN_IPSEC_PSK=[your_ipsec_pre_shared_key]
VPN_USER=[your_vpn_username]
VPN_PASSWORD=[your_vpn_password]
EOF

Step 7. Load the af_key kernel module

modprobe af_key

Step 8. Start the Docker container

docker run \
    --name vpn-server \
    --env-file .env \
    --restart=always \
    -p 500:500/udp \
    -p 4500:4500/udp \
    -v /lib/modules:/lib/modules:ro \
    -d --privileged \
    hwdsl2/ipsec-vpn-server

Step 9. Set up your device

You need to set up a new L2TP type VPN connection on iOS or MacOS.

Your server will be your DigitalOcean droplet’s public IP which is visible on DigitalOcean’s dashboard.
The account will be what you set as VPN_USER
The secret will be the VPN_IPSEC_PSK’s value
The password is what is in the VPN_PASSWORD variable

How to receive push notifications from your rtorrent client

1. step:

Download pushover to your device, register, and create a new app on their site:
Name it as you like, eg. rtorrent. Pick a nice icon for the app.

You will need 2 keys for the next step:
– your user key
– and your app’s key

2. Set up a script which will handle the rtorrent’s events.

Ruby needs to be installed on your system.
Open your favourite editor and paste the following script:

#!/usr/bin/env ruby
require "net/https" url = URI.parse("https://api.pushover.net/1/messages.json")
req = Net::HTTP::Post.new(url.path) 
req.set_form_data({ :token => "YOUR_APP_KEY", :user => "YOUR_USER_KEY", :message => "start " + ARGV[0], }) 
res = Net::HTTP.new(url.host, url.port) 
res.use_ssl = true res.verify_mode = OpenSSL::SSL::VERIFY_PEER 
res.start {|http| http.request(req) }

Replace the two placeholders with your keys (YOUR_APP_KEY and YOUR_USER_KEY)
You would save it to /usr/local/bin (you need administrator privileges) and then make it executable:

chmod +x /usr/local/bin/rtorrent-pushover.rb

At this point, you can try it working with the following command:

/usr/local/bin/rtorrent-pushover.rb "test message"

3. Change your rtorrent config to call the notification script.

Add the following line to your ~/.rtorrent.rc file:

system.method.set_key = event.download.inserted_new,notify_me,"execute=/usr/local/bin/rtorrent-pushover.rb,$d.get_name="

If you would like, you can set up another notification for the finished torrents.
In this case, the only thing you should change is the “event.download.inserted_new” to “event.download.finished”.

If you’ve set up everything correctly, you should receive notifications about new torrents to your device.