[Feature Request] Automatic / Smart Selection of Network Egress Interface
After the TUN inbound is implemented, there is an important detail users need to handle: for every outbound, sockopt.interface must be explicitly set to a physical egress network interface. Otherwise, traffic may fall back to the TUN inbound by default, causing a routing loop.
I’d like to propose adding a new high-level option to sockopt, for example:
sockopt.excludedInterface = "utun99"
This option would specify which network interfaces should be avoided. When it is set, the system would:
- Automatically retrieve the list of available network interfaces
- Sort them by routing priority / hop distance
- Exclude the specified interfaces (e.g.
utun99) - Select the highest-priority remaining interface (e.g.
en0)
The end result would be functionally equivalent to setting:
sockopt.interface = "en0"
but without requiring users to hardcode the actual egress interface name.
As an alternative design, we could continue using sockopt.interface but extend its string syntax with rules, for example:
sockopt.interface = "excluded:utun99"
This would indicate that the outbound should automatically select an interface, excluding the specified one(s).
我觉得核心提供一个接口就行了 别的乱七八糟的工作就给客户端吧 涉及到乱七八糟自动/智能处理 结果就把一个简单一个系统调用 又变复杂 今天auto interface 明天就auto route了 就算真要搞 也放在auto route的时候再搞吧(如果真的有)
于我个人直接跑裸 core 的使用体验而言,core 自带 auto-interface、auto-route 什么的还是会方便不少的
不过实现上可能不会改 sockopt interface 配置项,而是 tun 入站配置了 auto-route 后,出站没配置 interface 的就自动避开入站 tun
https://github.com/XTLS/Xray-core/pull/5887 Windows 已支持 autoSystemRoutingTable 和 autoOutboundsInterface,其它系统 PR welcome
现在 autoOutbuondsInterface 和 autoSystemRoutingTable 支持 macOS 和 Linux 了
还剩个 FreeBSD https://github.com/XTLS/Xray-core/pull/6366#issuecomment-4788510365
{
"tag": "tun-in",
"protocol": "tun",
"settings": {
"name": "xray0",
"mtu": 1500,
"gateway": [
"198.18.0.1",
"198.18.0.2"
],
"autoSystemRoutingTable": [
"192.168.201.0/24"
],
"autoOutboundsInterface": "auto"
}
}
这样配置在alpine 3.22 x86_64上不能自动创建 192.168.201.0/24 到xray0的路由