Browse Source

feat: bypass the private network automatically

master
dnomd343 3 years ago
parent
commit
99247f7c8f
  1. 39
      load.sh
  2. 12
      tproxy.sh

39
load.sh

@ -191,7 +191,7 @@ chmod +x $ASSET_DIR/update.sh
}
load_network_ipv4(){
cat>"$NETWORK_DIR/ipv4"<<EOF
cat>"$NETWORK_DIR/interface/ipv4"<<EOF
ADDRESS=
GATEWAY=
FORWARD=true
@ -199,7 +199,7 @@ EOF
}
load_network_ipv6(){
cat>"$NETWORK_DIR/ipv6"<<EOF
cat>"$NETWORK_DIR/interface/ipv6"<<EOF
ADDRESS=
GATEWAY=
FORWARD=true
@ -219,7 +219,7 @@ do
[ "$row" != "$temp" ] && ipv4_gateway=$temp
temp=${row#FORWARD=}
[ "$row" != "$temp" ] && ipv4_forward=$temp
done < $NETWORK_DIR/ipv4
done < $NETWORK_DIR/interface/ipv4
[ -n "$ipv4_address" ] && eval "ip -4 addr add $ipv4_address dev eth0"
[ -n "$ipv4_gateway" ] && eval "ip -4 route add default via $ipv4_gateway"
if [ -n "$ipv4_forward" ]; then
@ -237,7 +237,7 @@ do
[ "$row" != "$temp" ] && ipv6_gateway=$temp
temp=${row#FORWARD=}
[ "$row" != "$temp" ] && ipv6_forward=$temp
done < $NETWORK_DIR/ipv6
done < $NETWORK_DIR/interface/ipv6
[ -n "$ipv6_address" ] && eval "ip -6 addr add $ipv6_address dev eth0"
[ -n "$ipv6_gateway" ] && eval "ip -6 route add default via $ipv6_gateway"
if [ -n "$ipv6_forward" ]; then
@ -247,18 +247,18 @@ if [ -n "$ipv6_forward" ]; then
eval "sysctl -w net.ipv6.conf.all.forwarding=0"
fi
fi
if [ -s "$NETWORK_DIR/dns" ]; then
cat /dev/null > /etc/resolv.conf
while read -r row
do
echo "nameserver $row" >> /etc/resolv.conf
done < $NETWORK_DIR/dns
fi
}
init_dns(){
cat /dev/null > /etc/resolv.conf
while read -r row
do
echo "nameserver $row" >> /etc/resolv.conf
done < $NETWORK_DIR/dns
}
load_ipv4(){
cat>$XRAY_DIR/expose/segment/ipv4<<EOF
127.0.0.0/8
169.254.0.0/16
224.0.0.0/3
EOF
@ -266,10 +266,9 @@ EOF
load_ipv6(){
cat>$XRAY_DIR/expose/segment/ipv6<<EOF
::1/128
FC00::/7
FE80::/10
FF00::/8
fc00::/7
fe80::/10
ff00::/8
EOF
}
@ -295,7 +294,9 @@ cp $ASSET_DIR/*.dat $XRAY_DIR/asset/
[ ! -s "$XRAY_DIR/expose/segment/ipv4" ] && load_ipv4
[ ! -s "$XRAY_DIR/expose/segment/ipv6" ] && load_ipv6
[ -f "$NETWORK_DIR/ignore" ] && exit
[ ! -s "$NETWORK_DIR/ipv4" ] && load_network_ipv4
[ ! -s "$NETWORK_DIR/ipv6" ] && load_network_ipv6
mkdir -p $NETWORK_DIR/interface
[ -s "$NETWORK_DIR/dns" ] && init_dns
[ -f "$NETWORK_DIR/interface/ignore" ] && exit
[ ! -s "$NETWORK_DIR/interface/ipv4" ] && load_network_ipv4
[ ! -s "$NETWORK_DIR/interface/ipv6" ] && load_network_ipv6
init_network

12
tproxy.sh

@ -4,6 +4,12 @@ sh /etc/xray/load.sh
ip rule add fwmark 1 table 100
ip route add local 0.0.0.0/0 dev lo table 100
iptables -t mangle -N XRAY
ip -4 addr | grep -w "inet" | awk '{print $2}' > /ipv4_range
while read -r segment
do
eval "iptables -t mangle -A XRAY -d $segment -j RETURN"
done < /ipv4_range
rm -f /ipv4_range
while read -r segment
do
eval "iptables -t mangle -A XRAY -d $segment -j RETURN"
@ -15,6 +21,12 @@ iptables -t mangle -A PREROUTING -j XRAY
ip -6 rule add fwmark 1 table 106
ip -6 route add local ::/0 dev lo table 106
ip6tables -t mangle -N XRAY6
ip -6 addr | grep -w "inet6" | awk '{print $2}' > /ipv6_range
while read -r segment
do
eval "ip6tables -t mangle -A XRAY6 -d $segment -j RETURN"
done < /ipv6_range
rm -f /ipv6_range
while read -r segment
do
eval "ip6tables -t mangle -A XRAY6 -d $segment -j RETURN"

Loading…
Cancel
Save