← Back to Home

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

Step 1. Generate .sh in NetRoute Pro

  1. Open the target website in Chrome
  2. Click the NetRoute Pro icon in your extensions
  3. Select the Linux platform
  4. Set the gateway to your VPN interface IP (for example 10.8.0.1)
  5. Choose aggregation mask (recommended /24)
  6. Click Analyze Website
  7. Download the result as routes.sh
Tip: enable RIPE BGP optimization to get announced BGP prefixes instead of individual IPs — more stable when CDNs rotate addresses.

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
Note: @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