Skip to content

初步使用v4.71的几个问题 #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bluehj777 opened this issue May 28, 2023 · 41 comments
Closed

初步使用v4.71的几个问题 #234

bluehj777 opened this issue May 28, 2023 · 41 comments

Comments

@bluehj777
Copy link

环境 debian11 干净安装,多网卡。chnroute 代理本机和内网,本机为网关。使用DNS内置方案

ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9000 qdisc fq state UP group default qlen 1000
    link/ether xx:xx:00:4a:ab:xx brd ff:ff:ff:ff:ff:ff
    altname enp0s3
    inet 192.168.100.254/24 brd 192.168.100.255 scope global ens3
       valid_lft forever preferred_lft forever
3: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9000 qdisc fq state UP group default qlen 1000
    link/ether xx:xx:00:c9:96:xx brd ff:ff:ff:ff:ff:ff
    altname enp0s4
    inet 192.168.30.254/24 brd 192.168.30.255 scope global ens4
       valid_lft forever preferred_lft forever
4: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9000 qdisc fq state UP group default qlen 1000
    link/ether xx:xx:00:22:xx:xx brd ff:ff:ff:ff:ff:ff
    altname enp0s5
    inet 192.168.20.254/24 brd 192.168.20.255 scope global ens5
       valid_lft forever preferred_lft forever
    inet6 2400:8xxx:620:5de1:5054:ff:xxxx:xxxx/64 scope global dynamic mngtmpaddr
       valid_lft 252000sec preferred_lft 165600sec
    inet6 fe80::5054:ff:fe22:d120/64 scope link
       valid_lft forever preferred_lft forever

cat ss-tproxy.config

## mode
#mode='chnroute'  global模式 (不分流 ) gfwlist 模式 (黑名单) chnroute 模式 (白名单)
mode='chnroute' # 大陆白名单:{gfwlist}走代理,{ignlist,chnlist,chnroute}走直连,其他走代理

## ipv4/6
ipv4='true'     # 是否对ipv4启用'透明代理': true启用 false不启用
ipv6='false'    # 是否对ipv6启用'透明代理': true启用 false不启用

## tproxy
tproxy='true'  # true:  TPROXY(tcp)   + TPROXY(udp) ## 纯 tproxy 模式 ##
                # false: REDIRECT(tcp) + TPROXY(udp) ## redirect 模式  ##
                #
                # 具体取决于'本机代理进程'的透明代理传入'协议'
                #
                # ss/ssr/trojan 通常为 redirect 模式
                # v2ray 两者都支持,具体取决于 v2ray 配置
                # ipt2socks 默认为纯 tproxy 模式,也可切换为 redirect 模式
                # ss-libev 3.3.5+ 支持纯 tproxy 模式,参数为"-T"、"tcp_tproxy": true
                # trojan 原生不支持 udp 透明代理,但可以配合 ipt2socks 来实现
                # trojan-go 只使用纯 tproxy 模式,支持 tcp 和 udp
                #
                # 其他代理软件请自行甄别测试,配置错误将无法正常透明代理

## tcponly
tcponly='false' # true:仅代理TCP流量 | false:代理TCP和UDP流量
                # 取决与'代理套件',有些代理/机场不支持UDP协议的代理
                # DNS查询默认走UDP,若代理不支持UDP,请将此选项设为true

## selfonly
selfonly='false' # true: 只代理ss-tproxy主机(本机)传出的流量
                 # false: 代理本机、内网机传出的流量(网关和dns指向ss-tproxy主机)
                 # 由于dns_remote必须走代理,且dns逻辑在本机进行,因此本机必须走代理
                 # 虽然可以只处理dns流量,其他流量不走代理,但感觉意义不大,还是简单点好

## proxy
#
# 本机代理进程相关,如透明代理端口,进程启动和停止命令(如果想自己控制进程启停,可以留空)
#
# ss-tproxy要求"代理进程"不参与ip分流,也不参与dns解析,专心让iptables过来的tcp/udp流量走代理即可
# 本机代理进程只会收到"纯ip"的tcp/udp流量,不会有dns相关的东西让你知晓,因为这些已被dns解析组件处理
# 因此ss-tproxy的设计原则是:各组件只负责自己的专业领域,无需知晓透明代理的全局面貌,做好自己的事就行
#
# 如果要切换代理/节点,请直接操作代理进程,而不是修改ss-tproxy.conf、重启ss-tproxy
# 因为这是一个重量级操作,除非tproxy模式、tcponly模式等涉及iptables规则的配置发生了更改
# 换句话说,ss-tproxy应该主要用于iptables管理,以及附带的dns方案,顺便帮你启动/关闭代理进程
#
proxy_procgroup='proxy_ss_tproxy'  # 本机代理进程的group(fsgid),所有代理进程都需要以此身份运行,用于流量放行
                         # 不允许填root或0,脚本会自动帮你创建group(如果填的是name),建议使用name
                         #
proxy_tcpport='60080'    # ss/ssr/v2ray/ipt2socks 等本机进程的 TCP 监听端口,该端口支持"透明代理"
proxy_udpport='60080'    # ss/ssr/v2ray/ipt2socks 等本机进程的 UDP 监听端口,该端口支持"透明代理"
                         # 代理进程只需监听"127.0.0.1"(v4环境)+"::1"(v6环境),不需要监听"全0地址"
                         #
proxy_startcmd='/etc/ss-tproxy/bin/xray run -config /etc/ss-tproxy/shadowsocks.json </dev/null &>>/var/log/v2ray.log &'        # 用于启动"本机代理进程(组)"的 shell 命令行,该命令行不应该执行过长时间
proxy_stopcmd='kill -9 $(pidof ss-redir v2ray xray obfs-local dnsmasq chinadns-ng dns2tcp)'         # 用于关闭"本机代理进程(组)"的 shell 命令行,该命令行不应该执行过长时间
                         # 如果想自己接管"本机代理进程"的启动/停止,可以在startcmd/stopcmd上留空
                         #
                         # 如果命令行比较长,建议封装为函数,然后在startcmd/stopcmd中调用这些函数
                         # shell函数可以定义在ss-tproxy.conf的任何位置,比如ss-tproxy.conf的末尾
                         #
                         # 可以调用 set_proxy_group 给可执行文件设置所属 group、setgid 权限位
                         # 比如:"set_proxy_group ss-redir",执行 ss-redir 时会自动切换 group

## dns
dns_custom='false'        # true:使用自定义dns方案(高级用户,见下面的说明) | false:使用内置dns方案
                                      # 使用自定义dns方案时,所有dns相关的配置被忽略,内置的域名分流规则也会失效
                                      # 需要自己实现域名解析/分流;udp代理未启用时,如果想走代理,请记得走tcp协议
                                      #
dns_procgroup='proxy_ss_tproxy_dns'   # dns进程的group(fsgid),不能与proxy_procgroup相同,所有dns进程都需要以此身份运行
                                      # 不允许填root或0,脚本会自动帮你创建group(如果填的是name),建议使用name而不是gid
                                      #
dns_mainport='60053'  # dns请求的逻辑入口(udp监听端口),脚本内部会将"所有"dns请求重定向至此udp端口
                                      # 监听地址必须能覆盖到"127.0.0.1"(v4环境)+"::1"(v6环境),用于接收本机dns请求
                                      # 如果要代理内网,则监听地址还需覆盖到相关网卡,为了简单,建议监听通配地址(全0)
                                      #
                                      # 下面的这些 dns_* 配置,只在使用"内置dns方案"时有效
                                      #
                                      # 直连DNS和远程DNS,控制的是"内置dns组件"的上游dns服务器参数
                                      # white和black,控制的是"ipset白名单/黑名单",即:直连还是代理
                                      # 放在这里是为了方便修改dns配置,不必修改ignlist.ext/gfwlist.ext
                                      #
                                      # white和black允许以下3类值,以dns_direct_white为例(其他同理)
                                      # - 'true'    # dns_direct的ip加入白名单,使其走直连
                                      # - 'false'   # dns_direct的ip不加入白名单,比如局域网ip
                                      # - '1.2.3.4' # 将1.2.3.4这个ip加入白名单,可填多个ip,空格隔开
                                      # > 注意,对于填写ip的情况,带6的选项请填ipv6地址,不带6的填ipv4地址
                                      #
dns_direct='119.29.29.29#53'             # 直连DNS(v4环境使用),必须指定端口,可使用本地/内网服务器
#dns_direct6='240C::6666#53'           # 直连DNS(v6环境使用),必须指定端口,可使用本地/内网服务器
dns_direct_white='true'               # 将dns_direct的ip加入白名单(global/chnroute),使其走直连
#dns_direct6_white='true'              # 将dns_direct6的ip加入白名单(global/chnroute),使其走直连
                                      #
dns_remote='8.8.8.8#53'               # 远程DNS(v4环境使用),必须指定端口,可使用本地/内网服务器
#dns_remote6='2001:4860:4860::8888#53' # 远程DNS(v6环境使用),必须指定端口,可使用本地/内网服务器
dns_remote_black='true'               # 将dns_remote的ip加入黑名单(gfwlist/chnroute),使其走代理
#dns_remote6_black='true'              # 将dns_remote6的ip加入黑名单(gfwlist/chnroute),使其走代理

## dnsmasq
# 使用自定义dns方案时,dnsmasq相关配置被忽略,dnsmasq不会启动
# 这里允许dnsmasq监听其他端口,是为了在它前面加入其他进程,优先处理dns
dnsmasq_bind_port='60053'                    # dnsmasq监听端口,留空表示端口同dns_mainport
dnsmasq_cache_size='4096'               # 最多缓存多少条,0表示禁用缓存,太大会影响性能
dnsmasq_cache_time_min='3600'           # 最短缓存多少秒,上限值为3600,0表示禁用此功能
dnsmasq_query_maxcnt='1024'             # dns查询最大并发数(dns-forward-max),默认150
dnsmasq_log_enable='false'              # 记录详细日志,除非进行调试,否则不建议启用
dnsmasq_log_file='/var/log/dnsmasq.log' # 日志文件,如果不想保存日志可以改为 /dev/null
dnsmasq_conf_dir=()                     # `--conf-dir` 选项的参数,可以填多个,空格隔开
dnsmasq_conf_file=(/etc/ss-tproxy/dnsmasq.d/dnsmasq.conf)                    # `--conf-file` 选项的参数,可以填多个,空格隔开
dnsmasq_conf_string=()                  # 自定义配置,一个数组元素就是一行配置,空格隔开

## chinadns
# 使用自定义dns方案时,chinadns相关配置被忽略,chinadns-ng不会启动
chinadns_for_gfwlist='true'              # 用于mode=gfwlist,提升域名匹配性能
chinadns_bind_port='65353'               # 监听端口,若 65353 被占用,请注意更改
chinadns_chnlist_first='false'           # 优先加载 chnlist 域名 (默认优先 gfwlist)
chinadns_extra_options=''                # 其他附加的命令行选项(已有的选项就别再填了)
chinadns_verbose='false'                 # 记录详细日志,除非进行调试,否则不建议启用
chinadns_logfile='/var/log/chinadns.log' # 日志文件,如果不想保存日志可以改为 /dev/null

## dns2tcp
# 使用自定义dns方案时,dns2tcp相关配置被忽略,dns2tcp不会启动
# 如果udp代理效果一般,建议启用dns2tcp,个人测试tcp查询快于udp,可能是isp/gfw对udp进行了qos
# 这里提供禁用选项,主要是为了方便使用其他dns工具替代dns2tcp,比如dnsproxy,走doh,也是tcp协议
dns2tcp_enable='auto'                   # auto:tcponly时启用 | true:总是启用 | false:禁用
dns2tcp_bind_port='65454'               # 监听端口,若 65454 被占用,请注意更改
dns2tcp_extra_options=''                # 其他附加的命令行选项(已有的选项就别再填了)
dns2tcp_verbose='false'                 # 记录详细日志,除非进行调试,否则不建议启用
dns2tcp_logfile='/var/log/dns2tcp.log'  # 日志文件,如果不想保存日志可以改为 /dev/null

## ipts
ipts_if_lo='lo'                     # 环回接口的名称,在标准发行版中,通常为 lo,如果不是请修改
ipts_rt_tab='233'                   # iproute2 路由表名或表 ID,除非产生冲突,否则不建议改动该选项
ipts_rt_mark='0x2333'               # iproute2 策略路由的防火墙标记,除非产生冲突,否则不建议改动该选项
ipts_set_snat='false'               # 设置 ipv4 MASQUERADE(SNAT) 规则,selfonly=false 时有效,详见 README
ipts_set_snat6='false'              # 设置 ipv6 MASQUERADE(SNAT) 规则,selfonly=false 时有效,详见 README
ipts_reddns_onstop='223.5.5.5#53'   # stop后重定向内网主机发来的dns至指定dns,selfonly=false 时有效,详见 README
ipts_reddns6_onstop='240C::6666#53' # stop后重定向内网主机发来的dns至指定dns,selfonly=false 时有效,详见 README
ipts_proxy_dst_port='1:10000,35101:35102,54320:54330'              # 要代理哪些端口,留空表示全部,多个逗号隔开,冒号表示范围(含边界),详见 README

## opts
opts_ss_netstat='auto'      # auto/ss/netstat,用哪个端口检测工具: auto(自动选择,优先考虑ss) | ss | netstat

## url
# 用于更新gfwlist.txt,格式:`域名后缀`或`server=/域名后缀/dns_ip`(dnsmasq格式,只关心`域名后缀`字段)
url_gfwlist='https://raw.githubusercontent.com/pexcn/daily/gh-pages/gfwlist/gfwlist.txt'
# 用于更新chnlist.txt,格式:`域名后缀`或`server=/域名后缀/dns_ip`(dnsmasq格式,只关心`域名后缀`字段)
url_chnlist='https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf'
# 用于更新chnroute*.txt,目前只支持APNIC格式,如果想使用其他ip库,建议在当前文件重写ss-tproxy的相关函数
url_chnroute='https://ftp.apnic.net/stats/apnic/delegated-apnic-latest'

## 回国模式
#
# 在国外访问大陆网站时,可能会出现ip区域限制等问题,导致无法正常使用大陆网络服务
# 此时可以使用"回国模式",通过代理回到国内,摆脱ip区域限制等问题,原理与翻墙类似
#
# ss-tproxy支持回国模式,要切换到回国模式,请执行以下步骤:
#
# - 使用 gfwlist 分流模式,即 mode='gfwlist'
# - 互换 dns_direct* 和 dns_remote* 的配置内容
# - url_gfwlist 改为大陆域名列表的url,如 url_chnlist
# - 注释 gfwlist.ext 中的 Telegram 地址段 (这是给国内用的)
# - 执行 ss-tproxy update-gfwlist (将gfwlist.txt换成大陆域名)
#
# 以上步骤只需执行一次,之后就是正常使用 ss-tproxy start/stop 了

###################### 钩子函数 ######################

# 此函数在"启动逻辑之前"执行
pre_start() {
    # do something
    return
}

# 此函数在"启动逻辑之后"执行
post_start() {
    # do something
    return
}

# 此函数在"停止逻辑之前"执行
pre_stop() {
    # do something
    return
}

# 此函数在"停止逻辑之后"执行
post_stop() {
    # do something
    return
}

# 额外状态,如curl测试代理是否ok
extra_status() {
    # do something
    return
}

# 此函数在start的最后一步执行,获取运行时状态(如进程pid),保存到文件
extra_pid() {
    # 格式同shell变量赋值,注意变量命名,防止冲突/覆盖
    # pid文件是一个shell脚本,下次执行时会source加载它
    # echo "pid_foo=$pid_foo"
    # echo "pid_bar=$pid_bar"
    return
}

###################### 自定义dns方案 ######################

# 自定义dns方案时,你需要自己实现"域名分流"(ignlist/chnlist/gfwlist)
# 并且将相关域名解析出来的ip加入ipset黑/白名单,以便与iptables规则联动
# 黑名单: sstp_black、sstp_black6 | 白名单: sstp_white、sstp_white6

# 以下接口不要求全部实现,你可以根据需要自由组织代码,保证逻辑正确即可
# 如果不知道怎么实现,可以参考ss-tproxy脚本中有关dns的源码,依葫芦画瓢

# 初始化,脚本加载时调用
custom_dns_init() {
    # do something
    return
}

# 要加入白名单的ip,启动dns之前调用
custom_dns_whiteip() {
    # 格式同 ignlist.ext,一行一个
    # echo "-223.5.5.5"
    # echo "~240C::6666"
    return
}

# 要加入黑名单的ip,启动dns之前调用
custom_dns_blackip() {
    # 格式同 gfwlist.ext,一行一个
    # echo "-8.8.8.8"
    # echo "~2001:4860:4860::8888"
    return
}

# 启动dns进程,请务必以dns_procgroup身份运行
custom_dns_start() {
    # do something
    return
}

# 关闭dns进程,stop时调用
custom_dns_stop() {
    # do something
    return
}

# 打印运行状态,status时调用
custom_dns_status() {
    # do something
    return
}

# 清空dns缓存,flush-dnscache时调用
custom_dns_flush() {
    # do something
    return
}

# 此函数在start的最后一步执行,获取运行时状态,同extra_pid
custom_dns_pid() {
    # 格式同shell变量赋值,注意变量命名,防止冲突/覆盖
    # pid文件是一个shell脚本,下次执行时会source加载它
    # echo "pid_foo=$pid_foo"
    # echo "pid_bar=$pid_bar"
    return
}

# 除了上述钩子函数,你还可以定义其他shell函数和变量
# 你也可以在当前文件使用ss-tproxy中已定义的函数和变量
#
# 若定义的函数与ss-tproxy中的同名,则本文件定义的函数覆盖原函数
# 使用自定义dns方案时,此特性可帮助你快速与原脚本融合(见脚本源码)
#
# ss-tproxy.conf是一个shell脚本,可以使用source来加载其他shell脚本
# ss-tproxy.conf被执行时,可以访问ss-tproxy传来的命令行参数(位置参数)

如上设置,初步测试简单测试看大体没有问题。
如下小问题:
1.这个新加的参数dns_mainport 没太看明白,监听通配地址,这里如何设置监听地址?给的例子是个53端口,我设置60053,会监听127.0.0.1和0.0.0.0的60053端口。可否让他监听192.168.100.254和192.168.30.254的60053吗?

dns_mainport='60053'  # dns请求的逻辑入口(udp监听端口),脚本内部会将"所有"dns请求重定向至此udp端口
                                      # 监听地址必须能覆盖到"127.0.0.1"(v4环境)+"::1"(v6环境),用于接收本机dns请求
                                      # 如果要代理内网,则监听地址还需覆盖到相关网卡,为了简单,建议监听通配地址(全0)

2.较比以前的4.6x的版本,在执行ss-tproxy stop ss-tproxy restart 时候,很容易出现
ipset v7.10: Set cannot be created: set with the same name already exists
这个提示。首次ss-tproxy restart执行不出现,然后再执行,基本就会出现

root@#/etc/ss-tproxy# ss-tproxy stop  (停止)
mode:           chnroute
proxy/tcp:      [stopped]
proxy/udp:      [stopped]
dnsmasq:        [stopped]
chinadns:       [stopped]
root@#:/etc/ss-tproxy# ipset flush  (手动清一下)
root@#:/etc/ss-tproxy# ss-tproxy start (启动,不出现错误)
mode:           chnroute
proxy/tcp:      [running]
proxy/udp:      [running]
dnsmasq:        [running]
chinadns:       [running]
root@#:/etc/ss-tproxy# ss-tproxy restart(重启1次启动,不出现错误)
mode:           chnroute
proxy/tcp:      [stopped]
proxy/udp:      [stopped]
dnsmasq:        [stopped]
chinadns:       [stopped]

mode:           chnroute
proxy/tcp:      [running]
proxy/udp:      [running]
dnsmasq:        [running]
chinadns:       [running]
root@#:/etc/ss-tproxy# ss-tproxy restart(重启第2次启动,开始出现错误)
ipset v7.10: Set cannot be destroyed: it is in use by a kernel component
mode:           chnroute
proxy/tcp:      [stopped]
proxy/udp:      [stopped]
dnsmasq:        [stopped]
chinadns:       [stopped]

