Skip to content

Instantly share code, notes, and snippets.

@oddmario
Last active December 19, 2024 19:54
Show Gist options
  • Save oddmario/22e48a66f9ec02c69e7930a6d8a65fa6 to your computer and use it in GitHub Desktop.
Save oddmario/22e48a66f9ec02c69e7930a6d8a65fa6 to your computer and use it in GitHub Desktop.
Stop routing all traffic through Cloudflare WARP and use it on-demand using the tunnel interface name instead

Stop routing all traffic through Cloudflare WARP and use it on-demand using the tunnel interface name instead

#!/bin/bash

# https://serverfault.com/questions/978701/setting-up-openvpn-as-an-interface-rather-than-routing-all-traffic-from-paid-vpn
# https://serverfault.com/questions/992624/vpn-client-doesnt-have-internet-connection

WARP_INTERFACE_NAME="CloudflareWARP"

# Get the IP address assigned to $WARP_INTERFACE_NAME
TUN_IP=$(ip -4 addr show $WARP_INTERFACE_NAME | grep -oP '(?<=inet\s)\d+(\.\d+){3}')

# Add the routing table entry if it doesn't exist
if ! grep -q "1000 vpn" /etc/iproute2/rt_tables; then
  echo "1000 vpn" >> /etc/iproute2/rt_tables
fi

# Delete any already existing rules that end with 'lookup vpn'
for rule in $(ip rule show | grep 'lookup vpn' | awk '{print $1}' | sed 's/://'); do
    ip rule del pref $rule
done

# disallow warp-cli from routing all the traffic through warp
warp-cli add-excluded-route 0.0.0.0/1
warp-cli add-excluded-route 128.0.0.0/1

warp-cli mode warp
warp-cli disconnect
warp-cli connect
sleep 5

# Delete any already existing routes in the vpn table
ip route flush table vpn

# Delete the default CloudflareWARP table routes
# change the `65743` part below if it's different for you (shouldn't be).
# you can get the table name that WARP uses by doing `ip route show table all` after connecting to WARP using `warp-cli connect`
ip route flush table 65743
ip -6 route flush table 65743

ip rule add from $TUN_IP/32 lookup vpn
ip route add default via $TUN_IP dev $WARP_INTERFACE_NAME table vpn

Example

curl --interface CloudflareWARP https://icanhazip.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment