|
@@ -321,7 +321,7 @@ min-cache-ttl = $dnsmasq_cache_time
|
|
|
no-negcache
|
|
no-negcache
|
|
|
no-resolv
|
|
no-resolv
|
|
|
port = 53
|
|
port = 53
|
|
|
-$(for dns in "${dns_direct[@]}"; do echo "server = $dns"; done)
|
|
|
|
|
|
|
+server = $dns_direct
|
|
|
$(perl -pe 's@^.*+$@server=/$&/127.0.0.1#60053\nipset=/$&/gfwlist@' $dnsmasq_gfwlist <(
|
|
$(perl -pe 's@^.*+$@server=/$&/127.0.0.1#60053\nipset=/$&/gfwlist@' $dnsmasq_gfwlist <(
|
|
|
perl -ne 'print unless m@^\s|\s\n$|^#|^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext
|
|
perl -ne 'print unless m@^\s|\s\n$|^#|^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext
|
|
|
))
|
|
))
|
|
@@ -331,9 +331,8 @@ EOF
|
|
|
tproxy_chnroute)
|
|
tproxy_chnroute)
|
|
|
chinadns_chnroute_temp=$(mktemp)
|
|
chinadns_chnroute_temp=$(mktemp)
|
|
|
cat $chinadns_chnroute >$chinadns_chnroute_temp
|
|
cat $chinadns_chnroute >$chinadns_chnroute_temp
|
|
|
- for dns in "${dns_direct[@]}"; do echo "$dns/32" >>$chinadns_chnroute_temp; done
|
|
|
|
|
- chinadns_upstream=$(for dns in "${dns_direct[@]}"; do echo -n "$dns,"; done)
|
|
|
|
|
- chinadns_params="-b 0.0.0.0 -p 65353 -s ${chinadns_upstream}127.0.0.1:60053 -c $chinadns_chnroute_temp"
|
|
|
|
|
|
|
+ echo "$dns_direct/32" >>$chinadns_chnroute_temp
|
|
|
|
|
+ chinadns_params="-b 0.0.0.0 -p 65353 -s $dns_direct,127.0.0.1:60053 -c $chinadns_chnroute_temp"
|
|
|
[ "$chinadns_mutation" = 'true' ] && chinadns_params+=' -m'
|
|
[ "$chinadns_mutation" = 'true' ] && chinadns_params+=' -m'
|
|
|
[ "$chinadns_verbose" = 'true' ] && chinadns_params+=' -v'
|
|
[ "$chinadns_verbose" = 'true' ] && chinadns_params+=' -v'
|
|
|
nohup chinadns $chinadns_params </dev/null &>>"$chinadns_log" &
|
|
nohup chinadns $chinadns_params </dev/null &>>"$chinadns_log" &
|
|
@@ -392,7 +391,7 @@ min-cache-ttl = $dnsmasq_cache_time
|
|
|
no-negcache
|
|
no-negcache
|
|
|
no-resolv
|
|
no-resolv
|
|
|
port = 53
|
|
port = 53
|
|
|
-$(for dns in "${dns_direct[@]}"; do echo "server = $dns"; done)
|
|
|
|
|
|
|
+server = $dns_direct
|
|
|
$(perl -pe 's@^.*+$@server=/$&/127.0.0.1#60053\nipset=/$&/gfwlist@' $dnsmasq_gfwlist <(
|
|
$(perl -pe 's@^.*+$@server=/$&/127.0.0.1#60053\nipset=/$&/gfwlist@' $dnsmasq_gfwlist <(
|
|
|
perl -ne 'print unless m@^\s|\s\n$|^#|^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext
|
|
perl -ne 'print unless m@^\s|\s\n$|^#|^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext
|
|
|
))
|
|
))
|
|
@@ -411,9 +410,8 @@ EOF
|
|
|
|
|
|
|
|
chinadns_chnroute_temp=$(mktemp)
|
|
chinadns_chnroute_temp=$(mktemp)
|
|
|
cat $chinadns_chnroute >$chinadns_chnroute_temp
|
|
cat $chinadns_chnroute >$chinadns_chnroute_temp
|
|
|
- for dns in "${dns_direct[@]}"; do echo "$dns/32" >>$chinadns_chnroute_temp; done
|
|
|
|
|
- chinadns_upstream=$(for dns in "${dns_direct[@]}"; do echo -n "$dns,"; done)
|
|
|
|
|
- chinadns_params="-b 0.0.0.0 -p 65353 -s ${chinadns_upstream}127.0.0.1:60053 -c $chinadns_chnroute_temp"
|
|
|
|
|
|
|
+ echo "$dns_direct/32" >>$chinadns_chnroute_temp
|
|
|
|
|
+ chinadns_params="-b 0.0.0.0 -p 65353 -s $dns_direct,127.0.0.1:60053 -c $chinadns_chnroute_temp"
|
|
|
[ "$chinadns_mutation" = 'true' ] && chinadns_params+=' -m'
|
|
[ "$chinadns_mutation" = 'true' ] && chinadns_params+=' -m'
|
|
|
[ "$chinadns_verbose" = 'true' ] && chinadns_params+=' -v'
|
|
[ "$chinadns_verbose" = 'true' ] && chinadns_params+=' -v'
|
|
|
nohup chinadns $chinadns_params </dev/null &>>"$chinadns_log" &
|
|
nohup chinadns $chinadns_params </dev/null &>>"$chinadns_log" &
|
|
@@ -464,7 +462,7 @@ min-cache-ttl = $dnsmasq_cache_time
|
|
|
no-negcache
|
|
no-negcache
|
|
|
no-resolv
|
|
no-resolv
|
|
|
port = 53
|
|
port = 53
|
|
|
-$(for dns in "${dns_direct[@]}"; do echo "server = $dns"; done)
|
|
|
|
|
|
|
+server = $dns_direct
|
|
|
$(perl -pe "s@^.*+\$@server=/$&/${dns_remote/:/#}\nipset=/$&/gfwlist@" $dnsmasq_gfwlist <(
|
|
$(perl -pe "s@^.*+\$@server=/$&/${dns_remote/:/#}\nipset=/$&/gfwlist@" $dnsmasq_gfwlist <(
|
|
|
perl -ne 'print unless m@^\s|\s\n$|^#|^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext
|
|
perl -ne 'print unless m@^\s|\s\n$|^#|^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext
|
|
|
))
|
|
))
|
|
@@ -474,9 +472,8 @@ EOF
|
|
|
tun2socks_chnroute)
|
|
tun2socks_chnroute)
|
|
|
chinadns_chnroute_temp=$(mktemp)
|
|
chinadns_chnroute_temp=$(mktemp)
|
|
|
cat $chinadns_chnroute >$chinadns_chnroute_temp
|
|
cat $chinadns_chnroute >$chinadns_chnroute_temp
|
|
|
- for dns in "${dns_direct[@]}"; do echo "$dns/32" >>$chinadns_chnroute_temp; done
|
|
|
|
|
- chinadns_upstream=$(for dns in "${dns_direct[@]}"; do echo -n "$dns,"; done)
|
|
|
|
|
- chinadns_params="-b 0.0.0.0 -p 60053 -s ${chinadns_upstream}${dns_remote} -c $chinadns_chnroute_temp"
|
|
|
|
|
|
|
+ echo "$dns_direct/32" >>$chinadns_chnroute_temp
|
|
|
|
|
+ chinadns_params="-b 0.0.0.0 -p 60053 -s $dns_direct,$dns_remote -c $chinadns_chnroute_temp"
|
|
|
[ "$chinadns_mutation" = 'true' ] && chinadns_params+=' -m'
|
|
[ "$chinadns_mutation" = 'true' ] && chinadns_params+=' -m'
|
|
|
[ "$chinadns_verbose" = 'true' ] && chinadns_params+=' -v'
|
|
[ "$chinadns_verbose" = 'true' ] && chinadns_params+=' -v'
|
|
|
nohup chinadns $chinadns_params </dev/null &>>"$chinadns_log" &
|
|
nohup chinadns $chinadns_params </dev/null &>>"$chinadns_log" &
|
|
@@ -535,7 +532,7 @@ min-cache-ttl = $dnsmasq_cache_time
|
|
|
no-negcache
|
|
no-negcache
|
|
|
no-resolv
|
|
no-resolv
|
|
|
port = 53
|
|
port = 53
|
|
|
-$(for dns in "${dns_direct[@]}"; do echo "server = $dns"; done)
|
|
|
|
|
|
|
+server = $dns_direct
|
|
|
$(perl -pe 's@^.*+$@server=/$&/127.0.0.1#60053\nipset=/$&/gfwlist@' $dnsmasq_gfwlist <(
|
|
$(perl -pe 's@^.*+$@server=/$&/127.0.0.1#60053\nipset=/$&/gfwlist@' $dnsmasq_gfwlist <(
|
|
|
perl -ne 'print unless m@^\s|\s\n$|^#|^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext
|
|
perl -ne 'print unless m@^\s|\s\n$|^#|^\d++\.\d++\.\d++\.\d++(?:/\d++)?$@' $dnsmasq_gfwlist_ext
|
|
|
))
|
|
))
|
|
@@ -554,9 +551,8 @@ EOF
|
|
|
|
|
|
|
|
chinadns_chnroute_temp=$(mktemp)
|
|
chinadns_chnroute_temp=$(mktemp)
|
|
|
cat $chinadns_chnroute >$chinadns_chnroute_temp
|
|
cat $chinadns_chnroute >$chinadns_chnroute_temp
|
|
|
- for dns in "${dns_direct[@]}"; do echo "$dns/32" >>$chinadns_chnroute_temp; done
|
|
|
|
|
- chinadns_upstream=$(for dns in "${dns_direct[@]}"; do echo -n "$dns,"; done)
|
|
|
|
|
- chinadns_params="-b 0.0.0.0 -p 65353 -s ${chinadns_upstream}127.0.0.1:60053 -c $chinadns_chnroute_temp"
|
|
|
|
|
|
|
+ echo "$dns_direct/32" >>$chinadns_chnroute_temp
|
|
|
|
|
+ chinadns_params="-b 0.0.0.0 -p 65353 -s $dns_direct,127.0.0.1:60053 -c $chinadns_chnroute_temp"
|
|
|
[ "$chinadns_mutation" = 'true' ] && chinadns_params+=' -m'
|
|
[ "$chinadns_mutation" = 'true' ] && chinadns_params+=' -m'
|
|
|
[ "$chinadns_verbose" = 'true' ] && chinadns_params+=' -v'
|
|
[ "$chinadns_verbose" = 'true' ] && chinadns_params+=' -v'
|
|
|
nohup chinadns $chinadns_params </dev/null &>>"$chinadns_log" &
|
|
nohup chinadns $chinadns_params </dev/null &>>"$chinadns_log" &
|
|
@@ -803,6 +799,7 @@ function start_kopts {
|
|
|
function dns_proxy {
|
|
function dns_proxy {
|
|
|
while umount /etc/resolv.conf; do :; done &>/dev/null
|
|
while umount /etc/resolv.conf; do :; done &>/dev/null
|
|
|
resolv=$(mktemp)
|
|
resolv=$(mktemp)
|
|
|
|
|
+ chmod 0644 $resolv
|
|
|
cat <<EOF >$resolv
|
|
cat <<EOF >$resolv
|
|
|
# Generated by ss-tproxy at $(date '+%F %T')
|
|
# Generated by ss-tproxy at $(date '+%F %T')
|
|
|
nameserver 127.0.0.1
|
|
nameserver 127.0.0.1
|
|
@@ -811,20 +808,9 @@ EOF
|
|
|
rm -f $resolv &>/dev/null
|
|
rm -f $resolv &>/dev/null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function dns_normal {
|
|
|
|
|
- while umount /etc/resolv.conf; do :; done &>/dev/null
|
|
|
|
|
- resolv=$(mktemp)
|
|
|
|
|
- cat <<EOF >$resolv
|
|
|
|
|
-# Generated by ss-tproxy at $(date '+%F %T')
|
|
|
|
|
-$(for dns in "${dns_direct[@]}"; do echo "nameserver $dns"; done)
|
|
|
|
|
-EOF
|
|
|
|
|
- mount -rB $resolv /etc/resolv.conf
|
|
|
|
|
- rm -f $resolv &>/dev/null
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
function start {
|
|
function start {
|
|
|
check_depend
|
|
check_depend
|
|
|
- dns_normal
|
|
|
|
|
|
|
+ while umount /etc/resolv.conf; do :; done &>/dev/null
|
|
|
start_socks
|
|
start_socks
|
|
|
start_dns
|
|
start_dns
|
|
|
start_rule
|
|
start_rule
|
|
@@ -834,7 +820,7 @@ function start {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function stop {
|
|
function stop {
|
|
|
- dns_normal
|
|
|
|
|
|
|
+ while umount /etc/resolv.conf; do :; done &>/dev/null
|
|
|
|
|
|
|
|
iptables -t nat -F OUTPUT
|
|
iptables -t nat -F OUTPUT
|
|
|
iptables -t nat -F PREROUTING
|
|
iptables -t nat -F PREROUTING
|
|
@@ -850,7 +836,7 @@ function stop {
|
|
|
iptables -t mangle -X TUN2SOCKS &>/dev/null
|
|
iptables -t mangle -X TUN2SOCKS &>/dev/null
|
|
|
|
|
|
|
|
for intranet in "${iptables_intranet[@]}"; do
|
|
for intranet in "${iptables_intranet[@]}"; do
|
|
|
- iptables -t nat -A PREROUTING -p udp -s $intranet -d $intranet --dport 53 -j DNAT --to-destination ${dns_direct[0]}
|
|
|
|
|
|
|
+ iptables -t nat -A PREROUTING -p udp -s $intranet -d $intranet --dport 53 -j DNAT --to-destination $dns_direct
|
|
|
iptables -t nat -A POSTROUTING -s $intranet ! -d $intranet -j MASQUERADE
|
|
iptables -t nat -A POSTROUTING -s $intranet ! -d $intranet -j MASQUERADE
|
|
|
done
|
|
done
|
|
|
|
|
|