ipset v7.10: Set cannot be created: set with the same name already exists
mode:           chnroute
proxy/tcp:      [running]
proxy/udp:      [running]
dnsmasq:        [running]
chinadns:       [running]

3.对于proxy_stopcmd的处理。
proxy_stopcmd='kill -9 $(pidof ss-redir v2ray xray obfs-local dnsmasq chinadns-ng dns2tcp)' # 用于关闭"本机代理进程(组)"

在 ss-tproxy stop 后,再次执行ss-tproxy stop(比如手误时)。出现提示
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
以前4.6x版本,是不会的。

  1. 对比4.6x版本,现在新版不在修改/etc/resolv.conf了。这个改进是不是会优化当网关上ss-tproxy有故障或错误时,起码不会影响内网机器正常上网了,网关上的/etc/resolv.conf一直是一个固定可用的公共DNS地址。

以上是初步测试,所有问题到没有影响SS-TPROXY的使用结果。

@zfl9
Copy link
Owner

zfl9 commented May 28, 2023

待会看看

stopcmd的是改了,之前会默认丢弃输出和错误,新版需要自己丢弃输出和错误了。

mainport的那个注释是给自定义dns看的,内置的不用管,默认会给设置好的。监听0.0.0.0会覆盖到本机所有网卡。

ipset报错问题,加个-x参数重新执行,看看是哪个set出的错。我这边没有遇到这个问题。

@zfl9
Copy link
Owner

zfl9 commented May 28, 2023

另外,stopcmd里面不需要填dns进程。填代理相关的就可以了

@zfl9
Copy link
Owner

zfl9 commented May 28, 2023

dnsmasq_bind_port 一般不需要去改,默认留空就好,这里提供选项是为了在dnsmasq前面加入其他dns进程(也就是说,新加入的进程监听mainport,dnsmasq监听其他端口)。

@bluehj777
Copy link
Author

待会看看

stopcmd的是改了,之前会默认丢弃输出和错误,新版需要自己丢弃输出和错误了。
这个解决
mainport的那个注释是给自定义dns看的,内置的不用管,默认会给设置好的。监听0.0.0.0会覆盖到本机所有网卡。
已设默认
ipset报错问题,加个-x参数重新执行,看看是哪个set出的错。我这边没有遇到这个问题。
这个就很诡异了。第一次ss-tproxy restart 都不会有问题
如果在ss-tproxy restart 第一次执行后1-2秒内重新执行肯定会出现问题
但有时又不会出现
ss-tproxy restart -x
========================================

