Skip to content
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

透明代理能设置转发访问端口白名单吗? #256

Closed
wnpllrzodiac opened this issue Nov 3, 2023 · 11 comments
Closed

透明代理能设置转发访问端口白名单吗? #256

wnpllrzodiac opened this issue Nov 3, 2023 · 11 comments

Comments

@wnpllrzodiac
Copy link

现在路由器下连的N1盒子开启了透明代理,路由器上设置N1盒子为网关。
N1盒子自身,以及路由器下的其他设备访问网页均没有问题。
但是从路由器下的其他设备通过ssh访问N1,连接不上,ping也似乎不同。感觉是iptable错误认为是需要转发的数据流。

PS 从路由器上ssh是可以登陆到N1盒子的,另外路由器配置了端口映射,从外网访问路由器再通过端口映射也是可以ssh登陆到N1盒子的。

ping 192.168.123.5                                         <== N1 LAN ip addr
PING 192.168.123.5 (192.168.123.5): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4

望答疑解惑,谢谢!

@zfl9
Copy link
Owner

zfl9 commented Nov 3, 2023

在其他局域网主机,执行 ssh -vv 192.168.123.5 看下什么错误?

@wnpllrzodiac
Copy link
Author

ssh -vv root@192.168.123.5
OpenSSH_9.0p1, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug2: resolve_canonicalize: hostname 192.168.123.5 is address
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to 192.168.123.5 [192.168.123.5] port 22.

卡住了

@zfl9
Copy link
Owner

zfl9 commented Nov 3, 2023

进入 n1 里面,看下 iptables 规则:

for t in raw mangle nat filter; do
    echo "========= $t ==========="
    iptables -t $t -S
done

@zfl9
Copy link
Owner

zfl9 commented Nov 3, 2023

我也用过 n1、rpi 作为 ss-tproxy “旁路由”,没见过这种情况。

另外,关闭 ss-tproxy 时,局域网内能访问 n1 吗(网关和 dns 这些不要动,还是指向 n1)

@wnpllrzodiac
Copy link
Author

========= raw ===========
-P PREROUTING ACCEPT
-P OUTPUT ACCEPT
========= mangle ===========
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-N SSTP_PREROUTING
-N SSTP_OUTPUT
-N SSTP_RULE
-A PREROUTING -j SSTP_PREROUTING
-A OUTPUT -j SSTP_OUTPUT
-A SSTP_PREROUTING -i lo -m mark ! --mark 0x2333 -j RETURN
-A SSTP_PREROUTING -p tcp -m addrtype ! --src-type LOCAL ! --dst-type LOCAL -j SSTP_RULE
-A SSTP_PREROUTING -p tcp -m mark --mark 0x2333 -j TPROXY --on-port 60080 --on-ip 127.0.0.1 --tproxy-mark 0x0/0x0
-A SSTP_OUTPUT -m owner --uid-owner 65534 --gid-owner 65534 -j RETURN
-A SSTP_OUTPUT -p tcp -m addrtype --src-type LOCAL ! --dst-type LOCAL -j SSTP_RULE
-A SSTP_RULE -j CONNMARK --restore-mark --nfmask 0xffffffff --ctmask 0xffffffff
-A SSTP_RULE -m mark --mark 0x2333 -j RETURN
-A SSTP_RULE -d 8.8.8.8/32 -p tcp -m tcp --dport 53 -j MARK --set-xmark 0x2333/0xffffffff
-A SSTP_RULE -d 8.8.8.8/32 -p tcp -m tcp --dport 53 -j RETURN
-A SSTP_RULE -p tcp -m set --match-set gfwlist dst -m multiport --dports 1:65535 -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j MARK --set-xmark 0x2333/0xffffffff
-A SSTP_RULE -j CONNMARK --save-mark --nfmask 0xffffffff --ctmask 0xffffffff
========= nat ===========
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P POSTROUTING ACCEPT
-P OUTPUT ACCEPT
-N SSTP_OUTPUT
-N SSTP_POSTROUTING
-A POSTROUTING -j SSTP_POSTROUTING
-A OUTPUT -j SSTP_OUTPUT
-A SSTP_OUTPUT -d 127.0.0.1/32 -p udp -m owner --uid-owner 65534 --gid-owner 65534 -m udp --dport 53 -j DNAT --to-destination 192.168.123.1:53
-A SSTP_POSTROUTING -d 192.168.123.1/32 -p udp -m owner --uid-owner 65534 --gid-owner 65534 -m udp --dport 53 -j MASQUERADE
-A SSTP_POSTROUTING -m addrtype ! --src-type LOCAL -m conntrack --ctstate SNAT,DNAT -j RETURN
-A SSTP_POSTROUTING -p tcp -m addrtype ! --src-type LOCAL -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j MASQUERADE
-A SSTP_POSTROUTING -p udp -m addrtype ! --src-type LOCAL -m conntrack --ctstate NEW -j MASQUERADE
-A SSTP_POSTROUTING -p icmp -m addrtype ! --src-type LOCAL -m conntrack --ctstate NEW -j MASQUERADE
========= filter ===========
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT

@wnpllrzodiac
Copy link
Author

我也用过 n1、rpi 作为 ss-tproxy “旁路由”,没见过这种情况。

另外,关闭 ss-tproxy 时,局域网内能访问 n1 吗(网关和 dns 这些不要动,还是指向 n1)

网关设置成默认路由器,而不是N1的时候是正常的。你说的这种,我没试过,我试试

@wnpllrzodiac
Copy link
Author

我也用过 n1、rpi 作为 ss-tproxy “旁路由”,没见过这种情况。
另外,关闭 ss-tproxy 时,局域网内能访问 n1 吗(网关和 dns 这些不要动,还是指向 n1)

网关设置成默认路由器,而不是N1的时候是正常的。你说的这种,我没试过,我试试

试过了。问题依旧。

外网可以端口映射到N1的ssh,或者先ssh登陆到路由器,再通过路由器ssh登陆到N1。感觉是WAN口可以ssh到N1,LAN口不行。

@zfl9
Copy link
Owner

zfl9 commented Nov 3, 2023

你这个 iptables 规则看起来是 旧版 ss-tproxy 的。是 4.6 吗?

@zfl9
Copy link
Owner

zfl9 commented Nov 3, 2023

尝试执行以下命令,将iptables规则完全清空,然后再试这个情况:

关闭 ss-tproxy 时,局域网内能访问 n1 吗(网关和 dns 这些不要动,还是指向 n1)

# 停止脚本 (v4.7版本之前)
ss-tproxy stop
ss-tproxy flush-postrule
ss-tproxy delete-gfwlist

# 停止脚本 (v4.7版本开始)
ss-tproxy stop
ss-tproxy flush-stoprule

@wnpllrzodiac
Copy link
Author

你这个 iptables 规则看起来是 旧版 ss-tproxy 的。是 4.6 吗?

不记得版本了,应该1,2年前装的了。没更新过。能在线更新吗?
另外,我发现我用手机连路由器,可以ssh登陆N1的。

问题应该是 我的mac电脑连了VPN。路由的问题。奇怪的是路由器的ip是可以连的。
先把issue close了吧。应该不是个issue。

@zfl9
Copy link
Owner

zfl9 commented Nov 3, 2023

不记得版本了,应该1,2年前装的了。没更新过。能在线更新吗?

如果有时间,更新下比较好,因为新版本有一些重要改进(主要是 iptables 规则)。

更新指南:https://github.com/zfl9/ss-tproxy?tab=readme-ov-file#%E5%8D%87%E7%BA%A7%E8%84%9A%E6%9C%AC

更新的话,其实就是先把原来的卸载,然后重新安装新版而已啦。

不过你这个问题应该和 ss-tproxy 版本无关了。


使用 ss-tproxy version 查看版本

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

2 participants