|
@@ -3,7 +3,7 @@
|
|
|
main_cfg='/etc/tproxy/ss-tproxy.conf'
|
|
main_cfg='/etc/tproxy/ss-tproxy.conf'
|
|
|
|
|
|
|
|
if [ ! -e "${main_cfg}" ]; then
|
|
if [ ! -e "${main_cfg}" ]; then
|
|
|
- echo -e "\e[37m${main_cfg}\e[0m [\e[1;35mnot_exist\e[0m]"
|
|
|
|
|
|
|
+ echo -e "\e[37m${main_cfg}\e[0m [\e[1;35mnot_exist\e[0m]" 1>&2
|
|
|
exit 1
|
|
exit 1
|
|
|
else
|
|
else
|
|
|
source "${main_cfg}"
|
|
source "${main_cfg}"
|
|
@@ -89,6 +89,19 @@ function ipts_update() {
|
|
|
iptables -t nat -F SS-TCP &> /dev/null
|
|
iptables -t nat -F SS-TCP &> /dev/null
|
|
|
iptables -t nat -X SS-TCP &> /dev/null
|
|
iptables -t nat -X SS-TCP &> /dev/null
|
|
|
|
|
|
|
|
|
|
+ iptables -t nat -N SS-TCP
|
|
|
|
|
+ iptables -t nat -A SS-TCP -d 0/8 -j RETURN
|
|
|
|
|
+ iptables -t nat -A SS-TCP -d 10/8 -j RETURN
|
|
|
|
|
+ iptables -t nat -A SS-TCP -d 127/8 -j RETURN
|
|
|
|
|
+ iptables -t nat -A SS-TCP -d 169.254/16 -j RETURN
|
|
|
|
|
+ iptables -t nat -A SS-TCP -d 172.16/12 -j RETURN
|
|
|
|
|
+ iptables -t nat -A SS-TCP -d 192.168/16 -j RETURN
|
|
|
|
|
+ iptables -t nat -A SS-TCP -d 224/4 -j RETURN
|
|
|
|
|
+ iptables -t nat -A SS-TCP -d 240/4 -j RETURN
|
|
|
|
|
+ iptables -t nat -A SS-TCP -d ${server_addr} -j RETURN
|
|
|
|
|
+ iptables -t nat -A SS-TCP -m set --match-set chnroute dst -j RETURN
|
|
|
|
|
+ iptables -t nat -A SS-TCP -p tcp -j REDIRECT --to-ports ${redir_port}
|
|
|
|
|
+
|
|
|
iptables -t mangle -N SS-UDP
|
|
iptables -t mangle -N SS-UDP
|
|
|
iptables -t mangle -A SS-UDP -d 0/8 -j RETURN
|
|
iptables -t mangle -A SS-UDP -d 0/8 -j RETURN
|
|
|
iptables -t mangle -A SS-UDP -d 10/8 -j RETURN
|
|
iptables -t mangle -A SS-UDP -d 10/8 -j RETURN
|
|
@@ -102,27 +115,17 @@ function ipts_update() {
|
|
|
iptables -t mangle -A SS-UDP -m set --match-set chnroute dst -j RETURN
|
|
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_tproxy_mark} --on-ip ${iptables_tproxy_ip} --on-port ${iptables_tproxy_port}
|
|
iptables -t mangle -A SS-UDP -p udp -j TPROXY --tproxy-mark ${iptables_tproxy_mark} --on-ip ${iptables_tproxy_ip} --on-port ${iptables_tproxy_port}
|
|
|
|
|
|
|
|
- iptables -t mangle -A PREROUTING -p udp -s ${iptables_intranet} ! -d ${iptables_intranet} --dport 53 -j ACCEPT
|
|
|
|
|
- iptables -t mangle -A PREROUTING -p udp -s ${iptables_intranet} -j SS-UDP
|
|
|
|
|
|
|
+ iptables -t nat -A OUTPUT -p tcp -j SS-TCP
|
|
|
|
|
|
|
|
- iptables -t nat -N SS-TCP
|
|
|
|
|
- iptables -t nat -A SS-TCP -d 0/8 -j RETURN
|
|
|
|
|
- iptables -t nat -A SS-TCP -d 10/8 -j RETURN
|
|
|
|
|
- iptables -t nat -A SS-TCP -d 127/8 -j RETURN
|
|
|
|
|
- iptables -t nat -A SS-TCP -d 169.254/16 -j RETURN
|
|
|
|
|
- iptables -t nat -A SS-TCP -d 172.16/12 -j RETURN
|
|
|
|
|
- iptables -t nat -A SS-TCP -d 192.168/16 -j RETURN
|
|
|
|
|
- iptables -t nat -A SS-TCP -d 224/4 -j RETURN
|
|
|
|
|
- iptables -t nat -A SS-TCP -d 240/4 -j RETURN
|
|
|
|
|
- iptables -t nat -A SS-TCP -d ${server_addr} -j RETURN
|
|
|
|
|
- iptables -t nat -A SS-TCP -m set --match-set chnroute dst -j RETURN
|
|
|
|
|
- iptables -t nat -A SS-TCP -p tcp -j REDIRECT --to-ports ${redir_port}
|
|
|
|
|
|
|
+ for intranet in "$iptables_intranet"; do
|
|
|
|
|
+ iptables -t mangle -A PREROUTING -p udp -s $intranet ! -d $intranet --dport 53 -j ACCEPT
|
|
|
|
|
+ iptables -t nat -A PREROUTING -p udp -s $intranet ! -d $intranet --dport 53 -j REDIRECT --to-ports 53
|
|
|
|
|
|
|
|
- iptables -t nat -A OUTPUT -p tcp -j SS-TCP
|
|
|
|
|
- iptables -t nat -A PREROUTING -p udp -s ${iptables_intranet} ! -d ${iptables_intranet} --dport 53 -j REDIRECT --to-ports 53
|
|
|
|
|
- iptables -t nat -A PREROUTING -p tcp -s ${iptables_intranet} -j SS-TCP
|
|
|
|
|
|
|
+ iptables -t nat -A PREROUTING -p tcp -s $intranet -j SS-TCP
|
|
|
|
|
+ iptables -t mangle -A PREROUTING -p udp -s $intranet -j SS-UDP
|
|
|
|
|
|
|
|
- iptables -t nat -A POSTROUTING -s ${iptables_intranet} ! -d ${iptables_intranet} -j MASQUERADE
|
|
|
|
|
|
|
+ iptables -t nat -A POSTROUTING -s $intranet ! -d $intranet -j MASQUERADE
|
|
|
|
|
+ done
|
|
|
}
|
|
}
|
|
|
function ipts_origin() {
|
|
function ipts_origin() {
|
|
|
iptables -t mangle -F PREROUTING
|
|
iptables -t mangle -F PREROUTING
|
|
@@ -134,8 +137,10 @@ function ipts_origin() {
|
|
|
iptables -t nat -F SS-TCP &> /dev/null
|
|
iptables -t nat -F SS-TCP &> /dev/null
|
|
|
iptables -t nat -X SS-TCP &> /dev/null
|
|
iptables -t nat -X SS-TCP &> /dev/null
|
|
|
|
|
|
|
|
- iptables -t nat -A PREROUTING -p udp -s ${iptables_intranet} -d ${iptables_intranet} --dport 53 -j DNAT --to-destination ${dns_original_1}
|
|
|
|
|
- iptables -t nat -A POSTROUTING -s ${iptables_intranet} ! -d ${iptables_intranet} -j MASQUERADE
|
|
|
|
|
|
|
+ for intranet in "$iptables_intranet"; do
|
|
|
|
|
+ iptables -t nat -A PREROUTING -p udp -s $intranet -d $intranet --dport 53 -j DNAT --to-destination ${dns_original[0]}
|
|
|
|
|
+ iptables -t nat -A POSTROUTING -s $intranet ! -d $intranet -j MASQUERADE
|
|
|
|
|
+ done
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function pbr_add() {
|
|
function pbr_add() {
|
|
@@ -154,24 +159,21 @@ function ipfwd_on() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function dns_update() {
|
|
function dns_update() {
|
|
|
-cat << EOF > /etc/resolv.conf
|
|
|
|
|
-# Generated by ss-tproxy at $(date '+%F %T')
|
|
|
|
|
-nameserver 127.0.0.1
|
|
|
|
|
-EOF
|
|
|
|
|
|
|
+ echo "# Generated by ss-tproxy at $(date '+%F %T')" > /etc/resolv.conf
|
|
|
|
|
+ echo "nameserver 127.0.0.1" >> /etc/resolv.conf
|
|
|
}
|
|
}
|
|
|
function dns_origin() {
|
|
function dns_origin() {
|
|
|
-cat << EOF > /etc/resolv.conf
|
|
|
|
|
-# Generated by ss-tproxy at $(date '+%F %T')
|
|
|
|
|
-nameserver ${dns_original_1}
|
|
|
|
|
-nameserver ${dns_original_2}
|
|
|
|
|
-EOF
|
|
|
|
|
|
|
+ echo "# Generated by ss-tproxy at $(date '+%F %T')" > /etc/resolv.conf
|
|
|
|
|
+ for dns in "$dns_original"; do
|
|
|
|
|
+ echo "nameserver $dns" >> /etc/resolv.conf
|
|
|
|
|
+ done
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function current_ip() {
|
|
function current_ip() {
|
|
|
ip_info=$(curl -4skL ip.chinaz.com/getip.aspx | sed -r "s/^\{ip:'(.*)',address:'(.*)'\}$/\1|\2/g")
|
|
ip_info=$(curl -4skL ip.chinaz.com/getip.aspx | sed -r "s/^\{ip:'(.*)',address:'(.*)'\}$/\1|\2/g")
|
|
|
my_ip=$(echo ${ip_info} | awk -F'|' '{print $1}')
|
|
my_ip=$(echo ${ip_info} | awk -F'|' '{print $1}')
|
|
|
my_loc=$(echo ${ip_info} | awk -F'|' '{print $2}')
|
|
my_loc=$(echo ${ip_info} | awk -F'|' '{print $2}')
|
|
|
- echo -e "\e[37mIP:\e[0m ${my_ip}\t\e[37m位置:\e[0m ${my_loc}"
|
|
|
|
|
|
|
+ echo -e "\e[37mIP:\e[0m ${my_ip}\t\e[37mLocation:\e[0m ${my_loc}"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function start() {
|
|
function start() {
|
|
@@ -234,12 +236,12 @@ function start() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function stop() {
|
|
function stop() {
|
|
|
- pgrep '^ss-redir$' | xargs kill -9 &> /dev/null
|
|
|
|
|
- pgrep '^ss-tunnel$' | xargs kill -9 &> /dev/null
|
|
|
|
|
- pgrep '^ssr-redir$' | xargs kill -9 &> /dev/null
|
|
|
|
|
- pgrep '^ssr-tunnel$' | xargs kill -9 &> /dev/null
|
|
|
|
|
- pgrep '^chinadns$' | xargs kill -9 &> /dev/null
|
|
|
|
|
- pgrep '^pdnsd$' | xargs kill -9 &> /dev/null
|
|
|
|
|
|
|
+ pkill '^pdnsd$' &> /dev/null
|
|
|
|
|
+ pkill '^chinadns$' &> /dev/null
|
|
|
|
|
+ pkill '^ss-redir$' &> /dev/null
|
|
|
|
|
+ pkill '^ss-tunnel$' &> /dev/null
|
|
|
|
|
+ pkill '^ssr-redir$' &> /dev/null
|
|
|
|
|
+ pkill '^ssr-tunnel$' &> /dev/null
|
|
|
|
|
|
|
|
ipts_origin
|
|
ipts_origin
|
|
|
ipset -X chnroute &> /dev/null
|
|
ipset -X chnroute &> /dev/null
|
|
@@ -291,7 +293,6 @@ function status() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function usage() {
|
|
function usage() {
|
|
|
-{
|
|
|
|
|
echo -e "\e[37mUsage:\e[0m \e[36m${0}\e[0m \e[1;37mCOMMAND\e[0m"
|
|
echo -e "\e[37mUsage:\e[0m \e[36m${0}\e[0m \e[1;37mCOMMAND\e[0m"
|
|
|
echo -e "\e[1;37mCOMMAND\e[0m := {"
|
|
echo -e "\e[1;37mCOMMAND\e[0m := {"
|
|
|
echo -e "\t\e[33mstart\e[0m\t\tstart ss-tproxy"
|
|
echo -e "\t\e[33mstart\e[0m\t\tstart ss-tproxy"
|
|
@@ -302,10 +303,9 @@ function usage() {
|
|
|
echo -e "\t\e[33mflush_dnsche\e[0m\tflush dns cache for pdnsd"
|
|
echo -e "\t\e[33mflush_dnsche\e[0m\tflush dns cache for pdnsd"
|
|
|
echo -e "\t\e[33mupdate_chnip\e[0m\tupdate chnroute for ipset/chinadns"
|
|
echo -e "\t\e[33mupdate_chnip\e[0m\tupdate chnroute for ipset/chinadns"
|
|
|
echo -e "}"
|
|
echo -e "}"
|
|
|
-} | more
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-case ${1} in
|
|
|
|
|
|
|
+case $1 in
|
|
|
star*) # start
|
|
star*) # start
|
|
|
start
|
|
start
|
|
|
status
|
|
status
|
|
@@ -321,6 +321,7 @@ r*) # restart
|
|
|
stop
|
|
stop
|
|
|
status
|
|
status
|
|
|
echo
|
|
echo
|
|
|
|
|
+ sleep 1
|
|
|
start
|
|
start
|
|
|
status
|
|
status
|
|
|
;;
|
|
;;
|
|
@@ -339,7 +340,7 @@ h*) # help
|
|
|
usage
|
|
usage
|
|
|
;;
|
|
;;
|
|
|
*)
|
|
*)
|
|
|
- usage
|
|
|
|
|
|
|
+ usage 1>&2
|
|
|
exit 1
|
|
exit 1
|
|
|
;;
|
|
;;
|
|
|
esac
|
|
esac
|