+ (( ++i ))
+ (( i < 2 ))
+ '[' 1 -eq 0 ']'
+ '[' /etc/ss-tproxy ']'
+ '[' ss-tproxy.conf ']'
+ cd -- /etc/ss-tproxy
+ load_config
+ file_required ss-tproxy.conf
+ file_is_exists ss-tproxy.conf
+ '[' -f ss-tproxy.conf ']'
+ source ss-tproxy.conf restart
++ mode=chnroute
++ ipv4=true
++ ipv6=false
++ tproxy=true
++ tcponly=false
++ selfonly=false
++ proxy_procgroup=proxy_ss_tproxy
++ proxy_tcpport=60080
++ proxy_udpport=60080
++ proxy_startcmd='/etc/ss-tproxy/bin/xray run -config /etc/ss-tproxy/shadowsocks.json >>/var/log/v2ray.log &'
++ proxy_stopcmd='kill -9 $(pidof ss-redir v2ray xray obfs-local chinadns-ng dns2tcp)  >/dev/null 2>&1'
++ dns_custom=false
++ dns_procgroup=proxy_ss_tproxy_dns
++ dns_mainport=53
++ dns_direct=119.29.29.29#53
++ dns_direct6=240C::6666#53
++ dns_direct_white=false
++ dns_direct6_white=false
++ dns_remote=8.8.8.8#53
++ dns_remote6=2001:4860:4860::8888#53
++ dns_remote_black=false
++ dns_remote6_black=false
++ dnsmasq_bind_port=
++ dnsmasq_cache_size=4096
++ dnsmasq_cache_time_min=3600
++ dnsmasq_query_maxcnt=1024
++ dnsmasq_log_enable=false
++ dnsmasq_log_file=/var/log/dnsmasq.log
++ dnsmasq_conf_dir=()
++ dnsmasq_conf_file=()
++ dnsmasq_conf_string=()
++ chinadns_for_gfwlist=false
++ chinadns_bind_port=65353
++ chinadns_chnlist_first=false
++ chinadns_extra_options=
++ chinadns_verbose=false
++ chinadns_logfile=/var/log/chinadns.log
++ dns2tcp_enable=auto
++ dns2tcp_bind_port=65454
++ dns2tcp_extra_options=
++ dns2tcp_verbose=false
++ dns2tcp_logfile=/var/log/dns2tcp.log
++ ipts_if_lo=lo
++ ipts_rt_tab=233
++ ipts_rt_mark=0x2333
++ ipts_set_snat=false
++ ipts_set_snat6=false
++ ipts_reddns_onstop=119.29.29.29#53
++ ipts_reddns6_onstop=240C::6666#53
++ ipts_proxy_dst_port=1:10000,35101:35102,54320:54330
++ opts_ss_netstat=auto
++ url_gfwlist=https://raw.githubusercontent.com/pexcn/daily/gh-pages/gfwlist/gfwlist.txt
++ url_chnlist=https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf
++ url_chnroute=https://ftp.apnic.net/stats/apnic/delegated-apnic-latest
+ is_enabled_ipv4
+ is_true true
+ '[' true = true ']'
+ is_global_mode
+ '[' chnroute = global ']'
+ is_gfwlist_mode
+ '[' chnroute = gfwlist ']'
+ is_chnroute_mode
+ '[' chnroute = chnroute ']'
+ file_required ignlist.ext
+ file_is_exists ignlist.ext
+ '[' -f ignlist.ext ']'
+ file_required chnlist.txt
+ file_is_exists chnlist.txt
+ '[' -f chnlist.txt ']'
+ file_required chnroute.txt
+ file_is_exists chnroute.txt
+ '[' -f chnroute.txt ']'
+ file_required chnroute6.txt
+ file_is_exists chnroute6.txt
+ '[' -f chnroute6.txt ']'
+ file_required gfwlist.txt
+ file_is_exists gfwlist.txt
+ '[' -f gfwlist.txt ']'
+ file_required gfwlist.ext
+ file_is_exists gfwlist.ext
+ '[' -f gfwlist.ext ']'
+ '[' proxy_ss_tproxy -a proxy_ss_tproxy '!=' 0 -a proxy_ss_tproxy '!=' root ']'
+ '[' proxy_ss_tproxy_dns -a proxy_ss_tproxy_dns '!=' 0 -a proxy_ss_tproxy_dns '!=' root ']'
+ '[' proxy_ss_tproxy '!=' proxy_ss_tproxy_dns ']'
+ group_is_exists proxy_ss_tproxy
+ is_uint proxy_ss_tproxy
+ '[' proxy_ss_tproxy ']'
+ '[' -z proxy_ss_tproxy ']'
+ grep -q '^proxy_ss_tproxy:' /etc/group
+ group_is_exists proxy_ss_tproxy_dns
+ is_uint proxy_ss_tproxy_dns
+ '[' proxy_ss_tproxy_dns ']'
+ '[' -z proxy_ss_tproxy_dns ']'
+ grep -q '^proxy_ss_tproxy_dns:' /etc/group
+ is_need_iproute
+ is_tcp_tproxy
+ is_true true
+ '[' true = true ']'
+ command_required ip
+ command_is_exists ip
+ type -P ip
+ command_required ipset
+ command_is_exists ipset
+ type -P ipset
+ is_enabled_ipv4
+ is_true true
+ '[' true = true ']'
+ command_required iptables
+ command_is_exists iptables
+ type -P iptables
+ is_enabled_ipv6
+ is_true false
+ '[' false = true ']'
+ '[' '' ']'
+ dnsmasq_bind_port=53
+ is_built_in_dns
+ is_false false
+ is_true false
+ '[' false = true ']'
+ set_dns_group dnsmasq
+ set_command_group proxy_ss_tproxy_dns dnsmasq
+ command_required dnsmasq
+ command_is_exists dnsmasq
+ type -P dnsmasq
++ command_path dnsmasq
++ type -P dnsmasq
+ local group=proxy_ss_tproxy_dns path=/usr/sbin/dnsmasq
+ chgrp proxy_ss_tproxy_dns /usr/sbin/dnsmasq
+ chmod g+xs /usr/sbin/dnsmasq
+ is_enabled_chinadns
+ is_chnroute_mode
+ '[' chnroute = chnroute ']'
+ set_dns_group chinadns-ng
+ set_command_group proxy_ss_tproxy_dns chinadns-ng
+ command_required chinadns-ng
+ command_is_exists chinadns-ng
+ type -P chinadns-ng
++ command_path chinadns-ng
++ type -P chinadns-ng
+ local group=proxy_ss_tproxy_dns path=/etc/ss-tproxy/bin/chinadns-ng
+ chgrp proxy_ss_tproxy_dns /etc/ss-tproxy/bin/chinadns-ng
+ chmod g+xs /etc/ss-tproxy/bin/chinadns-ng
+ is_enabled_dns2tcp
+ case "$dns2tcp_enable" in
+ is_enabled_udp
+ is_false false
+ is_true false
+ '[' false = true ']'
+ case "$opts_ss_netstat" in
+ command_is_exists ss
+ type -P ss
+ netstat=ss
+ load_pidfile
+ ss_tproxy_is_started
+ iptables -t mangle -S SSTP_OUTPUT
+ source .ss-tproxy.pid
++ sstp_pid_dnsmasq=7782
++ sstp_pid_chinadns=7768
++ sstp_pid_dns2tcp4=
++ sstp_pid_dns2tcp6=
+ case "${arg_list[0]}" in
+ stop
+ call_func pre_stop
+ is_func pre_stop
++ type -t pre_stop
+ '[' function = function ']'
+ pre_stop
+ return
+ delete_pidfile
+ rm -f .ss-tproxy.pid
+ flush_iptables
+ _flush_iptables iptables
+ iptables -t mangle -D PREROUTING -j SSTP_PREROUTING
+ iptables -t mangle -D OUTPUT -j SSTP_OUTPUT
+ iptables -t nat -D PREROUTING -j SSTP_PREROUTING
+ iptables -t nat -D OUTPUT -j SSTP_OUTPUT
+ iptables -t nat -D POSTROUTING -j SSTP_POSTROUTING
+ for table in mangle nat
++ iptables -t mangle -S
++ grep '^-N SSTP_'
++ awk '{print $2}'
+ local 'chain_list=SSTP_OUTPUT
SSTP_PREROUTING
SSTP_RULE'
+ for chain in $chain_list
+ iptables -t mangle -F SSTP_OUTPUT
+ command iptables -w -t mangle -F SSTP_OUTPUT
+ for chain in $chain_list
+ iptables -t mangle -F SSTP_PREROUTING
+ command iptables -w -t mangle -F SSTP_PREROUTING
+ for chain in $chain_list
+ iptables -t mangle -F SSTP_RULE
+ command iptables -w -t mangle -F SSTP_RULE
+ for chain in $chain_list
+ iptables -t mangle -X SSTP_OUTPUT
+ command iptables -w -t mangle -X SSTP_OUTPUT
+ for chain in $chain_list
+ iptables -t mangle -X SSTP_PREROUTING
+ command iptables -w -t mangle -X SSTP_PREROUTING
+ for chain in $chain_list
+ iptables -t mangle -X SSTP_RULE
+ command iptables -w -t mangle -X SSTP_RULE
+ for table in mangle nat
++ iptables -t nat -S
++ grep '^-N SSTP_'
++ awk '{print $2}'
+ local chain_list=SSTP_OUTPUT
+ for chain in $chain_list
+ iptables -t nat -F SSTP_OUTPUT
+ command iptables -w -t nat -F SSTP_OUTPUT
+ for chain in $chain_list
+ iptables -t nat -X SSTP_OUTPUT
+ command iptables -w -t nat -X SSTP_OUTPUT
+ _flush_iptables ip6tables
+ ip6tables -t mangle -D PREROUTING -j SSTP_PREROUTING
+ ip6tables -t mangle -D OUTPUT -j SSTP_OUTPUT
+ ip6tables -t nat -D PREROUTING -j SSTP_PREROUTING
+ ip6tables -t nat -D OUTPUT -j SSTP_OUTPUT
+ ip6tables -t nat -D POSTROUTING -j SSTP_POSTROUTING
+ for table in mangle nat
++ ip6tables -t mangle -S
++ grep '^-N SSTP_'
++ awk '{print $2}'
+ local chain_list=
+ for table in mangle nat
++ ip6tables -t nat -S
++ grep '^-N SSTP_'
++ awk '{print $2}'
+ local chain_list=
+ flush_iproute
+ _flush_iproute -4
+ ip -4 rule del table 233
+ true
+ ip -4 rule del table 233
+ ip -4 route flush table 233
+ _flush_iproute -6
+ ip -6 rule del table 233
+ ip -6 route flush table 233
+ stop_dnsserver
+ kill -9 7782
+ kill -9 7768
+ kill -9
+ kill -9
+ call_func custom_dns_stop
+ is_func custom_dns_stop
++ type -t custom_dns_stop
+ '[' function = function ']'
+ custom_dns_stop
+ return
+ stop_proxyproc
+ eval 'kill -9 $(pidof ss-redir v2ray xray obfs-local chinadns-ng dns2tcp)  >/dev/null 2>&1'
+++ pidof ss-redir v2ray xray obfs-local chinadns-ng dns2tcp
++ kill -9 7766
+ flush_ipset
++ ipset -n list
++ grep '^sstp_'
+ for setname in $(ipset -n list | grep '^sstp_')
+ ipset destroy sstp_white
ipset v7.10: Set cannot be destroyed: it is in use by a kernel component
+ for setname in $(ipset -n list | grep '^sstp_')
+ ipset destroy sstp_white6
+ for setname in $(ipset -n list | grep '^sstp_')
+ ipset destroy sstp_black
+ for setname in $(ipset -n list | grep '^sstp_')
+ ipset destroy sstp_black6
+ add_stoprule
+ is_proxy_other
+ is_false false
+ is_true false
+ '[' false = true ']'
+ is_enabled_ipv4
+ is_true true
+ '[' true = true ']'
+ _add_stoprule iptables
+ add_reddns_rule iptables
+ local direct_dns_ip direct_dns_ipx direct_dns_port
+ is_ipv4_ipts iptables
+ '[' iptables = iptables ']'
+ '[' -z 119.29.29.29#53 ']'
++ get_ip_from_addr 119.29.29.29#53
++ local addr=119.29.29.29#53
++ echo 119.29.29.29
+ direct_dns_ip=119.29.29.29
+ direct_dns_ipx=119.29.29.29
++ get_port_from_addr 119.29.29.29#53
++ local addr=119.29.29.29#53
++ echo 53
+ direct_dns_port=53
+ iptables -t nat -N SSTP_PREROUTING
+ iptables -t nat -N SSTP_POSTROUTING
+ iptables -t nat -A SSTP_PREROUTING -p udp -m udp --dport 53 -m addrtype '!' --src-type LOCAL --dst-type LOCAL -j DNAT --to-destination 119.29.29.29:53
+ command iptables -w -t nat -A SSTP_PREROUTING -p udp -m udp --dport 53 -m addrtype '!' --src-type LOCAL --dst-type LOCAL -j DNAT --to-destination 119.29.29.29:53
+ iptables -t nat -A SSTP_POSTROUTING -d 119.29.29.29 -p udp -m udp --dport 53 -m addrtype '!' --src-type LOCAL -j MASQUERADE
+ command iptables -w -t nat -A SSTP_POSTROUTING -d 119.29.29.29 -p udp -m udp --dport 53 -m addrtype '!' --src-type LOCAL -j MASQUERADE
+ add_snat_rule iptables
+ is_ipv4_ipts iptables
+ '[' iptables = iptables ']'
+ is_false false
+ is_true false
+ '[' false = true ']'
+ return
+ add_sstp_chain iptables nat PREROUTING
+ local table=nat chain=PREROUTING
+ chain_is_exists iptables nat SSTP_PREROUTING
+ local table=nat chain=SSTP_PREROUTING
+ iptables -t nat -S SSTP_PREROUTING
+ iptables -t nat -A PREROUTING -j SSTP_PREROUTING
+ command iptables -w -t nat -A PREROUTING -j SSTP_PREROUTING
+ add_sstp_chain iptables nat POSTROUTING
+ local table=nat chain=POSTROUTING
+ chain_is_exists iptables nat SSTP_POSTROUTING
+ local table=nat chain=SSTP_POSTROUTING
+ iptables -t nat -S SSTP_POSTROUTING
+ iptables -t nat -A POSTROUTING -j SSTP_POSTROUTING
+ command iptables -w -t nat -A POSTROUTING -j SSTP_POSTROUTING
+ is_enabled_ipv6
+ is_true false
+ '[' false = true ']'
+ call_func post_stop
+ is_func post_stop
++ type -t post_stop
+ '[' function = function ']'
+ post_stop
+ return
+ status
++ font_bold chnroute
++ printf '\e[1mchnroute\e[0m'
+ echo -e 'mode:\t\tchnroute'
mode:           chnroute
+ _status proxy/tcp tcp_port_is_exists 60080
+ local name=proxy/tcp func=tcp_port_is_exists
+ shift 2
+ tcp_port_is_exists 60080
+ ss -lnpt
+ grep -q ':60080[[:blank:]]'
++ color_red '[stopped]'
++ printf '\e[35m[stopped]\e[0m'
+ echo -e 'proxy/tcp:\t[stopped]'
proxy/tcp:      [stopped]
+ is_enabled_udp
+ is_false false
+ is_true false
+ '[' false = true ']'
+ _status proxy/udp udp_port_is_exists 60080
+ local name=proxy/udp func=udp_port_is_exists
+ shift 2
+ udp_port_is_exists 60080
+ ss -anpu
+ grep -q ':60080[[:blank:]]'
++ color_red '[stopped]'
++ printf '\e[35m[stopped]\e[0m'
+ echo -e 'proxy/udp:\t[stopped]'
proxy/udp:      [stopped]
+ is_built_in_dns
+ is_false false
+ is_true false
+ '[' false = true ']'
+ _status dnsmasq process_is_running 7782
+ local name=dnsmasq func=process_is_running
+ shift 2
+ process_is_running 7782
+ kill -0 7782
++ color_red '[stopped]'
++ printf '\e[35m[stopped]\e[0m'
+ echo -e 'dnsmasq:\t[stopped]'
dnsmasq:        [stopped]
+ is_enabled_chinadns
+ is_chnroute_mode
+ '[' chnroute = chnroute ']'
+ _status chinadns process_is_running 7768
+ local name=chinadns func=process_is_running
+ shift 2
+ process_is_running 7768
+ kill -0 7768
++ color_red '[stopped]'
++ printf '\e[35m[stopped]\e[0m'
+ echo -e 'chinadns:\t[stopped]'
chinadns:       [stopped]
+ is_enabled_dns2tcp
+ case "$dns2tcp_enable" in
+ is_enabled_udp
+ is_false false
+ is_true false
+ '[' false = true ']'
+ is_enabled_dns2tcp
+ case "$dns2tcp_enable" in
+ is_enabled_udp
+ is_false false
+ is_true false
+ '[' false = true ']'
+ call_func extra_status
+ is_func extra_status
++ type -t extra_status
+ '[' function = function ']'
+ extra_status
+ return
+ echo

