A quick way to check VPN connection speed using SSH
Greetings!

A short note about how to check Download/Upload speed using SSH on Linux. This kind of diagnostics is useful when analyzing issues related to data transfer over secure communication channels, such as VPN.

The demonstration in this article was performed in Linux Mint Debian Edition 6 (Debian 12). Everything will work the same way in other Linux distributions.

Preparation

To do this we’ll need:

Of the list above, only the pv utility needs to be installed (an extremely useful tool). It’s available in the standard repositories:

BASH
sudo apt update && sudo apt install pv
Click to expand and view more

Checking the speed

In my example, the username on the remote server is ivan and the host address is vpn.r4ven.me (an IP address can be specified as well). Replace these values in the commands with your own.

Disable the VPN and check the download speed with the command:

Be careful with the dd command! Make sure you don’t accidentally overwrite important data.

BASH
ssh ivan@vpn.r4ven.me dd if=/dev/zero bs=1M count=1024 | pv | cat > /dev/null
Click to expand and view more

To stop the check, use the Ctrl+c key combination.

And now the upload speed:

BASH
dd if=/dev/zero bs=1M count=1024 | pv | ssh ivan@vpn.r4ven.me 'cat > /dev/null'
Click to expand and view more

Then enable the VPN and run both commands again. If the speed without tunneling the traffic is significantly higher, this means the factors affecting the data transfer speed lie on the server itself where the VPN is deployed. If the speed is low in both cases, the issue is likely with the channel to the server.

What these commands actually do

1st command (Download)

2nd command (Upload)

This way a synthetic check is performed that simply utilizes the channel without creating any files.

If the route to the remote server doesn’t go through the tunnel when the VPN is enabled

In this situation, try temporarily adding a route manually, and remove it after the checks are done. But only if the remote server is not the VPN server itself!

Here’s an example of the commands:

BASH
# check the route
ip route get <IP_address>

# add a route through the tun0 network interface
ip route add <IP_address> dev tun0

# remove the previously added route
ip route del <IP_address> dev tun0
Click to expand and view more

Where <IP_address> is the server’s IP address, and tun0 is the virtual network interface of your tunnel connection on the local machine. Replace the values with your own. You can find them out using the commands:

BASH
# ip address
ping -c1 vpn.r4ven.me | head -1 | awk -F'[()]' '{print $2}'

# list of interfaces
ip address
Click to expand and view more

Further reading

Copyright Notice

Author: Ivan Cherniy

Link: https://r4ven.me/en/networking/bystryj-sposob-proverit-skorost-vpn-soedineniya-s-pomoshhyu-ssh/

License: CC BY-NC-SA 4.0

Blog materials may be used with attribution to the author and source, for non-commercial purposes, and under the same license.

Start searching

Enter keywords to search articles

↑↓
ESC
⌘K Shortcut