autovpn2 and autovpn3 - scripts to automatically connect to a free VPNs

Free VPNs with easy setup

I already talked about the autovpn program in the article “Free easy way to hide IP in Linux”. The essence of its work is as follows: it downloads a list of free VPN servers, searches them for VPN servers from the country you specified, and connects to it. As a result, all your traffic starts going through the VPN - this is a very fast and automatic way to change your IP and bypass blocking.

Due to the peculiarities of VPN operation, all traffic (not just web browser requests) goes through the VPN network, that is, if you use network tools, they will also change their IP.

The author of autovpn removed the source code, and as a result Rupert Edwards (the author of TorIptables2) rewrote the autovpn code and named the program autovpn2. The program does the same thing.

In this article, we will introduce autovpn2.

Looking at how autovpn2 works I have always wondered:

  • is it really necessary to re-download the file with the list of VPN servers every time?
  • why is it necessary to indicate the country, why the program cannot choose just any VPN from the list?
  • why there is no support for connecting to a VPN through a proxy (as well as downloading a VPN list through a proxy) - this is even better for anonymity
  • why is autovpn2 using Python 2? Yes, due to the lack of dependencies, autovpn2 works quietly even on Python 2 without modules (as it is present in Kali Linux). But there may come a time when Python 2 will be completely removed from distributions.

In general, I took all these notes into account and once again rewrote autovpn (this time in Bash) and called it autovpn3. I will also share the script in this article.

Auto connect to free VPN with autovpn2

autovpn2 is a VPN Gate client (based on OpenVPN) for Linux that connects you to a random free VPN in the country of your choice, indicated by a two-letter country code.

The program can help you hide your real IP address from the sites you visit, as well as open sites that are blocked in your country.

Key features of the program:

  • redirects all traffic on the system through the VPN (not just web browser traffic like some plugins do)
  • uses free VPNs
  • the resulting VPN settings are not tied to anything - you do not need to register, enter your e-mail or perform any similar actions
  • everything is done automatically: search for free VPN servers, get the settings, launch the OpenVPN client with an indication of the received settings

The autovpn2 program is very easy to use, it allows you to quickly connect to a VPN and hide your IP address from visited sites without manually configuring an OpenVPN client, as well as bypass blocking.

Since OpenVPN redirects all traffic through the VPN server, any tools you use will go online through the VPN server.

The program can be run without options:

sudo autovpn2

In this case, a search will be performed for free VPN servers from the US (USA).

You can specify a two-letter country code (ISO 3166-2), in this case a VPN from the specified country will be selected.

An example of finding a VPN server from Japan and automatically connecting to it:

sudo autovpn2 JP

To check your IP and which country it belongs to, you can use this online service or any other.

If, immediately after starting, the program quickly exits without connecting to a VPN, this may mean:

  • you entered the wrong country code
  • no VPN from the selected country

You can find a list of free VPN servers on this page:

If the output of the program ends with a line containing “Initialization Sequence Completed”, then this means that the connection has been successfully established and now you are accessing the network via VPN:

To stop the VPN press CTRL+c, a message will be displayed:

[autovpn2] try another VPN? (y/n)

The autovpn2 script asks if it should try another VPN?

If you want to try another VPN, then press “y”, if you want to exit, then press “n”.

How to change the default country in autovpn2

If you do not specify a country, then VPN servers in the USA will be searched by default. You can change this by opening the file. If you moved the script to $PATH, then open it like this:

sudo gedit /usr/local/bin/autovpn2

You need to change lines 21 and 45 to indicate the two-letter country code of the desired country (in capital letters) instead of “US”.

autovpn3 - additional features for managing free VPN connections

As I already wrote, in my opinion, there could be more functions in autovpn.

Additional features in autovpn3 compared to autovpn2:

  • the VPN list is cached and downloaded again only when it is really needed, thanks to this, reconnection to a new server is much faster;
  • you can specify a country to search for VPN servers in it, or use a VPN from a randomly selected country
  • added support for connecting to a VPN through a proxy (as well as downloading a VPN list through a proxy) - it's even better for anonymity
  • written in Bash, you will have no problems with Python 2, does not require compilation
  • you can save the list of VPN servers and use it without re-downloading
  • quick change of VPN server

Installation instructions and the script itself on this page:

The program has already got an optimal setting suitable for most users, so you can simply run the script without tuning it:

sudo ./

Let's look at the settings (they are right at the beginning of the script):


In the first setting, you can select the country from which the VPN server should be, for example, JP, KR, US, TH. That is, a two-letter code, the letters must be in uppercase. If you leave it blank, then a VPN server from any country will be selected. That is, the script does not accept the country code as an option - the country must be written in the code.

If you do not like the selected VPN server, then press Ctrl+c and the program will offer to try again with another VPN. In this case, the list of servers is not downloaded again - the same server is used. But if you close the program and start it again, the list of VPN servers will be downloaded again. If this suits you, set the value to 0. If you want the old list to be used when the program is restarted, then set the value to 1. If the list is missing, it will be downloaded again regardless of the settings. When you restart your computer, the list is deleted in any case:


We will consider all the proxy settings in another article, where we will connect to a free VPN through a proxy, including through the Tor network:

proxyType='socks' # socks or http

The script selects a random VPN server from the entire list (if no country is specified) or from the list for the specified country. If this suits you, then set the value to 0, if you want to always use the first server, then set the value to 1. Perhaps the score of the first server are higher (better speed, less ping, etc. - in fact, I haven't tested it):


The path to the file where the downloaded list of VPN servers is saved. By default, it is stored in the /tmp/ folder, which is cleared every time the computer is restarted. You can choose a more stable location if you like (makes sense with “useSavedVPNlist=1”):


In the next article, we will be connecting to a VPN through a proxy and over the Tor network. Including, we will use autovpn3 to connect through a proxy and Tor to free VPN servers.

Recommended for you:

One Comment to autovpn2 and autovpn3 - scripts to automatically connect to a free VPNs

  1. Nh3092 says:

    Hi, thanks for the autovpn3 it's useful for me, just little improve is possible to sort the higher line quality and select the server to use based on speed, not by index list. Hopefully this will get more speed than the index sort one

    How to do it? 


Leave a Reply

Your email address will not be published.