-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_split_tunnle_owrt.sh
72 lines (57 loc) · 1.95 KB
/
setup_split_tunnle_owrt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Banner
echo "###############################################################"
echo "# ROUTE SETTING SCRIPT (c) 2024 suuhmer #"
echo "# ------------------------------------------------- #"
echo "# WG-Help : https://github.com/suuhm/wireguard-help #"
echo "###############################################################"
# Resolve the domain to an IP address
domain="your.wg-endpoint.com"
wgdev="wg"
wan_dev="eth0.23"
echo "Resolving the domain: $domain"
# Resolve IP using nslookup
ip=$(nslookup -type=A $domain | tail -n3 | grep Addr | cut -d " " -f2)
defip=$(ip r | grep -E $wan_dev | grep $ip | head -n1 | cut -d " " -f3)
# MAIN
if [ -z "$ip" ]; then
echo "Error: Could not resolve the domain $domain."
exit 1
else
echo "The IP address of $domain is: $ip"
fi
# Set the first default route (0.0.0.0/1)
echo "Setting default route 0.0.0.0/1 via $ip"
sudo ip route add 0.0.0.0/1 dev $wgdev
# Check if the route was successfully added
if [ $? -eq 0 ]; then
echo "Successfully set default route 0.0.0.0/1."
else
echo "Error: Failed to set default route 0.0.0.0/1."
exit 1
fi
# Set the second default route (128.0.0.0/1)
echo "Setting default route 128.0.0.0/1 via $ip"
sudo ip route add 128.0.0.0/1 dev $wgdev
# Check if the second route was successfully added
if [ $? -eq 0 ]; then
echo "Successfully set default route 128.0.0.0/1."
else
echo "Error: Failed to set default route 128.0.0.0/1."
exit 1
fi
# Add the specific route to the resolved IP
echo "Adding route to $ip via $defip"
ip r a $ip via $defip
# Sleep for 2 seconds to let the routes settle
sleep 2
# Delete the default route
echo "Deleting the default route"
ip r del default
# Print the current routing table
echo "Current routing table:"
ip route
echo "###############################################"
echo "# ROUTE SETTING COMPLETE #"
echo "###############################################"
exit 0;