Add Routes on Linux via .sh Script
NetRoute Pro generates a plain Bash script with ip route add commands. Apply it with one command for instant routes. Persistence requires one extra step depending on your distro.
Prerequisites
iproute2(preinstalled on virtually all modern distros — Ubuntu, Debian, Fedora, Arch, etc.)- Root/
sudoaccess - A configured VPN interface (WireGuard, OpenVPN, IKEv2, etc.) that is already up
- NetRoute Pro Chrome extension installed
Step 1. Generate .sh in NetRoute Pro
- Open the target website in Chrome
- Click the NetRoute Pro icon in your extensions
- Select the Linux platform
- Set the gateway to your VPN interface IP (for example
10.8.0.1) - Choose aggregation mask (recommended
/24) - Click Analyze Website
- Download the result as
routes.sh
Step 2. Apply the script
chmod +x routes.sh
sudo bash routes.sh
Routes are applied immediately — but only until the next reboot or until your VPN interface goes down. For permanence, see Step 3.
Step 3. Make routes persistent
Pick one of the three options below, depending on how your system manages networking.
systemd-networkd
If your distro uses systemd-networkd (default on many minimal installs, Arch, server distros), create a drop-in file:
sudo mkdir -p /etc/systemd/network/10-vpn.network.d
sudo nano /etc/systemd/network/10-vpn.network.d/routes.conf
Add one [Route] block per subnet:
[Route]
Destination=104.21.32.0/24
Gateway=10.8.0.1
[Route]
Destination=172.67.182.0/24
Gateway=10.8.0.1
Apply:
sudo systemctl restart systemd-networkd
NetworkManager dispatcher
If you use NetworkManager (Ubuntu desktop, Fedora Workstation, most laptops), save a dispatcher hook:
sudo nano /etc/NetworkManager/dispatcher.d/99-vpn-routes
Example content — checks that the triggering interface is your VPN device and re-runs the ip route add commands:
#!/bin/bash
# $1 = interface name, $2 = action
if [ "$1" = "<your-vpn-interface>" ] && [ "$2" = "up" ]; then
ip route add 104.21.32.0/24 via 10.8.0.1
ip route add 172.67.182.0/24 via 10.8.0.1
fi
Make it executable:
sudo chmod +x /etc/NetworkManager/dispatcher.d/99-vpn-routes
@reboot cron (simplest, universal)
Works on any distro regardless of network stack. Move the generated script to a stable location and schedule it at boot:
sudo mv routes.sh /usr/local/bin/routes.sh
sudo chmod +x /usr/local/bin/routes.sh
sudo crontab -e
Add the line:
@reboot /usr/local/bin/routes.sh
@reboot runs before your VPN may be fully up. If you hit Network is unreachable, add a short sleep at the top of the script or trigger it from your VPN's post-up hook instead.
Verify
Check that the routes are in the kernel table:
ip route show | grep 10.8.0.1
All added subnets should appear, bound to your VPN gateway.
Rollback
To remove the routes, generate a reverse script by replacing add with del in routes.sh and run it as root:
sed 's/ip route add/ip route del/' routes.sh > unroutes.sh
sudo bash unroutes.sh
Common issues
Network is unreachable
Your VPN interface is down. Check with:
ip link show
Bring the interface up before running the script.
RTNETLINK answers: File exists
The route is already present. Remove it first:
sudo ip route del <subnet>
Then re-run the script.
Permission denied
ip route add needs root. Always invoke with sudo.
References
Ready to try?
NetRoute Pro — a free Chrome extension to generate routes from any website.
Install Extension