+ start
+ ss_tproxy_is_started
+ iptables -t mangle -S SSTP_OUTPUT
+ iptables -t nat -S SSTP_OUTPUT
+ ip6tables -t mangle -S SSTP_OUTPUT
+ ip6tables -t nat -S SSTP_OUTPUT
+ ip -4 rule
+ grep -q 'lookup 233'
+ ip -6 rule
+ grep -q 'lookup 233'
+ ip -4 route show table 233
+ grep -q '^'
+ ip -6 route show table 233
+ grep -q '^'
+ flush_iptables
+ _flush_iptables iptables
+ iptables -t mangle -D PREROUTING -j SSTP_PREROUTING
+ iptables -t mangle -D OUTPUT -j SSTP_OUTPUT
+ iptables -t nat -D PREROUTING -j SSTP_PREROUTING
+ iptables -t nat -D OUTPUT -j SSTP_OUTPUT
+ iptables -t nat -D POSTROUTING -j SSTP_POSTROUTING
+ for table in mangle nat
++ iptables -t mangle -S
++ grep '^-N SSTP_'
++ awk '{print $2}'
+ local chain_list=
+ for table in mangle nat
++ iptables -t nat -S
++ grep '^-N SSTP_'
++ awk '{print $2}'
+ local 'chain_list=SSTP_POSTROUTING
SSTP_PREROUTING'
+ for chain in $chain_list
+ iptables -t nat -F SSTP_POSTROUTING
+ command iptables -w -t nat -F SSTP_POSTROUTING
+ for chain in $chain_list
+ iptables -t nat -F SSTP_PREROUTING
+ command iptables -w -t nat -F SSTP_PREROUTING
+ for chain in $chain_list
+ iptables -t nat -X SSTP_POSTROUTING
+ command iptables -w -t nat -X SSTP_POSTROUTING
+ for chain in $chain_list
+ iptables -t nat -X SSTP_PREROUTING
+ command iptables -w -t nat -X SSTP_PREROUTING
+ _flush_iptables ip6tables
+ ip6tables -t mangle -D PREROUTING -j SSTP_PREROUTING
+ ip6tables -t mangle -D OUTPUT -j SSTP_OUTPUT
+ ip6tables -t nat -D PREROUTING -j SSTP_PREROUTING
+ ip6tables -t nat -D OUTPUT -j SSTP_OUTPUT
+ ip6tables -t nat -D POSTROUTING -j SSTP_POSTROUTING
+ for table in mangle nat
++ ip6tables -t mangle -S
++ grep '^-N SSTP_'
++ awk '{print $2}'
+ local chain_list=
+ for table in mangle nat
++ ip6tables -t nat -S
++ grep '^-N SSTP_'
++ awk '{print $2}'
+ local chain_list=
+ call_func pre_start
+ is_func pre_start
++ type -t pre_start
+ '[' function = function ']'
+ pre_start
+ return
+ set_kernel_param
+ is_enabled_ipv4
+ is_true true
+ '[' true = true ']'
+ sysctl -wq net.ipv4.ip_forward=1
+ is_enabled_ipv6
+ is_true false
+ '[' false = true ']'
+ sysctl_all_iface 4 route_localnet=1
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/all/route_localnet=1
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/default/route_localnet=1
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/ens3/route_localnet=1
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/ens4/route_localnet=1
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/ens5/route_localnet=1
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/lo/route_localnet=1
+ sysctl_all_iface 4 send_redirects=0
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/all/send_redirects=0
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/default/send_redirects=0
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/ens3/send_redirects=0
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/ens4/send_redirects=0
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/ens5/send_redirects=0
+ for path in /proc/sys/net/ipv$1/conf/*
+ sysctl -wq net/ipv4/conf/lo/send_redirects=0
+ start_ipset
+ is_global_mode
+ '[' chnroute = global ']'
+ is_gfwlist_mode
+ '[' chnroute = gfwlist ']'
+ is_chnroute_mode
+ '[' chnroute = chnroute ']'
+ list_ext_ipv4 ignlist.ext
+ init_ipset sstp_white
+ grep '^-' ignlist.ext
+ cut -c2-
++ str_find sstp_white 6
++ [[ sstp_white == *\6* ]]
++ echo inet
+ ipset create sstp_white hash:net family inet
+ get_ext_whiteip
ipset v7.10: Set cannot be created: set with the same name already exists
+ list_ext_ipv4 -
+ is_built_in_dns
+ is_false false
+ is_true false
+ '[' false = true ']'
+ get_ext_ip - false 119.29.29.29#53
+ case "$2" in
+ get_ext_ip '~' false 240C::6666#53
+ case "$2" in
+ sed 's/^/add sstp_white /'
+ grep '^-' -
+ cut -c2-
+ ipset '-!' restore
+ cat chnroute.txt
+ list_ext_ipv6 ignlist.ext
+ init_ipset sstp_white6
+ grep '^~' ignlist.ext
+ cut -c2-
++ str_find sstp_white6 6
++ [[ sstp_white6 == *\6* ]]
++ echo inet6
+ ipset create sstp_white6 hash:net family inet6
+ get_ext_whiteip
+ is_built_in_dns
+ is_false false
+ is_true false
+ '[' false = true ']'
+ get_ext_ip - false 119.29.29.29#53
+ case "$2" in
+ get_ext_ip '~' false 240C::6666#53
+ case "$2" in
+ sed 's/^/add sstp_white6 /'
+ list_ext_ipv6 -
+ ipset '-!' restore
+ grep '^~' -
+ cut -c2-
+ cat chnroute6.txt
+ list_ext_ipv4 gfwlist.ext
+ init_ipset sstp_black
+ grep '^-' gfwlist.ext
+ cut -c2-
++ str_find sstp_black 6
++ [[ sstp_black == *\6* ]]
++ echo inet
+ ipset create sstp_black hash:net family inet
+ get_ext_blackip
+ is_built_in_dns
+ is_false false
+ is_true false
+ '[' false = true ']'
+ list_ext_ipv4 -
+ get_ext_ip - false 8.8.8.8#53
+ case "$2" in
+ get_ext_ip '~' false 2001:4860:4860::8888#53
+ case "$2" in
+ grep '^-' -
+ cut -c2-
+ sed 's/^/add sstp_black /'
+ ipset '-!' restore
+ list_ext_ipv6 gfwlist.ext
+ init_ipset sstp_black6
+ grep '^~' gfwlist.ext
+ cut -c2-
++ str_find sstp_black6 6
++ [[ sstp_black6 == *\6* ]]
++ echo inet6
+ ipset create sstp_black6 hash:net family inet6
+ get_ext_blackip
+ is_built_in_dns
+ list_ext_ipv6 -
+ is_false false
+ is_true false
+ '[' false = true ']'
+ get_ext_ip - false 8.8.8.8#53
+ case "$2" in
+ get_ext_ip '~' false 2001:4860:4860::8888#53
+ case "$2" in
+ ipset '-!' restore
+ sed 's/^/add sstp_black6 /'
+ grep '^~' -
+ cut -c2-
+ start_proxyproc
+ eval '/etc/ss-tproxy/bin/xray run -config /etc/ss-tproxy/shadowsocks.json >>/var/log/v2ray.log &'
++ /etc/ss-tproxy/bin/xray run -config /etc/ss-tproxy/shadowsocks.json
+ start_dnsserver
+ is_built_in_dns
+ is_false false
+ is_true false
+ '[' false = true ']'
+ is_enabled_dns2tcp
+ case "$dns2tcp_enable" in
+ is_enabled_udp
+ is_false false
+ is_true false
+ '[' false = true ']'
+ is_enabled_chinadns
+ is_chnroute_mode
+ '[' chnroute = chnroute ']'
+ start_chinadns
+ local 'args= -b 127.0.0.1 -l 65353'
+ is_enabled_ipv4
+ is_true true
+ '[' true = true ']'
+ is_enabled_ipv6
+ is_true false
+ '[' false = true ']'
+ is_enabled_ipv4
+ is_true true
+ '[' true = true ']'
+ args+=' -c 119.29.29.29#53'
+ args+=' -t 8.8.8.8#53'
+ is_true false
+ '[' false = true ']'
+ is_gfwlist_mode
+ '[' chnroute = gfwlist ']'
++ echo 8060
+++ list_ext_domain gfwlist.ext
+++ list_ext_domain ignlist.ext
+++ is_true false
+++ '[' false = true ']'
+++ grep '^@' gfwlist.ext
+++ cut -c2-
++ chinadns-ng -b 127.0.0.1 -l 65353 -c 119.29.29.29#53 -t 8.8.8.8#53 -g gfwlist.txt,/dev/fd/63 -m chnlist.txt,/dev/fd/62 -4 sstp_white -6 sstp_white6 -a -A sstp_black,sstp_black6
+++ grep '^@' ignlist.ext
+ sstp_pid_chinadns=8060
++ echo 'port = 53'
++ echo 'group = proxy_ss_tproxy_dns'
++ is_true false
++ echo 8075
++ '[' false = true ']'
++ echo 'log-facility = /var/log/dnsmasq.log'
++ echo 'log-async = 20'
++ echo domain-needed
++ echo no-resolv
++ echo no-negcache
++ echo 'cache-size = 4096'
++ (( dnsmasq_cache_time_min ))
++ dnsmasq --keep-in-foreground --conf-file=-
++ grep -q min-cache-ttl
++ dnsmasq --help
++ echo 'min-cache-ttl = 3600'
++ echo 'dns-forward-max = 1024'
++ is_global_mode
++ '[' chnroute = global ']'
++ is_gfwlist_mode
++ '[' chnroute = gfwlist ']'
++ is_chnroute_mode
++ '[' chnroute = chnroute ']'
++ get_chnroute_dnsconf
++ echo 'server = 127.0.0.1#65353'
+++ cut -c2-
+ sstp_pid_dnsmasq=8075
+ start_iproute
+ is_need_iproute
+ is_tcp_tproxy
+ is_true true
+ '[' true = true ']'
+ is_enabled_ipv4
+ is_true true
+ '[' true = true ']'
+ _start_iproute -4
+ local family=-4
+ ip -4 route add local default dev lo table 233
+ ip rule help
+ grep -Fwq protocol
+ ip -4 rule add fwmark 0x2333 table 233 protocol static
+ is_enabled_ipv6
+ is_true false
+ '[' false = true ']'
+ start_iptables
+ is_enabled_ipv4
+ is_true true
+ '[' true = true ']'
+ _start_iptables iptables
+ start_iptables_pre iptables
+ iptables -t mangle -N SSTP_PREROUTING
+ command iptables -w -t mangle -N SSTP_PREROUTING
+ iptables -t mangle -N SSTP_OUTPUT
+ command iptables -w -t mangle -N SSTP_OUTPUT
+ iptables -t nat -N SSTP_PREROUTING
+ command iptables -w -t nat -N SSTP_PREROUTING
+ iptables -t nat -N SSTP_OUTPUT
+ command iptables -w -t nat -N SSTP_OUTPUT
+ iptables -t nat -N SSTP_POSTROUTING
+ command iptables -w -t nat -N SSTP_POSTROUTING
+ local loopback_addr loopback_addrx white_setname black_setname
+ init_iptables_param iptables
+ is_ipv4_ipts iptables
+ '[' iptables = iptables ']'
+ loopback_addr=127.0.0.1
+ loopback_addrx=127.0.0.1
+ white_setname=sstp_white
+ black_setname=sstp_black
+ is_tcp_tproxy
+ is_true true
+ '[' true = true ']'
+ start_iptables_tproxy iptables
+ do_proxy_tproxy iptables
++ is_tcp_tproxy
++ is_true true
++ '[' true = true ']'
++ echo 1
+ local tcp=1
++ is_enabled_udp
++ is_false false
++ is_true false
++ '[' false = true ']'
++ echo 1
+ local udp=1
+ create_sstp_rule iptables tproxy
+ local table action
+ '[' tproxy = tproxy ']'
+ table=mangle
+ action='-j CONNMARK --set-mark 0x2333'
+ iptables -t mangle -N SSTP_RULE
+ command iptables -w -t mangle -N SSTP_RULE
+ is_global_mode
+ '[' chnroute = global ']'
+ is_gfwlist_mode
+ '[' chnroute = gfwlist ']'
+ is_chnroute_mode
+ '[' chnroute = chnroute ']'
+ iptables -t mangle -A SSTP_RULE -m set --match-set sstp_white dst -m set '!' --match-set sstp_black dst -j RETURN
+ command iptables -w -t mangle -A SSTP_RULE -m set --match-set sstp_white dst -m set '!' --match-set sstp_black dst -j RETURN
+ iptables -t mangle -A SSTP_RULE -j CONNMARK --set-mark 0x2333
+ command iptables -w -t mangle -A SSTP_RULE -j CONNMARK --set-mark 0x2333
+ iptables -t mangle -A SSTP_OUTPUT -m addrtype --dst-type LOCAL -j RETURN
+ command iptables -w -t mangle -A SSTP_OUTPUT -m addrtype --dst-type LOCAL -j RETURN
+ iptables -t mangle -A SSTP_OUTPUT -m conntrack --ctdir REPLY -j RETURN
+ command iptables -w -t mangle -A SSTP_OUTPUT -m conntrack --ctdir REPLY -j RETURN
+ iptables -t mangle -A SSTP_OUTPUT -m owner --gid-owner proxy_ss_tproxy -j RETURN
+ command iptables -w -t mangle -A SSTP_OUTPUT -m owner --gid-owner proxy_ss_tproxy -j RETURN
+ (( udp ))
+ iptables -t mangle -A SSTP_OUTPUT -p udp -m udp --dport 53 -m owner '!' --gid-owner proxy_ss_tproxy_dns -j RETURN
+ command iptables -w -t mangle -A SSTP_OUTPUT -p udp -m udp --dport 53 -m owner '!' --gid-owner proxy_ss_tproxy_dns -j RETURN
+ (( tcp ))
++ get_dst_port_match
++ '[' 1:10000,35101:35102,54320:54330 ']'
++ echo '-m multiport --dports 1:10000,35101:35102,54320:54330'
+ iptables -t mangle -A SSTP_OUTPUT -p tcp -m tcp --syn -m multiport --dports 1:10000,35101:35102,54320:54330 -j SSTP_RULE
+ command iptables -w -t mangle -A SSTP_OUTPUT -p tcp -m tcp --syn -m multiport --dports 1:10000,35101:35102,54320:54330 -j SSTP_RULE
+ (( udp ))
++ get_dst_port_match
++ '[' 1:10000,35101:35102,54320:54330 ']'
++ echo '-m multiport --dports 1:10000,35101:35102,54320:54330'
+ iptables -t mangle -A SSTP_OUTPUT -p udp -m conntrack --ctstate NEW,RELATED -m multiport --dports 1:10000,35101:35102,54320:54330 -j SSTP_RULE
+ command iptables -w -t mangle -A SSTP_OUTPUT -p udp -m conntrack --ctstate NEW,RELATED -m multiport --dports 1:10000,35101:35102,54320:54330 -j SSTP_RULE
+ iptables -t mangle -A SSTP_OUTPUT -m connmark --mark 0x2333 -j MARK --set-mark 0x2333
+ command iptables -w -t mangle -A SSTP_OUTPUT -m connmark --mark 0x2333 -j MARK --set-mark 0x2333
+ iptables -t mangle -A SSTP_PREROUTING -m addrtype --dst-type LOCAL -j RETURN
+ command iptables -w -t mangle -A SSTP_PREROUTING -m addrtype --dst-type LOCAL -j RETURN
+ iptables -t mangle -A SSTP_PREROUTING -m conntrack --ctdir REPLY -j RETURN
+ command iptables -w -t mangle -A SSTP_PREROUTING -m conntrack --ctdir REPLY -j RETURN
+ is_proxy_other
+ is_false false
+ is_true false
+ '[' false = true ']'
+ (( tcp ))
++ get_dst_port_match
++ '[' 1:10000,35101:35102,54320:54330 ']'
++ echo '-m multiport --dports 1:10000,35101:35102,54320:54330'
+ iptables -t mangle -A SSTP_PREROUTING -p tcp -m tcp --syn -m addrtype '!' --src-type LOCAL -m multiport --dports 1:10000,35101:35102,54320:54330 -j SSTP_RULE
+ command iptables -w -t mangle -A SSTP_PREROUTING -p tcp -m tcp --syn -m addrtype '!' --src-type LOCAL -m multiport --dports 1:10000,35101:35102,54320:54330 -j SSTP_RULE
+ (( udp ))
++ get_dst_port_match
++ '[' 1:10000,35101:35102,54320:54330 ']'
++ echo '-m multiport --dports 1:10000,35101:35102,54320:54330'
+ iptables -t mangle -A SSTP_PREROUTING -p udp -m conntrack --ctstate NEW,RELATED -m addrtype '!' --src-type LOCAL -m multiport --dports 1:10000,35101:35102,54320:54330 -j SSTP_RULE
+ command iptables -w -t mangle -A SSTP_PREROUTING -p udp -m conntrack --ctstate NEW,RELATED -m addrtype '!' --src-type LOCAL -m multiport --dports 1:10000,35101:35102,54320:54330 -j SSTP_RULE
+ (( tcp ))
+ iptables -t mangle -A SSTP_PREROUTING -p tcp -m connmark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080 --tproxy-mark 0x2333
+ command iptables -w -t mangle -A SSTP_PREROUTING -p tcp -m connmark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080 --tproxy-mark 0x2333
+ (( udp ))
+ iptables -t mangle -A SSTP_PREROUTING -p udp -m connmark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080 --tproxy-mark 0x2333
+ command iptables -w -t mangle -A SSTP_PREROUTING -p udp -m connmark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080 --tproxy-mark 0x2333
+ redir_dns_request iptables
+ iptables -t nat -A SSTP_OUTPUT -p udp -m udp --dport 53 -m conntrack --ctstate NEW -m owner '!' --gid-owner proxy_ss_tproxy -m owner '!' --gid-owner proxy_ss_tproxy_dns -j REDIRECT --to-ports 53
+ command iptables -w -t nat -A SSTP_OUTPUT -p udp -m udp --dport 53 -m conntrack --ctstate NEW -m owner '!' --gid-owner proxy_ss_tproxy -m owner '!' --gid-owner proxy_ss_tproxy_dns -j REDIRECT --to-ports 53
+ is_proxy_other
+ is_false false
+ is_true false
+ '[' false = true ']'
+ (( dns_mainport != 53 ))
+ is_proxy_other
+ is_false false
+ is_true false
+ '[' false = true ']'
+ add_snat_rule iptables
+ is_ipv4_ipts iptables
+ '[' iptables = iptables ']'
+ is_false false
+ is_true false
+ '[' false = true ']'
+ return
+ start_iptables_post iptables
+ iptables -t mangle -A PREROUTING -j SSTP_PREROUTING
+ command iptables -w -t mangle -A PREROUTING -j SSTP_PREROUTING
+ iptables -t mangle -A OUTPUT -j SSTP_OUTPUT
+ command iptables -w -t mangle -A OUTPUT -j SSTP_OUTPUT
+ iptables -t nat -A PREROUTING -j SSTP_PREROUTING
+ command iptables -w -t nat -A PREROUTING -j SSTP_PREROUTING
+ iptables -t nat -A OUTPUT -j SSTP_OUTPUT
+ command iptables -w -t nat -A OUTPUT -j SSTP_OUTPUT
+ iptables -t nat -A POSTROUTING -j SSTP_POSTROUTING
+ command iptables -w -t nat -A POSTROUTING -j SSTP_POSTROUTING
+ is_enabled_ipv6
+ is_true false
+ '[' false = true ']'
+ call_func post_start
+ is_func post_start
++ type -t post_start
+ '[' function = function ']'
+ post_start
+ return
+ save_pidfile
+ is_built_in_dns
+ is_false false
+ is_true false
+ '[' false = true ']'
+ echo sstp_pid_dnsmasq=8075
+ echo sstp_pid_chinadns=8060
+ echo sstp_pid_dns2tcp4=
+ echo sstp_pid_dns2tcp6=
+ call_func extra_pid
+ is_func extra_pid
++ type -t extra_pid
+ '[' function = function ']'
+ extra_pid
+ return
+ delete_unused_chain
+ is_enabled_ipv4
+ is_true true
+ '[' true = true ']'
+ _delete_unused_chain iptables
+ list=('mangle' 'PREROUTING' 'mangle' 'OUTPUT' 'nat' 'PREROUTING' 'nat' 'OUTPUT' 'nat' 'POSTROUTING')
+ local list
+ (( i = 0 ))
+ (( i < 10 ))
+ local table=mangle chain=PREROUTING
+ chain_is_empty iptables mangle SSTP_PREROUTING
+ local table=mangle chain=SSTP_PREROUTING
++ iptables -t mangle -S SSTP_PREROUTING
++ command iptables -w -t mangle -S SSTP_PREROUTING
++ wc -l
+ '[' 7 -le 1 ']'
+ (( i += 2 ))
+ (( i < 10 ))
+ local table=mangle chain=OUTPUT
+ chain_is_empty iptables mangle SSTP_OUTPUT
+ local table=mangle chain=SSTP_OUTPUT
++ iptables -t mangle -S SSTP_OUTPUT
++ wc -l
++ command iptables -w -t mangle -S SSTP_OUTPUT
+ '[' 8 -le 1 ']'
+ (( i += 2 ))
+ (( i < 10 ))
+ local table=nat chain=PREROUTING
+ chain_is_empty iptables nat SSTP_PREROUTING
+ local table=nat chain=SSTP_PREROUTING
++ iptables -t nat -S SSTP_PREROUTING
++ command iptables -w -t nat -S SSTP_PREROUTING
++ wc -l
+ '[' 1 -le 1 ']'
+ iptables -t nat -D PREROUTING -j SSTP_PREROUTING
+ command iptables -w -t nat -D PREROUTING -j SSTP_PREROUTING
+ iptables -t nat -X SSTP_PREROUTING
+ command iptables -w -t nat -X SSTP_PREROUTING
+ (( i += 2 ))
+ (( i < 10 ))
+ local table=nat chain=OUTPUT
+ chain_is_empty iptables nat SSTP_OUTPUT
+ local table=nat chain=SSTP_OUTPUT
++ iptables -t nat -S SSTP_OUTPUT
++ command iptables -w -t nat -S SSTP_OUTPUT
++ wc -l
+ '[' 2 -le 1 ']'
+ (( i += 2 ))
+ (( i < 10 ))
+ local table=nat chain=POSTROUTING
+ chain_is_empty iptables nat SSTP_POSTROUTING
+ local table=nat chain=SSTP_POSTROUTING
++ iptables -t nat -S SSTP_POSTROUTING
++ wc -l
++ command iptables -w -t nat -S SSTP_POSTROUTING
+ '[' 1 -le 1 ']'
+ iptables -t nat -D POSTROUTING -j SSTP_POSTROUTING
+ command iptables -w -t nat -D POSTROUTING -j SSTP_POSTROUTING
+ iptables -t nat -X SSTP_POSTROUTING
+ command iptables -w -t nat -X SSTP_POSTROUTING
+ (( i += 2 ))
+ (( i < 10 ))
+ is_enabled_ipv6
+ is_true false
+ '[' false = true ']'
+ status
++ font_bold chnroute
++ printf '\e[1mchnroute\e[0m'
+ echo -e 'mode:\t\tchnroute'
mode:           chnroute
+ _status proxy/tcp tcp_port_is_exists 60080
+ local name=proxy/tcp func=tcp_port_is_exists
+ shift 2
+ tcp_port_is_exists 60080
+ ss -lnpt
+ grep -q ':60080[[:blank:]]'
++ color_green '[running]'
++ printf '\e[32m[running]\e[0m'
+ echo -e 'proxy/tcp:\t[running]'
proxy/tcp:      [running]
+ is_enabled_udp
+ is_false false
+ is_true false
+ '[' false = true ']'
+ _status proxy/udp udp_port_is_exists 60080
+ local name=proxy/udp func=udp_port_is_exists
+ shift 2
+ udp_port_is_exists 60080
+ ss -anpu
+ grep -q ':60080[[:blank:]]'
++ color_green '[running]'
++ printf '\e[32m[running]\e[0m'
+ echo -e 'proxy/udp:\t[running]'
proxy/udp:      [running]
+ is_built_in_dns
+ is_false false
+ is_true false
+ '[' false = true ']'
+ _status dnsmasq process_is_running 8075
+ local name=dnsmasq func=process_is_running
+ shift 2
+ process_is_running 8075
+ kill -0 8075
++ color_green '[running]'
++ printf '\e[32m[running]\e[0m'
+ echo -e 'dnsmasq:\t[running]'
dnsmasq:        [running]
+ is_enabled_chinadns
+ is_chnroute_mode
+ '[' chnroute = chnroute ']'
+ _status chinadns process_is_running 8060
+ local name=chinadns func=process_is_running
+ shift 2
+ process_is_running 8060
+ kill -0 8060
++ color_green '[running]'
++ printf '\e[32m[running]\e[0m'
+ echo -e 'chinadns:\t[running]'
chinadns:       [running]
+ is_enabled_dns2tcp
+ case "$dns2tcp_enable" in
+ is_enabled_udp
+ is_false false
+ is_true false
+ '[' false = true ']'
+ is_enabled_dns2tcp
+ case "$dns2tcp_enable" in
+ is_enabled_udp
+ is_false false
+ is_true false
+ '[' false = true ']'
+ call_func extra_status
+ is_func extra_status
++ type -t extra_status
+ '[' function = function ']'
+ extra_status
+ return
+ return 0

@zfl9
Copy link
Owner

zfl9 commented May 28, 2023

确实有点神奇了,我明天看看,能不能自己复现出来

@cattyhouse
Copy link
Contributor

这是因为iptables还没有完全停止,那么这个sstp_white 就处于被占用中,无法destroy。可能跟 iptables -w 有关。

@cattyhouse
Copy link
Contributor

ipset 停止命令可以稍微优化下

while ipset list sstp_white &>/dev/null; do

ipset destroy sstp_white

done

@bluehj777
Copy link
Author

bluehj777 commented May 28, 2023

&>/dev/null

应该是这个问题,开始也怀疑了,在另一台配置稍好的机器上怎么restart 也不出现这个问题。
在这台有问题的机器上稍微给点儿延时,也能解决问题
cat ss-tproxy

==========
..........................

flush_ipset() {
    for setname in $(ipset -n list | grep '^sstp_'); do
        ipset destroy $setname
    done
}

添加了1秒延时,问题可以解决(0.2秒也行)

flush_ipset() {
    for setname in $(ipset -n list | grep '^sstp_'); do
        sleep 1
        ipset destroy $setname
    done
}

@bluehj777
Copy link
Author

@zfl9 还有个小问题

dns_direct='119.29.29.29#53' # 直连DNS(v4环境使用),必须指定端口,可使用本地/内网服务器

还能设内网私有IP吗?我的环境里有是个10.x.x.x段的Dns服务器,以前用在这里没问题,新版的设这个就无法用了
得用公共的DNS就没问题
有时间帮看看.

@bluehj777
Copy link
Author

这个已解决,是一个参数设错了

@zfl9 还有个小问题

dns_direct='119.29.29.29#53' # 直连DNS(v4环境使用),必须指定端口,可使用本地/内网服务器

还能设内网私有IP吗?我的环境里有是个10.x.x.x段的Dns服务器,以前用在这里没问题,新版的设这个就无法用了 得用公共的DNS就没问题 有时间帮看看.

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

ipset 那个问题,搜了下,感觉是 iptables -F 在规则被完全清理之前就返回了(命令执行完毕),你看看是不是因为用的后端是 nft(执行 iptables --version,看看是啥)

@bluehj777
Copy link
Author

看了下

iptables --version

iptables v1.8.7 (nf_tables)

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

另一个正常的机器呢?是 legacy 吗?

@bluehj777
Copy link
Author

一样的,都是kvm虚拟机,DEBIAN 11 最小安装,只是这个出问题的机器,分配的资源弱点。

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

了解,那我加个处理吧,sleep 1肯定不太合适,因为对于那些不出问题的人来说,sleep 1秒太伤了。

@bluehj777
Copy link
Author

这种问题,以前的版本也出现过,但是非常少见,多出现在把ss-tproxy装在路由器里的情况,比如用在 egdemax erx系列或unifi usg3 这些musl机型里时,后来都放在旁路x86的虚拟机里用了,在v4.6x版本中基本不会出现了再。

@cattyhouse
Copy link
Contributor

@bluehj777 你改一下 ss-tproxy 把 flush_iptables (1152行) 移动到 flush_ipset 上一行. 在测试下?

@bluehj777
Copy link
Author

改动测试下,还是不行

ss-tproxy status
mode:           chnroute
proxy/tcp:      [running]
proxy/udp:      [running]
dnsmasq:        [running]
chinadns:       [running]
root@#:~# ss-tproxy restart
ipset v7.10: Set cannot be destroyed: it is in use by a kernel component
mode:           chnroute
proxy/tcp:      [stopped]
proxy/udp:      [stopped]
dnsmasq:        [stopped]
chinadns:       [stopped]

ipset v7.10: Set cannot be created: set with the same name already exists
mode:           chnroute
proxy/tcp:      [running]
proxy/udp:      [running]
dnsmasq:        [running]
chinadns:       [running]

stop() {
    call_func pre_stop

    # 与start顺序相反
    delete_pidfile
    flush_iproute
    stop_dnsserver
    stop_proxyproc
    flush_iptables
    flush_ipset

    # 内网dns重定向、设置snat规则

@cattyhouse
Copy link
Contributor

出现这个问题的时候, 你立刻运行 iptables-save 看看里面是不是还有什么规则没有清理干净?

ss-tproxy stop ; ss-tproxy start ; ss-tproxy stop ; iptables-save ; ipset list -n

@bluehj777
Copy link
Author

这个 sstp_white摧毁不了?

ss-tproxy stop ; ss-tproxy start ; ss-tproxy stop ; iptables-save ; ipset list -n

ipset v7.10: Set cannot be destroyed: it is in use by a kernel component
mode:           chnroute
proxy/tcp:      [stopped]
proxy/udp:      [stopped]
dnsmasq:        [stopped]
chinadns:       [stopped]
ipset v7.10: Set cannot be created: set with the same name already exists
mode:           chnroute
proxy/tcp:      [running]
proxy/udp:      [running]
dnsmasq:        [running]
chinadns:       [running]
ipset v7.10: Set cannot be destroyed: it is in use by a kernel component
mode:           chnroute
proxy/tcp:      [stopped]
proxy/udp:      [stopped]
dnsmasq:        [stopped]
chinadns:       [stopped]
# Generated by iptables-save v1.8.7 on Mon May 29 11:13:21 2023
*mangle
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
# Completed on Mon May 29 11:13:21 2023
# Generated by iptables-save v1.8.7 on Mon May 29 11:13:21 2023
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:SSTP_POSTROUTING - [0:0]
:SSTP_PREROUTING - [0:0]
-A PREROUTING -j SSTP_PREROUTING
-A POSTROUTING -j SSTP_POSTROUTING
-A SSTP_POSTROUTING -d 119.29.29.29/32 -p udp -m udp --dport 53 -m addrtype ! --src-type LOCAL -j MASQUERADE
-A SSTP_PREROUTING -p udp -m udp --dport 53 -m addrtype ! --src-type LOCAL --dst-type LOCAL -j DNAT --to-destination 119.29.29.29:53
COMMIT
# Completed on Mon May 29 11:13:21 2023
sstp_white

@cattyhouse
Copy link
Contributor

cattyhouse commented May 29, 2023

你这个sstp_white是之前遗留下来的... 不是这次的. 再测试下:

ss-tproxy stop ; ipset x sstp_white ; ss-tproxy start ; ss-tproxy stop ; iptables-save ; ipset list -n

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

手动执行 ipset destroy sstp_white 看看?

ipset list -t 看看 References 这个字段

nft list ruleset 看看是不是这边有引用?

@cattyhouse
Copy link
Contributor

确保顺序还是

 flush_iptables
    flush_ipset

@bluehj777
Copy link
Author

确保顺序还是

 flush_iptables
    flush_ipset

是的,还是这个顺序

ss-tproxy stop ; ipset x sstp_white ; ss-tproxy start ; ss-tproxy stop ; iptables-save ; ipset list -n

mode:           chnroute
proxy/tcp:      [stopped]
proxy/udp:      [stopped]
dnsmasq:        [stopped]
chinadns:       [stopped]
ipset v7.10: The set with the given name does not exist
mode:           chnroute
proxy/tcp:      [running]
proxy/udp:      [running]
dnsmasq:        [running]
chinadns:       [running]
ipset v7.10: Set cannot be destroyed: it is in use by a kernel component
mode:           chnroute
proxy/tcp:      [stopped]
proxy/udp:      [stopped]
dnsmasq:        [stopped]
chinadns:       [stopped]
# Generated by iptables-save v1.8.7 on Mon May 29 11:18:32 2023
*mangle
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
# Completed on Mon May 29 11:18:32 2023
# Generated by iptables-save v1.8.7 on Mon May 29 11:18:32 2023
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:SSTP_POSTROUTING - [0:0]
:SSTP_PREROUTING - [0:0]
-A PREROUTING -j SSTP_PREROUTING
-A POSTROUTING -j SSTP_POSTROUTING
-A SSTP_POSTROUTING -d 119.29.29.29/32 -p udp -m udp --dport 53 -m addrtype ! --src-type LOCAL -j MASQUERADE
-A SSTP_PREROUTING -p udp -m udp --dport 53 -m addrtype ! --src-type LOCAL --dst-type LOCAL -j DNAT --to-destination 119.29.29.29:53
COMMIT
# Completed on Mon May 29 11:18:32 2023
sstp_white

@cattyhouse
Copy link
Contributor

echo "#1" ; ss-tproxy stop ; echo "#2" ; ipset x sstp_white ; echo "#3" ; ss-tproxy start ; echo "#4" ;ss-tproxy stop ;echo "#5" ; iptables-save ; echo "#6" ;ipset list -n

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

ss-tproxy stop 后,手动 destroy 这个 set(或者再次执行 ss-tproxy stop),是否可以销毁?

另外,ss-tproxy stop 后,执行 nft list ruleset,看看是不是还有残留规则。

还有,start 和 stop 后,执行 ipset list -t 看看存在几个引用

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

算了,不必再折腾了。


你把 flush_ipset 这个函数改一下,没问题,我就提交代码了。

flush_ipset() {
    for setname in $(ipset -n list | grep '^sstp_'); do
        while ! ipset destroy $setname &>/dev/null; do
            sleep 0.05 # 稍微等一下,避免短时间内执行太多指令
        done
    done
    # 加个检测
    if ipset -n list | grep -q '^sstp_'; then
        echo "ipset 没清理干净"
    fi
}

@bluehj777
Copy link
Author

bluehj777 commented May 29, 2023

已测试,加上这个处理后就没有问题了

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

好的。

@cattyhouse
Copy link
Contributor

一样的,都是kvm虚拟机,DEBIAN 11 最小安装,只是这个出问题的机器,分配的资源弱点。

有多弱?

@bluehj777
Copy link
Author

bluehj777 commented May 29, 2023

一样的,都是kvm虚拟机,DEBIAN 11 最小安装,只是这个出问题的机器,分配的资源弱点。

有多弱?

比没有问题的弱,4核4G内存,虚拟硬盘

@cattyhouse
Copy link
Contributor

一样的,都是kvm虚拟机,DEBIAN 11 最小安装,只是这个出问题的机器,分配的资源弱点。

有多弱?

比没有问题的弱,4核4G内存,虚拟硬盘

这根本不弱. 没啥关联的. 两个系统分别都是啥? iptables --version 分别都是啥?

@bluehj777
Copy link
Author

bluehj777 commented May 29, 2023

一样的,都是kvm虚拟机,DEBIAN 11 最小安装,只是这个出问题的机器,分配的资源弱点。

有多弱?

比没有问题的弱,4核4G内存,虚拟硬盘

这根本不弱. 没啥关联的. 两个系统分别都是啥? iptables --version 分别都是啥?

都是debian11 的x64 dist-upgrade 到最新。iptables --version 都是 iptables v1.8.7 (nf_tables)

一个是pve下的虚拟机,三网卡(不同VLAN),intel x550做了vfs(相当于直通吧)这台没问题。
另一个是有问题的,在QNAP NAS(威联通底层应该是用的ubuntu系统定制的)里的VirtualizationStation 3套件做虚拟机,三网卡(不同VLAN)网卡是virtIO虚拟网卡

目前有问题的这台,加了点儿sleep确定可以无论怎么restart都没问题了,只要不加,第2次开始就出问题。但是呢我发现要是等上个1,2分钟再RESTART就没问题(也很随机),然后再restart,就又开始。如果不用restart 用stop后在start,也是一样。出问题时ipset -n list
出来的残余表用 手动摧毁也不行。
没问题的机器,就是正常了,怎么restart都没有问题

btw:还有个问题请教。目前ss-tproxy新版的 想确定下restart 和stop/start 有什么区别?一般什么场景用restart什么用stop/start。比如我只切换代理服务器的地址(代理使用的客户端软件和其配置都不变时),是不是只要ss-tproxy flush-dnscache就行了?

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

想确定下restart 和stop/start 有什么区别

restart 就是 stop 然后 start,没区别。


切换代理,重启代理进程即可。我看你用的是 xray,重启 xray 进程即可。


flush-dnscache 应该不需要,因为代理进程不使用 ss-tproxy 上的 dns 服务。使用的 dns 是 /etc/resolv.conf 里面的。

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

只切换代理服务器的地址(代理使用的客户端软件和其配置都不变时)

如果使用的是域名,并且域名没变,只是对应的 ip 变了,通常不用操作。

可以通过 sg proxy_ss_tproxy 'dig 代理服务器的域名' 检查解析结果,这里切换 group 是为了模仿代理进程发出 dns 请求。

@bluehj777
Copy link
Author

我主要是在考虑布置一个 检测到代理服务器不可用自动切换节点 的脚本。是个单独的脚本,cron里每5分检测一下google。如果不可用就切换。预先设置好允许切换节点服务器配置的文件名,
cat server_list.txt

1 A.json.xray
2 B.json.xray
3 C.json.xray

代理服务器的配置信息,域名,加密方式等都实现写好在A,B,C.json.xray里。然后脚本就会按计划工作,如果发现节点不可用就去使用B.json.xray的配置,重新加载一遍代理程序,你的意思是此时不需要重启ss-tproxy?过程大概这样,但是有个问题,已5分钟间隔为例,假设第1分钟时A代理正常,客户端使用网络也都没有问题,第3分钟时A代理断了,但此时脚本还没到切换时间(5分钟时)此时客户端上网时应该出现问题,他应该得到了一个被污染的DNS IP。当5分钟时,脚本检测到故障,切换成功了,此时ss-tproxy应该有flush-dnscache的动作吧,这样可以快点正确解析出被污染的IP

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

第3分钟时A代理断了,但此时脚本还没到切换时间(5分钟时)此时客户端上网时应该出现问题,他应该得到了一个被污染的DNS IP。

代理如果断开了(不可用),也不会存在受污染的结果。因为此时解析 google 等域名,只会失败。

因此不需要担心缓存问题。当然在切换节点时,可以手动执行 flush-dnscache,主要是考虑到:新节点的地理位置与老节点不同,如果仍然使用之前的缓存结果,可能对某些cdn域名不友好(访问速度减慢),比如从亚太切换到北美节点。

@bluehj777
Copy link
Author

嗯,明白了,非常感谢指点。

@zfl9
Copy link
Owner

zfl9 commented May 29, 2023

如果发现节点不可用就去使用B.json.xray的配置,重新加载一遍代理程序,你的意思是此时不需要重启ss-tproxy?

是的,kill xray进程,然后start新的xray进程,即可。

你可以给 xray 的 json 配置文件来个软链接,切换节点就是切换这个软链接,然后restart xray进程。

@cattyhouse
Copy link
Contributor

curl 1.1.1.1 也比 curl google.com 强, 免去解析.

@bluehj777
Copy link
Author

curl 1.1.1.1 也比 curl google.com 强, 免去解析.

对。是这个道理,好优化。之前没想到。1.1.1.1本身比谷歌稳吧:-)

@zfl9 zfl9 closed this as completed in 5f3287b May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants