Scripts for automatic connection to free VPNs (autovpn2 and autovpn3)

9 May 2023 7 minutes Author: D2-R2

Free VPNs with easy connection

autovpn is a tool to automatically connect to a random VPN in a country of your choice. It uses openvpn to connect to the server obtained from VPN Gate. The essence of its work is as follows: it downloads a list of free VPN servers, searches for a VPN server from the country you specified and connects to it. As a result, all your traffic starts to go through a VPN – it is a very fast and automatic way to change your IP and bypass blocking. Due to the way VPNs work, all traffic (not just web browser requests) goes through the VPN network, so if you use network tools, they will also change their IP. The author of autovpn removed the source code, as a result Rupert Edwards (author of TorIptables2) rewrote the autovpn code and named the program autovpn2. The program does all the same. The autovpn feature allows users to securely connect two systems by creating a virtual point-to-point connection using the tunneling method. It helps in easy and quick access to files and folders.

Once the connection is established, the user’s computer or mobile device can be connected to the Internet as usual through secure VPN servers. Communication then becomes secure as all traffic is encrypted and securely routed. The provider’s route was completely bypassed. autovpn is convenient and easy to use, as it allows you to access your work resources even if you are away from the office. Setting up autovpn is simple and most of the configuration is done automatically. If you are interested in learning how to set up and use autovpn for remote connection, take a few minutes and read this.

Automatic connection to free VPNs with autovpn2

autovpn2 is a VPN Gate client (based on OpenVPN) for Linux, 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 in the system through VPN (not only web browser traffic, as some plugins do)
  • uses free VPNs
  • the resulting VPN settings are not tied to anything – you do not need to register, enter your email or perform any similar actions
  • everything is done automatically: searching for free VPN servers, getting settings, launching the OpenVPN client with the received settings

The autovpn2 program is very easy to use, it allows you to quickly, without manual configuration of the OpenVPN client, connect to a VPN and hide your IP address from visited sites, as well as bypass blocking. Since OpenVPN routes all traffic through the VPN server, any tools you use will go online through the VPN server. The program can be run without options:

In this case, it will search 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 searching for a VPN server from Japan and connecting to it automatically:

To check your IP and what country you belong to, you can use this online service or any other. If immediately after launching the program quickly terminates without connecting to a VPN, it may mean:

  • you entered the country code incorrectly
  • there is no VPN from the selected country

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

If the program output ended with a line containing «Initialization Sequence Completed», it means that the connection has been successfully established and you are now connected to the network via VPN:

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

The autovpn2 script asks whether to try another VPN? If you want to try another VPN, press “y“, if you want to exit, press “n“.

How to change the default country in autovpn2

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

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

autovpn3 – additional functions for managing connections to free VPNs

As I have already written, in my opinion, autovpn could have more functions. Additional features in autovpn3 compared to autovpn2:

  • the VPN list is cached and reloaded only when it is really needed, so reconnecting to a new server is much faster;
  • you can specify the country to search for VPN servers in it, or use a VPN from a randomly selected country
  • 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 VPN via proxy (as well as downloading the VPN list via proxy) – this is even better for anonymity
  • written in Bash, you will not have problems with Python 2, does not require compilation
  • you can save a list of VPN servers and use it without reloading
  • fast change of VPN server

Installation instructions and the script itself are on this page:

The program has already made the optimal setting suitable for most users, so you can just start working with the script:

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

As the first setting you can choose the country where the VPN server should be from, for example, JP, KR, US, TH. That is a two-letter code, the letters must be large. If you leave it blank, 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 specified in the code.

If you do not like the selected VPN server, press Ctrl+c and the program will offer to try again with another VPN. In this case, the list of servers is not reloaded – the same one is used. But if you close the program and start it again, the list of VPN servers will be loaded. If this suits you, then 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 loaded again regardless of the settings. When you restart the computer, the list is deleted in any case:

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

The script selects a random VPN server from the entire list (if the country is not specified) or from the list for the specified country. If this suits you, then set the value to 0, if you want the first server to always be used, then set the value to 1. Perhaps the performance of the first server is better (better speed, less pings, etc. – actually, I did not check it):

Path to the file where the downloaded list of VPN servers is stored. 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 want (makes sense with “useSavedVPNlist=1“):

In the next article, we will connect to a VPN through a proxy and through the Tor network. In particular, we will use autovpn3 to connect via proxy and Tor to free VPN servers.

Other related articles
Found an error?
If you find an error, take a screenshot and send it to the bot.