The original post: /r/mullvadvpn by /u/The-BluWiz on 2024-08-05 05:07:42.
Quick Access
There are three things I do regularly with my VPN. Connect, Disconnect, and Multihop. I love that Mullvad VPN (aside from the main privacy reasons we choose them) includes a friendly CLI. For me, the GUI process for choosing multi-hop takes tooooo many steps. Here is a wrapper that should make it easier/faster to handle via CLI. Be sure to change the standard connect and multi-hop entry location to your main country (for latency reasons). Hope you find this useful!
!/bin/bash
==========
This script is a simple wrapper around the Mullvad VPN CLI to expedite regular commands
=======================================================================================
Function to connect to a Mullvad server in the United States
============================================================
connect\_vpn() {
# Set the relay location to the United States
mullvad relay set tunnel wireguard --use-multihop off
mullvad relay set location us
mullvad connect
if [ $? -eq 0 ]; then echo "Connected to a Mullvad VPN server in the United States." else echo "Failed to connect to a Mullvad VPN server in the United States." fi
}
Function to disconnect from the Mullvad VPN
===========================================
disconnect\_vpn() {
mullvad disconnect
if [ $? -eq 0 ]; then
echo "Disconnected from Mullvad VPN."
else
echo "Failed to disconnect from Mullvad VPN."
fi
}
Function to connect to a multi-hop VPN with an exit in Switzerland
==================================================================
multi\_vpn() {
# Enable Mult-hop
mullvad relay set tunnel wireguard --use-multihop on
mullvad relay set tunnel wireguard entry location us
# Connect to the suggested entry server
mullvad relay set location se
mullvad connect
if [ $? -eq 0 ]; then echo "Connected to the suggested entry server."
# Set the exit server to Switzerland
mullvad relay set location ch
# Reconnect to apply the new exit server
mullvad reconnect
if [ $? -eq 0 ]; then
echo "Multi-hop VPN setup with exit server in Switzerland."
else
echo "Failed to set the exit server to Switzerland."
fi
else echo "Failed to connect to the suggested entry server." fi
}
Function to report the status of the Mullvad VPN connection
===========================================================
vpn\_status() {
status=$(mullvad status -v)
if [ $? -eq 0 ]; then echo "Mullvad VPN status:" echo "$status" else echo "Failed to retrieve Mullvad VPN status." fi
}
Main script logic to handle the command-line arguments
======================================================
case "$1" in
connect|c)
connect\_vpn
;;
disconnect|d)
disconnect\_vpn
;;
multi|m)
multi\_vpn
;;
status|s)
vpn\_status
;;
\*)
cat <<EOF
Usage: mvpn {connect|c|disconnect|d|multi|m|status|s}
Examples:
mvpn connect
mvpn d
mvpn m
mvpn status
EOF
exit 1
esac