VPN Gate for linux – ubuntu simple script

SoftEther VPN, created at the University of Tsukuba, is an open-source and multi-platform software (client and server) that supports many protocols: SSL VPN, L2TP/IPsec, OpenVPN and Microsoft Secure Socket Tunneling Protocol. It was released using the GPLv2 license on January 4, 2014.
VPN Gate is a plugin for SoftEther VPN that you can use to connect to VPN servers started by volunteers using SoftEther VPN servers.

vpn-gate
On the VPN Gate page you’ll find login tutorials for Windows, Mac, iPhone/iPad, and Android.
Because for linux (ubuntu 16.04) I do not have a decent client to connect to VPN Gate, I had to create a simple simple client for linux terminal.

What do you need to use VPN Gate in linux?

1. openvpn
Install it using the command:
sudo apt install openvpn
You do not need any special settings at this step

2. resolvconf
If it’s not already installed on your system, install it with the command:
sudo apt install resolvconf
To use the Internet with the script below, you’ll need to edit the configuration file /etc/resolvconf/resolv.conf.d/head. You have to add the following command at the end the “nameserver 8.8.8.8” line (explained here)
sudo nano /etc/resolvconf/resolv.conf.d/head
Add the line:
nameserver 8.8.8.8
Ctrl + o (to save)
Ctrl + x (for exit)
My file should look like this:

[email protected]:~$ cat /etc/resolvconf/resolv.conf.d/head
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
[email protected]:~$

3. Linux script for VPN Gate

vpn-gate terminal

Create a new folder on Desktop (or elsewhere) with any name, like “vpngate”:

cd ~
cd Desktop
mkdir vpngate
cd vpngate

Create a file with the name script.sh (or any other name) and add this text to the file you just created:

#! /bin/bash
read -p "Download a new .csv file? (y/n)" -n 1 -r
echo    
if [[ $REPLY =~ ^[Yy]$ ]]
	then
	echo "Start wget"
	if wget -O test.csv http://www.vpngate.net/api/iphone/
		then
			rm iphone.csv;
			mv test.csv iphone.csv;
			echo "wget OK"
		else
			rm test.csv; 
			echo "wget Failure"
		fi
	fi
awk -F ',' 'NR>2&&NR<99{print $7," - ",$6}' iphone.csv| sort | uniq -c echo "------------------------------------------------" read -r -p "Choose country code (ex.: US) " response cod=${response,,} cod=`echo $cod | tr [a-z] [A-Z]` OLDIFS=$IFS IFS="," while read a b c d e f g h i j k l m n o do if [[ $a =~ .*vpn.* ]] && ! [[ $a =~ .*_.* ]] && [[ $b =~ .*..* ]] then if [[ "$cod" == "$g" ]] then echo IP :$b server: $a rm connect.vpn echo $o | base64 --decode >> connect.vpn
			sudo openvpn --script-security 2 --config connect.vpn 
			sudo killall -9 openvpn
			echo Wait 5 sec.
			sleep 5s
		fi
		indice=$((indice+1))
	fi

 done < "iphone.csv"
 IFS=$OLDIFS
sudo killall -9 openvpn
exit

(select the script text above with the cursor, copy it with Right Click -> Copy)
nano script.sh
Shift + Insert (paste text from clipboard)
Ctrl + o (save)
Ctrl + x (exit)
chmod + x server.sh (execution rights)

Or you can download the VPN Gate login script from here.

Now everything is ready.

How does the login VPN Gate script work in linux?
The script starts with these commands:
Ctrl + Alt + t (open a terminal)
cd ~ (go to your personal directory)
cd Desktop/vpngate (go to Desktop/vpngate directory)
sudo ./server.sh (start the script)

You will be asked whether you want to download a new .csv file. This linux script uses iPhone API from VPN Gate. It is a large file with openvpn addresses that changes quite often (like once every 2 hours) and contains several configuration files for openvpn. It is recommended that you download a new file from time to time to have new vpn addresses. You need to press “Y” if you want to.
The script will download a file with the new address (about 1.76 MB), process it, and display your list of countries and the number of VPN addresses for each.

To choose a country you can type the country code (eg. US for United States) and then press Enter.
If you’re not connected, you can press Ctrl+C to interrupt the connection or press Ctrl+C twice to interrupt the connection and exit the script.
The script will display various information on the screen. If the last line is “Initialization Sequence Completed”, it means you are connected.
Once you’re logged in, check your IP address, DNS and location on https://www.iptest.club.
To change the server (from the same country), press Ctrl+C. To change the country press Ctrl+C twice (the script will disconnect and stop) and run the sudo ./script.sh command again.

VPN Gate is not perfect because it is a free VPN. VPN Gate is very good when you’re in a hurry, but you do not have to rely on it alone. Speed is often quite lacking and some servers do not work at all, or you can be disconnected while browsing the internet without realizing it and thus expose your real IP address and your actual location.
For a stable and secure connection, we recommend using NordVPN services.

Leave a Reply

Your email address will not be published. Required fields are marked *