|
@@ -15,6 +15,25 @@ fi
|
|
|
|
|
|
|
|
function check_depend {
|
|
function check_depend {
|
|
|
case "$mode" in
|
|
case "$mode" in
|
|
|
|
|
+ v2ray_global)
|
|
|
|
|
+ modprobe xt_TPROXY &>/dev/null || { echo "Error: xt_TPROXY module is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ command -v ip &>/dev/null || { echo "Error: iproute2 is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ command -v dnsmasq &>/dev/null || { echo "Error: dnsmasq is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ ;;
|
|
|
|
|
+ v2ray_gfwlist)
|
|
|
|
|
+ modprobe xt_TPROXY &>/dev/null || { echo "Error: xt_TPROXY module is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ command -v ip &>/dev/null || { echo "Error: iproute2 is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ command -v dnsmasq &>/dev/null || { echo "Error: dnsmasq is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ command -v ipset &>/dev/null || { echo "Error: ipset is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ command -v perl &>/dev/null || { echo "Error: perl is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ ;;
|
|
|
|
|
+ v2ray_chnroute)
|
|
|
|
|
+ modprobe xt_TPROXY &>/dev/null || { echo "Error: xt_TPROXY module is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ command -v ip &>/dev/null || { echo "Error: iproute2 is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ command -v dnsmasq &>/dev/null || { echo "Error: dnsmasq is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ command -v ipset &>/dev/null || { echo "Error: ipset is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ command -v chinadns &>/dev/null || { echo "Error: chinadns is not installed." 1>&2; exit 1; }
|
|
|
|
|
+ ;;
|
|
|
tproxy_global)
|
|
tproxy_global)
|
|
|
{ command -v ss-redir &>/dev/null || command -v ssr-redir &>/dev/null; } || { echo "Error: ss-redir/ssr-redir is not installed." 1>&2; exit 1; }
|
|
{ command -v ss-redir &>/dev/null || command -v ssr-redir &>/dev/null; } || { echo "Error: ss-redir/ssr-redir is not installed." 1>&2; exit 1; }
|
|
|
{ command -v ss-tunnel &>/dev/null || command -v ssr-tunnel &>/dev/null; } || { echo "Error: ss-tunnel/ssr-tunnel is not installed." 1>&2; exit 1; }
|
|
{ command -v ss-tunnel &>/dev/null || command -v ssr-tunnel &>/dev/null; } || { echo "Error: ss-tunnel/ssr-tunnel is not installed." 1>&2; exit 1; }
|
|
@@ -149,7 +168,7 @@ function update_chnroute {
|
|
|
|
|
|
|
|
function flush_cache {
|
|
function flush_cache {
|
|
|
case "$mode" in
|
|
case "$mode" in
|
|
|
- *global|*gfwlist*|*chnroute)
|
|
|
|
|
|
|
+ *global|*gfwlist*|*chnroute|v2ray*)
|
|
|
pgrep '^dnsmasq$' | xargs kill -HUP &>/dev/null
|
|
pgrep '^dnsmasq$' | xargs kill -HUP &>/dev/null
|
|
|
;;
|
|
;;
|
|
|
tproxy_global_tcp)
|
|
tproxy_global_tcp)
|
|
@@ -265,6 +284,9 @@ esac
|
|
|
|
|
|
|
|
function start_socks {
|
|
function start_socks {
|
|
|
case "$mode" in
|
|
case "$mode" in
|
|
|
|
|
+v2ray*)
|
|
|
|
|
+ eval "$v2ray_runcmd"
|
|
|
|
|
+ ;;
|
|
|
tproxy*)
|
|
tproxy*)
|
|
|
if [ "$server_use_ssr" = 'false' ]; then
|
|
if [ "$server_use_ssr" = 'false' ]; then
|
|
|
redir_params="-s'$server_addr' -p'$server_port' -m'$server_method' -k'$server_passwd' -b0.0.0.0 -l60080 --no-delay --reuse-port"
|
|
redir_params="-s'$server_addr' -p'$server_port' -m'$server_method' -k'$server_passwd' -b0.0.0.0 -l60080 --no-delay --reuse-port"
|
|
@@ -304,6 +326,74 @@ esac
|
|
|
|
|
|
|
|
function start_dns {
|
|
function start_dns {
|
|
|
case "$mode" in
|
|
case "$mode" in
|
|
|
|
|
+v2ray_global)
|
|
|
|
|
+ if [ $(grep -Ec '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' <<<"$v2ray_server") -eq 0 ]; then
|
|
|
|
|
+ v2ray_server_addr=$(getent hosts $v2ray_server | awk '{print $1}' | head -n1)
|
|
|
|
|
+ fi
|
|
|
|
|
+ dnsmasq -C <(cat <<EOF
|
|
|
|
|
+$([ "$dnsmasq_log_on" = 'true' ] && echo 'log-queries')
|
|
|
|
|
+log-async = 20
|
|
|
|
|
+log-facility = $dnsmasq_log_file
|
|
|
|
|
+domain-needed
|
|
|
|
|
+cache-size = $dnsmasq_cache_size
|
|
|
|
|
+$([ $(dnsmasq --help | grep -c min-cache-ttl) -ne 0 ] && echo "min-cache-ttl = $dnsmasq_cache_time")
|
|
|
|
|
+no-negcache
|
|
|
|
|
+no-resolv
|
|
|
|
|
+port = 53
|
|
|
|
|
+server = 127.0.0.1#${v2ray_tunnel#*:}
|
|
|
|
|
+$([ -n "$v2ray_server_addr" ] && echo "address = /$v2ray_server/$v2ray_server_addr")
|
|
|
|
|
+EOF
|
|
|
|
|
+)
|
|
|
|
|
+ ;;
|
|
|
|
|
+v2ray_gfwlist)
|
|
|
|
|
+ if [ $(grep -Ec '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' <<<"$v2ray_server") -eq 0 ]; then
|
|
|
|
|
+ v2ray_server_addr=$(getent hosts $v2ray_server | awk '{print $1}' | head -n1)
|
|
|
|
|
+ fi
|
|
|
|
|
+ dnsmasq -C <(cat <<EOF
|
|
|
|
|
+$([ "$dnsmasq_log_on" = 'true' ] && echo 'log-queries')
|
|
|
|
|
+log-async = 20
|
|
|
|
|
+log-facility = $dnsmasq_log_file
|
|
|
|
|
+domain-needed
|
|
|
|
|
+cache-size = $dnsmasq_cache_size
|
|
|
|
|
+$([ $(dnsmasq --help | grep -c min-cache-ttl) -ne 0 ] && echo "min-cache-ttl = $dnsmasq_cache_time")
|
|
|
|
|
+no-negcache
|
|
|
|
|
+no-resolv
|
|
|
|
|
+port = 53
|
|
|
|
|
+server = $dns_direct
|
|
|
|
|
+$([ -n "$v2ray_server_addr" ] && echo "address = /$v2ray_server/$v2ray_server_addr")
|
|
|
|
|
+$(perl -pe "s@^.*+\$@server=/$&/127.0.0.1#${v2ray_tunnel#*:}\nipset=/$&/gfwlist@" $dnsmasq_gfwlist <(
|
|
|
|
|
+perl -ne 'print unless m@^\s|\s\n$|^#|^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext
|
|
|
|
|
+))
|
|
|
|
|
+EOF
|
|
|
|
|
+)
|
|
|
|
|
+ ;;
|
|
|
|
|
+v2ray_chnroute)
|
|
|
|
|
+ chinadns_chnroute_temp=$(mktemp)
|
|
|
|
|
+ cat $chinadns_chnroute >$chinadns_chnroute_temp
|
|
|
|
|
+ echo "$dns_direct/32" >>$chinadns_chnroute_temp
|
|
|
|
|
+ chinadns_params="-b 0.0.0.0 -p 65353 -s $dns_direct,$v2ray_tunnel -c $chinadns_chnroute_temp"
|
|
|
|
|
+ [ "$chinadns_mutation" = 'true' ] && chinadns_params+=' -m'
|
|
|
|
|
+ [ "$chinadns_verbose" = 'true' ] && chinadns_params+=' -v'
|
|
|
|
|
+ nohup chinadns $chinadns_params </dev/null &>>"$chinadns_log" &
|
|
|
|
|
+
|
|
|
|
|
+ if [ $(grep -Ec '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' <<<"$v2ray_server") -eq 0 ]; then
|
|
|
|
|
+ v2ray_server_addr=$(getent hosts $v2ray_server | awk '{print $1}' | head -n1)
|
|
|
|
|
+ fi
|
|
|
|
|
+ dnsmasq -C <(cat <<EOF
|
|
|
|
|
+$([ "$dnsmasq_log_on" = 'true' ] && echo 'log-queries')
|
|
|
|
|
+log-async = 20
|
|
|
|
|
+log-facility = $dnsmasq_log_file
|
|
|
|
|
+domain-needed
|
|
|
|
|
+cache-size = $dnsmasq_cache_size
|
|
|
|
|
+$([ $(dnsmasq --help | grep -c min-cache-ttl) -ne 0 ] && echo "min-cache-ttl = $dnsmasq_cache_time")
|
|
|
|
|
+no-negcache
|
|
|
|
|
+no-resolv
|
|
|
|
|
+port = 53
|
|
|
|
|
+server = 127.0.0.1#65353
|
|
|
|
|
+$([ -n "$v2ray_server_addr" ] && echo "address = /$v2ray_server/$v2ray_server_addr")
|
|
|
|
|
+EOF
|
|
|
|
|
+)
|
|
|
|
|
+ ;;
|
|
|
tproxy_global)
|
|
tproxy_global)
|
|
|
dnsmasq -C <(cat <<EOF
|
|
dnsmasq -C <(cat <<EOF
|
|
|
$([ "$dnsmasq_log_on" = 'true' ] && echo 'log-queries')
|
|
$([ "$dnsmasq_log_on" = 'true' ] && echo 'log-queries')
|
|
@@ -609,7 +699,10 @@ function start_rule {
|
|
|
iptables_intranet_nonstd+=($cidr)
|
|
iptables_intranet_nonstd+=($cidr)
|
|
|
done
|
|
done
|
|
|
case "$mode" in
|
|
case "$mode" in
|
|
|
-tproxy_global*|tproxy_chnroute*)
|
|
|
|
|
|
|
+tproxy_global*|tproxy_chnroute*|v2ray_global|v2ray_chnroute)
|
|
|
|
|
+ [[ "$mode" == v* ]] && server_addr=$v2ray_server
|
|
|
|
|
+ [[ "$mode" == v* ]] && redir_port=${v2ray_redir#*:} || redir_port=60080
|
|
|
|
|
+
|
|
|
iptables -t nat -F OUTPUT
|
|
iptables -t nat -F OUTPUT
|
|
|
iptables -t nat -F PREROUTING
|
|
iptables -t nat -F PREROUTING
|
|
|
iptables -t nat -F POSTROUTING
|
|
iptables -t nat -F POSTROUTING
|
|
@@ -634,9 +727,9 @@ tproxy_global*|tproxy_chnroute*)
|
|
|
ipset -R <$iptables_ipset_file
|
|
ipset -R <$iptables_ipset_file
|
|
|
iptables -t nat -A SS-TCP -m set --match-set chnroute dst -j RETURN
|
|
iptables -t nat -A SS-TCP -m set --match-set chnroute dst -j RETURN
|
|
|
fi
|
|
fi
|
|
|
- iptables -t nat -A SS-TCP -p tcp -j REDIRECT --to-ports 60080
|
|
|
|
|
|
|
+ iptables -t nat -A SS-TCP -p tcp -j REDIRECT --to-ports $redir_port
|
|
|
|
|
|
|
|
- if [[ "$mode" != *tcp ]]; then
|
|
|
|
|
|
|
+ if [[ "$mode" != *tcp || "$mode" == v* ]]; then
|
|
|
iptables -t mangle -F PREROUTING
|
|
iptables -t mangle -F PREROUTING
|
|
|
iptables -t mangle -F SS-UDP &>/dev/null
|
|
iptables -t mangle -F SS-UDP &>/dev/null
|
|
|
iptables -t mangle -X SS-UDP &>/dev/null
|
|
iptables -t mangle -X SS-UDP &>/dev/null
|
|
@@ -655,7 +748,7 @@ tproxy_global*|tproxy_chnroute*)
|
|
|
iptables -t mangle -A SS-UDP -d 240/4 -j RETURN
|
|
iptables -t mangle -A SS-UDP -d 240/4 -j RETURN
|
|
|
iptables -t mangle -A SS-UDP -d $server_addr -j RETURN
|
|
iptables -t mangle -A SS-UDP -d $server_addr -j RETURN
|
|
|
[[ "$mode" == *chnroute* ]] && iptables -t mangle -A SS-UDP -m set --match-set chnroute dst -j RETURN
|
|
[[ "$mode" == *chnroute* ]] && iptables -t mangle -A SS-UDP -m set --match-set chnroute dst -j RETURN
|
|
|
- iptables -t mangle -A SS-UDP -p udp -j TPROXY --tproxy-mark $iptables_pbr_fwmark --on-ip 127.0.0.1 --on-port 60080
|
|
|
|
|
|
|
+ iptables -t mangle -A SS-UDP -p udp -j TPROXY --tproxy-mark $iptables_pbr_fwmark --on-ip 127.0.0.1 --on-port $redir_port
|
|
|
|
|
|
|
|
ip route add local 0/0 dev lo table $iptables_pbr_number
|
|
ip route add local 0/0 dev lo table $iptables_pbr_number
|
|
|
ip rule add fwmark $iptables_pbr_fwmark table $iptables_pbr_number
|
|
ip rule add fwmark $iptables_pbr_fwmark table $iptables_pbr_number
|
|
@@ -675,7 +768,9 @@ tproxy_global*|tproxy_chnroute*)
|
|
|
iptables -t nat -A POSTROUTING -s $intranet ! -d $intranet -j MASQUERADE
|
|
iptables -t nat -A POSTROUTING -s $intranet ! -d $intranet -j MASQUERADE
|
|
|
done
|
|
done
|
|
|
;;
|
|
;;
|
|
|
-tproxy_gfwlist*)
|
|
|
|
|
|
|
+tproxy_gfwlist*|v2ray_gfwlist)
|
|
|
|
|
+ [[ "$mode" == v* ]] && redir_port=${v2ray_redir#*:} || redir_port=60080
|
|
|
|
|
+
|
|
|
iptables -t nat -F OUTPUT
|
|
iptables -t nat -F OUTPUT
|
|
|
iptables -t nat -F PREROUTING
|
|
iptables -t nat -F PREROUTING
|
|
|
iptables -t nat -F POSTROUTING
|
|
iptables -t nat -F POSTROUTING
|
|
@@ -686,15 +781,15 @@ tproxy_gfwlist*)
|
|
|
ipset -N gfwlist hash:net &>/dev/null
|
|
ipset -N gfwlist hash:net &>/dev/null
|
|
|
perl -ne 'print if m@^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext | xargs -n1 ipset -A gfwlist &>/dev/null
|
|
perl -ne 'print if m@^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext | xargs -n1 ipset -A gfwlist &>/dev/null
|
|
|
[[ "$mode" == *tcp ]] && iptables -t nat -A SS-TCP -p tcp -d ${dns_remote%%:*} -j REDIRECT --to-ports 60080
|
|
[[ "$mode" == *tcp ]] && iptables -t nat -A SS-TCP -p tcp -d ${dns_remote%%:*} -j REDIRECT --to-ports 60080
|
|
|
- iptables -t nat -A SS-TCP -p tcp -m set --match-set gfwlist dst -j REDIRECT --to-ports 60080
|
|
|
|
|
|
|
+ iptables -t nat -A SS-TCP -p tcp -m set --match-set gfwlist dst -j REDIRECT --to-ports $redir_port
|
|
|
|
|
|
|
|
- if [[ "$mode" != *tcp ]]; then
|
|
|
|
|
|
|
+ if [[ "$mode" != *tcp || "$mode" == v* ]]; then
|
|
|
iptables -t mangle -F PREROUTING
|
|
iptables -t mangle -F PREROUTING
|
|
|
iptables -t mangle -F SS-UDP &>/dev/null
|
|
iptables -t mangle -F SS-UDP &>/dev/null
|
|
|
iptables -t mangle -X SS-UDP &>/dev/null
|
|
iptables -t mangle -X SS-UDP &>/dev/null
|
|
|
|
|
|
|
|
iptables -t mangle -N SS-UDP
|
|
iptables -t mangle -N SS-UDP
|
|
|
- iptables -t mangle -A SS-UDP -p udp -m set --match-set gfwlist dst -j TPROXY --tproxy-mark $iptables_pbr_fwmark --on-ip 127.0.0.1 --on-port 60080
|
|
|
|
|
|
|
+ iptables -t mangle -A SS-UDP -p udp -m set --match-set gfwlist dst -j TPROXY --tproxy-mark $iptables_pbr_fwmark --on-ip 127.0.0.1 --on-port $redir_port
|
|
|
|
|
|
|
|
ip route add local 0/0 dev lo table $iptables_pbr_number
|
|
ip route add local 0/0 dev lo table $iptables_pbr_number
|
|
|
ip rule add fwmark $iptables_pbr_fwmark table $iptables_pbr_number
|
|
ip rule add fwmark $iptables_pbr_fwmark table $iptables_pbr_number
|
|
@@ -858,6 +953,7 @@ function stop {
|
|
|
pkill -9 '^chinadns$'
|
|
pkill -9 '^chinadns$'
|
|
|
pkill -9 '^dnsforwarder$'
|
|
pkill -9 '^dnsforwarder$'
|
|
|
|
|
|
|
|
|
|
+ pkill -9 '^v2ray$'
|
|
|
pkill -9 '^ss-redir$'
|
|
pkill -9 '^ss-redir$'
|
|
|
pkill -9 '^ss-tunnel$'
|
|
pkill -9 '^ss-tunnel$'
|
|
|
pkill -9 '^ssr-redir$'
|
|
pkill -9 '^ssr-redir$'
|
|
@@ -870,6 +966,31 @@ function stop {
|
|
|
|
|
|
|
|
function status {
|
|
function status {
|
|
|
case "$mode" in
|
|
case "$mode" in
|
|
|
|
|
+ v2ray_global)
|
|
|
|
|
+ echo "mode: v2ray_global"
|
|
|
|
|
+ rport=${v2ray_redir#*:}; tport=${v2ray_tunnel#*:}
|
|
|
|
|
+ [ $(ss -lnpt | grep ":$rport\s" | wc -l) -ne 0 ] && echo -e "v2-redir/tcp \e[32m[running]\e[0m" || echo -e "v2-redir/tcp \e[35m[stopped]\e[0m"
|
|
|
|
|
+ [ $(ss -lnpu | grep ":$rport\s" | wc -l) -ne 0 ] && echo -e "v2-redir/udp \e[32m[running]\e[0m" || echo -e "v2-redir/udp \e[35m[stopped]\e[0m"
|
|
|
|
|
+ [ $(ss -lnpu | grep ":$tport\s" | wc -l) -ne 0 ] && echo -e "v2-tunnel/udp \e[32m[running]\e[0m" || echo -e "v2-tunnel/udp \e[35m[stopped]\e[0m"
|
|
|
|
|
+ [ $(pgrep -c '^dnsmasq$') -ne 0 ] && echo -e "dnsmasq: \e[32m[running]\e[0m" || echo -e "dnsmasq: \e[35m[stopped]\e[0m"
|
|
|
|
|
+ ;;
|
|
|
|
|
+ v2ray_gfwlist)
|
|
|
|
|
+ echo "mode: v2ray_gfwlist"
|
|
|
|
|
+ rport=${v2ray_redir#*:}; tport=${v2ray_tunnel#*:}
|
|
|
|
|
+ [ $(ss -lnpt | grep ":$rport\s" | wc -l) -ne 0 ] && echo -e "v2-redir/tcp \e[32m[running]\e[0m" || echo -e "v2-redir/tcp \e[35m[stopped]\e[0m"
|
|
|
|
|
+ [ $(ss -lnpu | grep ":$rport\s" | wc -l) -ne 0 ] && echo -e "v2-redir/udp \e[32m[running]\e[0m" || echo -e "v2-redir/udp \e[35m[stopped]\e[0m"
|
|
|
|
|
+ [ $(ss -lnpu | grep ":$tport\s" | wc -l) -ne 0 ] && echo -e "v2-tunnel/udp \e[32m[running]\e[0m" || echo -e "v2-tunnel/udp \e[35m[stopped]\e[0m"
|
|
|
|
|
+ [ $(pgrep -c '^dnsmasq$') -ne 0 ] && echo -e "dnsmasq: \e[32m[running]\e[0m" || echo -e "dnsmasq: \e[35m[stopped]\e[0m"
|
|
|
|
|
+ ;;
|
|
|
|
|
+ v2ray_chnroute)
|
|
|
|
|
+ echo "mode: v2ray_chnroute"
|
|
|
|
|
+ rport=${v2ray_redir#*:}; tport=${v2ray_tunnel#*:}
|
|
|
|
|
+ [ $(ss -lnpt | grep ":$rport\s" | wc -l) -ne 0 ] && echo -e "v2-redir/tcp \e[32m[running]\e[0m" || echo -e "v2-redir/tcp \e[35m[stopped]\e[0m"
|
|
|
|
|
+ [ $(ss -lnpu | grep ":$rport\s" | wc -l) -ne 0 ] && echo -e "v2-redir/udp \e[32m[running]\e[0m" || echo -e "v2-redir/udp \e[35m[stopped]\e[0m"
|
|
|
|
|
+ [ $(ss -lnpu | grep ":$tport\s" | wc -l) -ne 0 ] && echo -e "v2-tunnel/udp \e[32m[running]\e[0m" || echo -e "v2-tunnel/udp \e[35m[stopped]\e[0m"
|
|
|
|
|
+ [ $(pgrep -c '^chinadns$') -ne 0 ] && echo -e "chinadns: \e[32m[running]\e[0m" || echo -e "chinadns: \e[35m[stopped]\e[0m"
|
|
|
|
|
+ [ $(pgrep -c '^dnsmasq$') -ne 0 ] && echo -e "dnsmasq: \e[32m[running]\e[0m" || echo -e "dnsmasq: \e[35m[stopped]\e[0m"
|
|
|
|
|
+ ;;
|
|
|
tproxy_global)
|
|
tproxy_global)
|
|
|
echo "mode: tproxy_global"
|
|
echo "mode: tproxy_global"
|
|
|
if [ "$server_use_ssr" != 'true' ]; then
|
|
if [ "$server_use_ssr" != 'true' ]; then
|