Skip to content

Instantly share code, notes, and snippets.

@atomlab
Last active September 11, 2025 14:57
Show Gist options
  • Select an option

  • Save atomlab/674cf1fbcec6e5642c78e7c2e613bb19 to your computer and use it in GitHub Desktop.

Select an option

Save atomlab/674cf1fbcec6e5642c78e7c2e613bb19 to your computer and use it in GitHub Desktop.
Discord Voice Servers Routing via tun2socks on macOS
#!/bin/bash
# Universal script for managing routes on macOS
#
# Usage:
# ./routes.sh file.json # show routes
# ./routes.sh apply file.json [file2...] # apply routes from JSON
# ./routes.sh delete <gateway> # delete all routes for a gateway
#
# JSON format:
# [
# {"hostname":"example.discord.gg","ip":"66.22.244.170"},
# {"hostname":"example2.discord.gg","ip":"66.22.244.155"}
# ]
DEFAULT_GATEWAY="198.18.0.1"
mode="show"
if [[ "$1" == "apply" ]]; then
mode="apply"
shift
elif [[ "$1" == "delete" ]]; then
mode="delete"
shift
fi
if [[ "$mode" == "show" || "$mode" == "apply" ]]; then
if [[ $# -lt 1 ]]; then
echo "Usage: $0 [apply] file1.json [file2.json ...]"
exit 1
fi
for file in "$@"; do
jq -r --arg gw "$DEFAULT_GATEWAY" '
.[] |
"# \(.hostname)\n" +
"sudo route -n add -net \(.ip)/32 \($gw)"
' "$file" |
while read -r line; do
if [[ "$mode" == "apply" ]]; then
if [[ "$line" =~ ^sudo ]]; then
echo "Applying: $line"
eval "$line"
else
echo "$line"
fi
else
echo "$line"
fi
done
done
elif [[ "$mode" == "delete" ]]; then
if [[ $# -lt 1 ]]; then
echo "Usage: $0 delete <gateway>"
exit 1
fi
GATEWAY="$1"
echo "Deleting all routes via $GATEWAY..."
# Get the list of routes where the Gateway matches, but Destination != Gateway
netstat -rn | awk -v gw="$GATEWAY" '$2 == gw && $1 != gw {print $1}' | while read -r DEST; do
echo "Deleting route: $DEST via $GATEWAY"
sudo route -n delete -net "$DEST" "$GATEWAY"
done
fi

Discord Voice Servers Routing via tun2socks on macOS

This guide explains how to route all Discord voice server traffic through tun2socks using a list of IP addresses from discord-voice-ips.


Prerequisites


Setup tun2socks

tun2socks -device utun123 -proxy socks5://127.0.0.1:7897
sudo ifconfig utun123 198.18.0.1 198.18.0.1 up

The IP 198.18.0.1 will be used as the gateway for routing Discord traffic.


Download and Prepare Discord IPs

git clone https://github.com/GhostRooter0953/discord-voice-ips.git
cd discord-voice-ips/amnezia
jq -s 'add | unique_by(.ip)' amnezia-*.json > merged.json

Manage Routes with gen_routes.sh

Make sure the script is executable:

chmod +x gen_routes.sh

Quick Command Table

Step Command Description
Preview routes ./gen_routes.sh merged.json Shows which routes will be applied
Apply routes ./gen_routes.sh apply merged.json Adds all Discord voice server IPs via tun2socks gateway
Delete routes ./gen_routes.sh delete 198.18.0.1 Removes all routes pointing to the tun2socks gateway, skipping destination=gateway

Notes

  • The merged.json file contains all Discord voice server IPs with duplicates removed.
  • Update the JSON files periodically to keep routing current.
  • Verify routes with netstat -rn before deleting or modifying them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment