Shadowsocks原生支持tcp、udp,且轻量速度快,做前置代理是非常好的选择。原先是通过Shadowsocks-rust搭建的,由于很多网站挂Cloudflare的CDN,且很多网站开启了HTTP/3,发现打开有HTTP/3协议的网站就比较慢,怎么设置都无法解决,通过HTTP/2协议访问网站则一切正常。
后来通过sing-box重新搭建了shadowsocks前置代理,在使用过程中发现,一打开网站sing-box就很大几率会报错udp message too long,可能这跟打开有HTTP/3协议的网站慢有关。
root@example:~# journalctl -u sing-box --output cat -f +0800 2024-12-22 17:34:21 ERROR inbound/shadowsocks[ss-in]: write back udp: write udp [::]:9527->1.2.3.4:16545: sendto: message too long +0800 2024-12-22 17:34:22 ERROR inbound/shadowsocks[ss-in]: write back udp: write udp [::]:9527->1.2.3.4:16545: sendto: message too long +0800 2024-12-22 17:34:22 ERROR inbound/shadowsocks[ss-in]: write back udp: write udp [::]:9527->1.2.3.4:43712: sendto: message too long +0800 2024-12-22 17:34:23 ERROR inbound/shadowsocks[ss-in]: write back udp: write udp [::]:9527->1.2.3.4:43712: sendto: message too long +0800 2024-12-22 17:34:23 ERROR inbound/shadowsocks[ss-in]: write back udp: write udp [::]:9527->1.2.3.4:43712: sendto: message too long
可以看到由于UDP数据包大,导致发送失败。尝试设置了IP分片、MTU,提高系统udp缓冲区设置等等,均无效果,还是提示message too long。后来加入了singbox内置的udp分片设置,message too long 提示不再出现。
打开sing-box的配置文件/etc/sing-box/config.json,在shadowsocks结构内加入udp_fragment
udp_timeout
字段即可解决,也就是加入:
{ "type": "shadowsocks", "tag": "ss-in", "udp_fragment": true, "udp_timeout": "5m", ... // 其他 }
完整配置见:https://www.bandwh.com/net/2175.html
IP分片 UDP分片的介绍见:https://www.bandwh.com/net/2157.html
看了下Shadowsocks-rust的Issues,Shadowsocks-rust也将支持UDP分片,目前还未正式发布,好像是配置outbound_udp_allow_fragmentation
这个字段。目前sing-box虽然不报错了,打开有HTTP/3协议的网站还是不如HTTP/2,但比之前改善较多,可能问题主要出在Cloudflare身上。
技术不断升级,请注意文章时效性。
本站文章,欢迎转发。转载请注明出处:https://www.bandwh.com/net/2191.html