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

socks5 vs socks5h #109

Open
lanlin opened this issue Dec 2, 2021 · 0 comments
Open

socks5 vs socks5h #109

lanlin opened this issue Dec 2, 2021 · 0 comments

Comments

@lanlin
Copy link
Owner

lanlin commented Dec 2, 2021

情景

明明已经设置好了代理,通过浏览器访问正常。

但是通过 curl 等工具访问时却怎么也不行。

那么这篇短文可能会有所帮助。

1)curl https://www.google.com -x 127.0.0.1:1081
2)curl https://www.google.com -x http://127.0.0.1:1081
3)curl https://www.google.com -x socks://127.0.0.1:1080
4)curl https://www.google.com -x socks4://127.0.0.1:1080
5)curl https://www.google.com -x socks5://127.0.0.1:1080
6)curl https://www.google.com -x socks4a://127.0.0.1:1080
7)curl https://www.google.com -x socks5h://127.0.0.1:1080

如上所示,在 curl 中,可以使用 -x 指定 curl 通过某个隧道来连接网络。

一般而言,大部分的代理工具(如 V2RayN),提供的是通用的 http 隧道和 socks5 隧道。

默认情况下,curl 使用的就是 http 隧道(第一种和第二种情况)。

而在使用 socks 隧道时,默认使用的是 socks4 隧道(第三种和第四种)。

只有在显式声明使用 socks5 时,才会真正走 socks5 隧道。

代理域名解析机制

  1. socks(默认为 socks4), socks4 和 socks5 隧道都是由本机进行目标域名的 DNS 解析的。

  2. http,socks4a 和 socks5h 都是由代理端服务器完成 DNS 解析的。

也就是说通过修改本机的 hosts 是可以影响到 socks4 与 socks5 代理后的目标 IP 地址。

说明 socks4 和 socks5 在 DNS 受污染区域(墙内)是有很大可能会导致访问失败的。

结论

  1. 修改本机 DNS 服务器,直接用墙外的(速度及可靠性很难保障)

  2. 直接用 http, socks4a 和 socks5h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant