sing-box icon indicating copy to clipboard operation
sing-box copied to clipboard

Regression in 1.13.2 on Linux TUN + hijack-dns: systemd-resolved DNS loops to 127.0.0.1:53, while 1.12.4 works

Open LuciusChen opened this issue 8 months ago • 11 comments

Checklist

  • [x] I searched existing issues
  • [x] I can reproduce this on the same machine with the same config
  • [x] 1.12.4 works, 1.13.2 fails

Environment

  • OS: Arch Linux
  • DNS stack: systemd-resolved + NetworkManager
  • sing-box mode: TUN + hijack-dns
  • Working version: 1.12.4
  • Broken version: 1.13.2

Summary

I hit a regression after upgrading sing-box from 1.12.4 to 1.13.2.

On the same machine, with the same sing-box config:

  • 1.12.4 works
  • 1.13.2 breaks DNS resolution

When broken, raw IP connectivity still works, but domain resolution fails.

For example:

  • ping 1.1.1.1 works
  • ping archlinux.org fails with name resolution errors

After downgrading back to 1.12.4, DNS works again.

Relevant observations

When the problem happens on 1.13.2, resolvectl status shows that tun0 is injected as the default DNS path:

  • DNS Servers: 172.19.0.2
  • DNS Domain: ~.

At the same time, sing-box logs repeatedly show systemd-resolved traffic being routed to 127.0.0.1:53, which fails:

router: found process path: /usr/lib/systemd/systemd-resolved, user: systemd-resolve
outbound/direct[DIRECT]: outbound connection to 127.0.0.1:53
dial tcp 127.0.0.1:53: connect: connection refused

Important detail

My config does not use DNS server type: "local".

The DNS section is using legacy UDP server entries such as:

"dns": { "servers": [ { "tag": "dns_proxy", "type": "udp", "server": "8.8.8.8", "detour": "Auto" }, { "tag": "dns_direct", "type": "udp", "server": "223.5.5.5" } ], "final": "dns_proxy" }

And the route section includes:

{ "protocol": "dns", "action": "hijack-dns" }

TUN inbound is roughly:

{ "type": "tun", "tag": "tun-in", "interface_name": "tun0", "address": ["172.19.0.1/30"], "auto_route": true, "strict_route": true, "sniff": true, "sniff_override_destination": true }

Resolver state

I also checked the resolver files:

  • /etc/resolv.conf points to stub-resolv.conf
  • /run/systemd/resolve/stub-resolv.conf contains 127.0.0.53
  • I did not find any persistent config explicitly setting DNS to 127.0.0.1

So 127.0.0.1:53 seems to appear at runtime during the 1.13.2 failure path, not from an obvious static config file.

What I tried

These did not fix the problem on 1.13.2:

  • changing dns.final from dns_proxy to dns_direct
  • changing strict_route
  • changing auto_route
  • excluding systemd-resolve UID from TUN
  • excluding 127.0.0.0/8 from route

Temporary workaround while still on 1.13.2:

sudo resolvectl revert tun0

That restores DNS, but only as a workaround.

Regression window

  • good: 1.12.4
  • bad: 1.13.2

On 1.12.4, I can resolve and access domains normally again on the same host.

Related issue

This looks related to #3235, but my repro is different because I am not using DNS server type: "local".

Notes

I already downgraded back to 1.12.4 to restore connectivity on the machine. If needed, I can reproduce again on 1.13.2 and collect fresh outputs for:

  • ip route
  • ip rule
  • full journalctl -u sing-box
  • resolvectl status

LuciusChen avatar Mar 09 '26 06:03 LuciusChen

Check 6ebedf1a4097d51024dc333fd4c0ecc82314afdf

nekohasekai avatar Mar 09 '26 07:03 nekohasekai

Hi, I encountered the exact same underlying issue on 1.13.x (though in my case, it was on Android TUN, the root cause is identical).

The Root Cause: It seems there's a regression or behavior change in how 1.13.x handles UDP sniffing in TUN mode. The L7 protocol: "dns" rule fails to catch the initial UDP DNS packets in time. As a result, these packets bypass the hijack-dns action and fall into the standard routing table.

In your case (Linux + systemd-resolved), it causes a routing loop to 127.0.0.1:53.

In my case, it caused the virtual gateway IP 172.19.0.2:53 to hit the geoip-private rule and go to a blackhole.

The Workaround: Instead of relying solely on L7 protocol sniffing, you can use L4 port matching to force the hijack. It's much faster and completely bypasses the sniffing delay.

Simply add this rule to the very top of your route.rules:

{
  "port": [53],
  "action": "hijack-dns"
}

Because port matching evaluates the L4 header instantly, it will safely catch all your systemd-resolved DNS requests before they have a chance to loop. Hope this helps until the upstream sniffing logic is patched!

eurekaevan avatar Mar 09 '26 08:03 eurekaevan

+0800 2026-03-10 11:29:33 ERROR [1105544691 791ms] router: process DNS packet: listen udp 127.0.0.1:53: bind: address already in use +0800 2026-03-10 11:29:33 ERROR [2570306806 792ms] router: process DNS packet: listen udp 127.0.0.1:53: bind: address already in use +0800 2026-03-10 11:29:33 ERROR [1613615423 792ms] router: process DNS packet: listen udp 127.0.0.1:53: bind: address already in use +0800 2026-03-10 11:29:33 ERROR [2730059633 765ms] router: process DNS packet: listen udp 127.0.0.1:53: bind: address already in use

Similar issues, on Android with root access, using tproxy can cause this

ljr-impl avatar Mar 10 '26 03:03 ljr-impl

怎么样 怎么样 修复没

sbwml avatar Mar 14 '26 06:03 sbwml

Check 6ebedf1

之前节点域名不管用远程 DNS 解析还是直连DNS解析都可以正常解析出IP的!现在1.13.0用远程DNS无法解析出来IP了!

应该是1.13.0版本引入的!1.12.24的时候好像都是正常的!

1.13.2的版本

+0800 2026-03-12 16:26:17 ERROR [4002897648 2.29s] connection: open connection to 76.76.2.11:443 using outbound/vless[default:🇭🇰香港02-0.1倍]: lookup XXXXXXXX: (exchange6: SERVFAIL | exchange4: SERVFAIL) +0800 2026-03-12 16:26:17 ERROR [976979187 1.90s] connection: open connection to 9.9.9.10:853 using outbound/vless[default:🇭🇰香港02-0.1倍]: lookup XXXXXXX: (exchange6: SERVFAIL | exchange4: SERVFAIL)

大量的节点域名解析错误!1.12.24版本是正常可用的!一度让我怀疑鸡场炸了!

Aukansh avatar Mar 14 '26 07:03 Aukansh

1.13.3 版本依旧未修复

LuciusChen avatar Mar 16 '26 02:03 LuciusChen

This happens to me as well. To allow the system resolver do its job I have to disable auto_redirect as well as sudo resolvectl revert tun0.

I don't have any dns entries in the sing-box configuration file since I want to keep dns resolution the default way. But for some reason, sing-box still catches dns queries with firewall rules and resolvectl. But then fails to handle them. Is there a reason it's done this way?

$ sing-box version
sing-box version 1.13.11

Environment: go1.25.9 linux/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,with_ocm,with_naive_outbound,badlinkname,tfogo_checklinkname0,with_musl
Revision: 553cfa1f9f99f4da6118f93d507294e580db00d7
CGO: enabled
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 26.04 LTS
Release:	26.04
Codename:	resolute
$ cat /etc/sing-box/config.json
{
    "inbounds": [
        {
            "type": "tun",
            "interface_name": "tun0",
            "mtu": 1400,
            "address": ["10.0.1.1/30"],
            "auto_route": true,
            // bug: UDP responses not handled when auto_redirect enabled in TUN on Alpine Linux — https://github.com/SagerNet/sing-box/issues/3560
            // from docs: auto_redirect is always recommended on Linux, it provides better routing, higher performance (better than tproxy), and avoids conflicts between TUN and Docker bridge networks.
            "auto_redirect": false,
            "strict_route": false
        },
        {
            "type": "socks",
            "tag": "socks-in",
            "listen": "127.0.0.1",
            "listen_port": 1080
        }
    ],
    "outbounds": [
        {
            "type": "direct",
            "tag": "direct"
        },
        {
            "tag": "proxy",
            "type": "vless",
            <...>
        }
    ],
    "route": {
        "auto_detect_interface": true,
        "final": "proxy",
        "rules": [
            {
                "network": "icmp",
                "outbound": "direct"
            }
        ]
    }
}

dangoodman avatar Apr 29 '26 18:04 dangoodman

Could you check if this has been correctly fixed in the latest stable version?

nekohasekai avatar Aug 21 '26 05:08 nekohasekai

I don't see any changes to this issue.

my@ubuntu:~$ sing-box version
sing-box version 1.14.0

Environment: go1.26.7 linux/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,with_ocm,with_cloudflared,with_naive_outbound,with_usbip,with_openvpn,with_openconnect,badlinkname,tfogo_checklinkname0,with_musl
Revision: 0b8995879f29a9b98ee027bc17b75e101445b238
CGO: enabled


my@ubuntu:~$ resolvectl status
Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub

Link 2 (eth0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.88.1
       DNS Servers: 192.168.88.1
     Default Route: yes

Link 3 (wlp2s0b1)
    Current Scopes: none
         Protocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
     Default Route: no

Link 4 (tun0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 10.0.1.2
       DNS Servers: 10.0.1.2
        DNS Domain: ~.
     Default Route: yes

     
my@ubuntu:~$ dig google.com
;; communications error to 127.0.0.53#53: timed out
;; communications error to 127.0.0.53#53: timed out
;; communications error to 127.0.0.53#53: timed out

; <<>> DiG 9.20.24-1ubuntu0.3-Ubuntu <<>> google.com
;; global options: +cmd
;; no servers could be reached


my@ubuntu:~$ sudo resolvectl revert tun0
my@ubuntu:~$ resolvectl status
Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub

Link 2 (eth0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.88.1
       DNS Servers: 192.168.88.1
     Default Route: yes

Link 3 (wlp2s0b1)
    Current Scopes: none
         Protocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
     Default Route: no

Link 4 (tun0)
    Current Scopes: none
         Protocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
     Default Route: no

     
my@ubuntu:~$ dig google.com

; <<>> DiG 9.20.24-1ubuntu0.3-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25439
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;google.com.			IN	A

;; ANSWER SECTION:
google.com.		54	IN	A	172.253.152.101
google.com.		54	IN	A	172.253.152.102
google.com.		54	IN	A	172.253.152.113
google.com.		54	IN	A	172.253.152.138
google.com.		54	IN	A	172.253.152.139
google.com.		54	IN	A	172.253.152.100

;; Query time: 26 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Thu Sep 03 13:19:40 UTC 2026
;; MSG SIZE  rcvd: 135

/etc/sing-box/config.json:

{
   ...
    "inbounds": [
       {
           "type": "tun",
           "interface_name": "tun0",
           "mtu": 1400,
           "address": ["10.0.1.1/30"],
           "auto_route": false,
           "auto_redirect": false,
           "strict_route": false
       }
    ...
}

dangoodman avatar Sep 03 '26 13:09 dangoodman

The issue is that there is no way to stop Sing-box hijacking DNS queries. Given the configuration above, the path of a DNS query looks like this:

  1. App issues a UDP 53 request.
  2. This request gets to Sing-box
  3. Sing-box hijacks this request. Now it needs to re-issue this request on its own.
  4. Since no DNS settings are configured, it goes through the system resolver. Goto 1.

An option to stop hijacking DNS requests, i.e. treat them as regular UDP traffic, should do it.

dangoodman avatar Sep 03 '26 14:09 dangoodman

I think v1.14 gives us a fairly clean way to separate the two possible failure paths in this issue.

One important detail is that omitting TUN dns_mode does not mean "leave the system DNS configuration alone".

In current sing-tun:

func (o *Options) DNSModeOrDefault() string {
    if o.DNSMode == "" {
        return DNSModeHijack
    }
    return o.DNSMode
}

So the default is still hijack.

On Linux, when DNS mode is enabled, the TUN setup calls the equivalent of:

resolvectl domain <tun> ~.
resolvectl default-route <tun> true
resolvectl dns <tun> <dns-address>

This explains the apparently mysterious state reported here:

DNS Servers: 172.19.0.2
DNS Domain: ~.

even when that address is nowhere in the user's DNS configuration.

If dns_address is not explicitly configured, sing-tun derives it from the TUN prefix. For:

172.19.0.1/30

the automatically selected IPv4 DNS address is:

172.19.0.2

So this part is generated by the TUN DNS integration itself, not by NetworkManager or a hidden /etc/resolv.conf setting.

sing-box 1.14 added explicit TUN DNS modes (sing-tun commit 3131749737becfa54c14fe72fbfdca3ab4498bfd):

"dns_mode": "disabled"
"dns_mode": "native"
"dns_mode": "hijack"

Their current semantics are useful for diagnosing this issue:

  • disabled: don't configure platform/native DNS and don't add automatic TUN DNS hijacking;
  • native: configure the platform TUN DNS, but don't add the broad port-53 hijack;
  • hijack: native + port-53 hijacking; this is the default.

I would therefore suggest retesting the original reproducer on v1.14.x with exactly the same explicit route rule:

{
  "protocol": "dns",
  "action": "hijack-dns"
}

but testing the three TUN modes separately.

1. dns_mode: "disabled"

After startup, resolvectl status tun0 should no longer acquire the sing-box-generated:

DNS Server: 172.19.0.2
DNS Domain: ~.
DefaultRoute: yes

If DNS works in this mode, while the explicit protocol: dns -> hijack-dns rule is still present, then the regression is probably not primarily an L7 DNS-sniff failure.

It would point to the native systemd-resolved integration / TUN DNS takeover path instead.

2. dns_mode: "native"

If disabled works but native fails, that narrows the issue further to the systemd-resolved interface-DNS setup itself.

3. dns_mode: "hijack"

If native works but hijack fails, the additional automatic port-53 interception is the likely regression.

If all three fail, including disabled, then investigating the explicit protocol: dns sniff + RuleActionHijackDNS path makes sense.

This also answers the later report from a user with no DNS section at all: with the default TUN settings, DNS integration is still enabled because empty dns_mode resolves to hijack.

I haven't reproduced this on a systemd-resolved host, so this is source-level analysis rather than runtime confirmation. But the three-mode test should distinguish the currently mixed failure paths much more precisely than changing strict_route, UID exclusions, or resolver addresses.

HeisLuka avatar Sep 09 '26 23:09 HeisLuka