LibreSpeed
It’s useful to have an internal speed test. Browser based is best for end-users.
The two main choices are LibreSpeed or OpenSpeedTest. The former is generally preferred for it’s simplicity.
Preparation
Install a minimal Debian instance by using the netinst image, de-selecting the desktop system at the top, while adding ‘common system tools’ near the bottom.
Installation
You can use an Apache server with PHP, or a binary service. If you have a simple use case, the latter has fewer moving parts
Binary
You’ll need the need the web/assets folder and the pre-compiled binary. Let’s use the rust version with the theory being it’s safer and faster. (though in casual testing, this is debatable)
Look for the latest release at:
https://github.com/librespeed/speedtest-rust/releases
# Download the source and extract the assets folder
wget https://github.com/librespeed/speedtest-rust/archive/refs/tags/v1.3.8.tar.gz
tar --strip-components=1 -xzf v1.3.8.tar.gz speedtest-rust-1.3.8/assets/
# Download the binary, extract and make executable
wget https://github.com/librespeed/speedtest-rust/releases/download/v1.3.8/librespeed-rs-x86_64-unknown-linux-gnu.tar.xz
tar xf librespeed-rs-x86_64-unknown-linux-gnu.tar.xz
chmod +x librespeed-rs
# Disable the stored results database
sed -i 's/database_type="sqlite"/database_type="none"/' configs.toml
# Change the labels in the page
sed -i 's/Your server name here/speedtest.your.org/' assets/servers_list.js
sed -i 's/LibreSpeed Example/speedtest.your.org/' assets/index.html
# Launch the server and test
./librespeed-rs
firefox http://localhost:8080
Assuming that works as intended, you can create a service file and enable it.
Web Server
You might need to do more, such as run some code before letting people hit your speed test. Use the PHP version for this.
# Add the prerequisites. PHP is enabled for apache by default
apt install apache2 php openssl
# Look for the latest release at:
firefox https://github.com/librespeed/speedtest/releases
# Download, extract and copy a few things to your web folder
wget https://github.com/librespeed/speedtest/archive/refs/tags/5.4.1.tar.gz
tar xzf 5.4.1.tar.gz
cd speedtest-5.4.1
sudo cp -r index.html speedtest.js speedtest_worker.js favicon.ico backend /var/www/html/
LAN Speeds
Sometimes you want to compare LAN/WAN speeds across multiple networks but want to keep just a single URL. Do this by using multiple (or one server with multiple interfaces) and use a .php to redirect users to the right place based on their IP.
Add A Redirecting Page
Create a new index page.
sudo vi /var/www/html/index.php
<!DOCTYPE html>
<html>
<head>
<?php
# Extract the client's IP address
$chunks = explode('.', $_SERVER['REMOTE_ADDR']);
# Assume we have an interface on the clients LAN at .55 and
# redirect them to it.
$network = "$chunks[0].$chunks[1].$chunks[2].55";
# Use the .replace method so the next request client has a
# referring page, used later on.
echo "<script>";
echo "window.location.replace(\"http://$network/speed.html\")";
echo "</script>";
?>
</head>
</html>
Adjust apache so index.php takes precedence.
sudo vi /etc/apache2/mods-available/dir.conf
# Move index.php to be right at the front.
DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm
# Reload so changes take affect
sudo systemctl reload apache2.service
Modify The Main Page
Some users will bookmark the speed test page. If they change subnets and use the old bookmark, this will no longer be a LAN test.
Let’s copy the delivered index.html to a new page that includes referrer check. This makes sure they hit the main URL first and get redirected every time. (note the script above refers to the page “speed.html” so let’s use that)
sudo cp /var/www/html/index.html /var/www/html/speed.html
sudo vi /var/www/html/speed.html
<script>
// Redirects to the main URL in case somebody books the wrong subnet page
correct_referrer="http://speedtest.marietta.edu/";
actual_referrer=document.referrer;
if (actual_referrer != correct_referrer) window.location.replace(correct_referrer);
</script>
Special Asymmetric Routing Bonus
If you added interfaces to a server to test LAN connections, your clients will connect to the WAN IP address. But the server has an interface on the same network as the client, so it replies using that. The client will drop these unexpected replies.
You need to a routing policy so the server responds back on the same interface the client sent it’s request to.
Note: We are justing using table ID 1, and not bothering to create a rt_tables file to give it a custom name.
# On the WAN interface, 192.168.1.5 used below.
allow-hotplug eth0
iface eth0 inet static
address ...
gateway ...
dns-nameservers ...
up ip rule add from 192.168.1.5 table 1 prio 1
up ip route add default via 192.168.1.5 dev eth0 table 1
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.