ExpressVPN – Hourly random smart server reconnect (Linux)

This will force a disconnect, then a re-connect to a random server hourly. There are a few other options included. The original article can be sourced here.

Firstly open a terminal and type:

sudo crontab -e


This will open the CRON list where you can set script to run at certain intervals. In this case we want this event to happen on reboot.
Add at the bottom:

# MY CRON FILE
MAILTO=""
@reboot expressvpn connect


Now save the file by pressing [ctrl] + [X], then [Y], then [enter].
Now reboot your system.

sudo reboot


Once again in the terminal, type:

expressvpn status


This will tell you which server you are connected too. To make this switch locations automatically, type this in the terminal:

sudo nano /usr/sbin/smartexpressvpn.sh


Now paste this into the blank file:

expressvpn disconnect
expressvpn refresh

# Chose any of the below
# This will make you hop all over the world
VPN=$(expressvpn list all | tail -n +4 | awk '{ print $1 }' | shuf -n 1)

# This will make you hop around using recommended connections
# VPN=$(expressvpn list all | grep ‘\Y$’ | tail -n +4 | awk '{ print $1 }' | shuf -n 1)

# Use a custom list to connect to servers in the vicinity.
# VPN=$(cat /mnt/scripts/conf/expressvpn_EU_list.txt | tail -n +4 | awk '{ print $1 }' | shuf -n 1)

expressvpn connect $VPN


Save the file by pressing [ctrl] + [X], then [Y], then [enter].
Now we need to make this bash script file executable and we do that by running the following commands from terminal:

sudo chmod +x /usr/sbin/smartexpressvpn.sh


If you want to test the script, type this in the command line:

/usr/sbin/smartexpressvpn.sh


Check where you are connected by typing:

expressvpn status


This should have changed!
Now to make this run every hour of every day automagically!

sudo crontab -e


Modify the contents to:

# MY CRON FILE
MAILTO=""
@reboot expressvpn connect
0 */1 * * * /usr/sbin/smartexpressvpn.sh


Save the file by pressing [ctrl] + [X], then [Y], then [enter].

You’re done!
Every hour on the hour your expressvpn should change locations.
Thanks to Ubuntu 101 for the guide and the commenters for cleaning up the code.

😀

Leave a Reply

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