[GH-ISSUE #6366] [Feature]: Follow-up to #3821 (“Wireguard inbound icmp issue”). Investigated and reproduced on self-hosted 3x-ui 3.4.0 / AmneziaWG inbound. #4320

Open
opened 2026-10-31 20:38:48 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @dexiusprime-oss on GitHub (Aug 30, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6366

Problem

With a 3x-ui WireGuard/AmneziaWG inbound (protocol=wireguard|amneziawg):

✅ client connects; tunnel up
✅ TCP/UDP to the internet works (HTTP/HTTPS, SSH)
✅ ping (e.g. 10.8.1.1) works — answered locally by xray
❌ ping to any internet IP → 100% loss
❌ ping to another WG client in the same subnet → 100% loss
❌ traceroute outside the tunnel → all hops *
Confirmed on Debian 11, 3x-ui 3.4.0, AmneziaWG inbound (port 44219, subnet 10.8.1.0/24, server 10.8.1.1, client 10.8.1.2, mtu 1380). MTU is fine (DF probe boundary exactly 1380); DNS routing is a separate matter.

Root-cause hypothesis

The WG/AWG inbound is implemented userspace, inside xray (there is no kernel wg0 / awg0 interface on the host — the same observation as in #3821). As a result:

ICMP is stateless and there is no proxying “session” for it, and the panel does not install the L3 plumbing a real WG tunnel needs:
net.ipv4.ip_forward
iptables/nftables MASQUERADE (POSTROUTING) for the WG subnet
a kernel route for the WG subnet / AllowedIPs, and per-peer routing
TCP/UDP happen to work because xray opens an outbound socket and binds replies back to the inbound flow.
So it’s a TCP/UDP proxy masquerading as a VPN, not a true layer-3 network.

Describe the solution you'd like

Make WireGuard/AmneziaWG inbound behave as a full L3 VPN (feature):

Kernel integration (preferred): wire up the WG/AWG tunnel at the kernel level (wg-quick / wireguard-linux / AWG kernel module) when the panel creates an inbound — create the real interface, assign subnet, add peer routes from AllowedIPs/settings.clients.
L3 plumbing for the subnet:
enable ip_forward for the WG interface,
install MASQUERADE/NAT (POSTROUTING) so replies return,
allow client-to-client traffic within the WG subnet,
route ICMP (echo) to/from the internet.
Panel surface: expose the knob (e.g. “kernel mode” / “userspace mode”) and the subnet/NAT settings so it’s configurable, not hardcoded.
Verification criteria (what “works” means):
ping to internet IPs from a WG client → reply,
ping client-to-client within the subnet → reply,
ping still works,
TCP/UDP keep working,
external port only needs the single WG UDP port (no per-client NAT port).
Acceptance test (already scriptable)

From a connected WG client:

ping # must PASS
ping 1.1.1.1 # must PASS after fix (currently 100% loss)
ping # must PASS after fix (currently 100% loss)
curl -4 https://ifconfig.me # must still PASS
Environment

3x-ui: 3.4.0 (Debian 11 bullseye)
xray: latest from panel
Inbound: AmneziaWG, MTU 1380, subnet 10.8.1.0/24
Host: Debian 11, kernel supports WireGuard natively (no custom module needed)
If a fully kernel-backed tunnel is out of scope for xray, a fallback would be to add the L3 plumbing (ip_forward + NAT + subnet route) around the userspace inbound — that alone fixes ICMP transit and client-to-client.

Alternatives you've considered

No response

Concrete use case

No response

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

No response

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @dexiusprime-oss on GitHub (Aug 30, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6366 ### Is your feature request related to a problem? Problem With a 3x-ui WireGuard/AmneziaWG inbound (protocol=wireguard|amneziawg): ✅ client connects; tunnel up ✅ TCP/UDP to the internet works (HTTP/HTTPS, SSH) ✅ ping <server-tunnel-ip> (e.g. 10.8.1.1) works — answered locally by xray ❌ ping to any internet IP → 100% loss ❌ ping to another WG client in the same subnet → 100% loss ❌ traceroute outside the tunnel → all hops * Confirmed on Debian 11, 3x-ui 3.4.0, AmneziaWG inbound (port 44219, subnet 10.8.1.0/24, server 10.8.1.1, client 10.8.1.2, mtu 1380). MTU is fine (DF probe boundary exactly 1380); DNS routing is a separate matter. Root-cause hypothesis The WG/AWG inbound is implemented userspace, inside xray (there is no kernel wg0 / awg0 interface on the host — the same observation as in #3821). As a result: ICMP is stateless and there is no proxying “session” for it, and the panel does not install the L3 plumbing a real WG tunnel needs: net.ipv4.ip_forward iptables/nftables MASQUERADE (POSTROUTING) for the WG subnet a kernel route for the WG subnet / AllowedIPs, and per-peer routing TCP/UDP happen to work because xray opens an outbound socket and binds replies back to the inbound flow. So it’s a TCP/UDP proxy masquerading as a VPN, not a true layer-3 network. ### Describe the solution you'd like Make WireGuard/AmneziaWG inbound behave as a full L3 VPN (feature): Kernel integration (preferred): wire up the WG/AWG tunnel at the kernel level (wg-quick / wireguard-linux / AWG kernel module) when the panel creates an inbound — create the real interface, assign subnet, add peer routes from AllowedIPs/settings.clients. L3 plumbing for the subnet: enable ip_forward for the WG interface, install MASQUERADE/NAT (POSTROUTING) so replies return, allow client-to-client traffic within the WG subnet, route ICMP (echo) to/from the internet. Panel surface: expose the knob (e.g. “kernel mode” / “userspace mode”) and the subnet/NAT settings so it’s configurable, not hardcoded. Verification criteria (what “works” means): ping to internet IPs from a WG client → reply, ping client-to-client within the subnet → reply, ping <server-tunnel-ip> still works, TCP/UDP keep working, external port only needs the single WG UDP port (no per-client NAT port). Acceptance test (already scriptable) From a connected WG client: ping <server-tunnel-ip> # must PASS ping 1.1.1.1 # must PASS after fix (currently 100% loss) ping <other-wg-client-ip> # must PASS after fix (currently 100% loss) curl -4 https://ifconfig.me # must still PASS Environment 3x-ui: 3.4.0 (Debian 11 bullseye) xray: latest from panel Inbound: AmneziaWG, MTU 1380, subnet 10.8.1.0/24 Host: Debian 11, kernel supports WireGuard natively (no custom module needed) If a fully kernel-backed tunnel is out of scope for xray, a fallback would be to add the L3 plumbing (ip_forward + NAT + subnet route) around the userspace inbound — that alone fixes ICMP transit and client-to-client. ### Alternatives you've considered _No response_ ### Concrete use case _No response_ ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? _No response_ ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [ ] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 30, 2026):

Your observations are accurate, but the root cause you propose is not the one in the code — and the fallback you suggest (net.ipv4.ip_forward + MASQUERADE + a subnet route) would change nothing, because no decapsulated tunnel packet ever reaches the host kernel in the first place. Treating this as a valid feature request for ICMP transit + client-to-client, not as a bug, and explaining below exactly where it would have to land.

Why ICMP does not transit

Both WireGuard-family inbounds are userspace, but in two different processes:

  • amneziawg inbounds are terminated inside the panel process — internal/amneziawgnet/netstack.go:1, "Package amneziawgnet embeds amneziawg-go … directly in the panel process". They are deliberately excluded from the generated Xray config at internal/web/service/xray.go:177:

    if inbound.Protocol == model.MTProto || inbound.Protocol == model.AmneziaWG {
        continue
    }
    
  • wireguard inbounds are handed to xray-core: peers are rewritten into xray's shape at internal/database/model/model.go:364 (case WireGuard: → WireguardClientsToPeers) and emitted at internal/web/service/xray.go:246.

In the embedded stack, ICMP is registered — internal/amneziawgnet/netstack.go:62:

TransportProtocols: []stack.TransportProtocolFactory{tcp.NewProtocol, udp.NewProtocol, icmp.NewProtocol6, icmp.NewProtocol4},

That registration is why ping 10.8.1.1 answers: the userspace stack replies to an echo addressed to its own interface address. But only two transport handlers are ever attached, and neither is ICMP:

  • internal/amneziawgnet/forwarder.go:42 — gstack.SetTransportProtocolHandler(tcp.ProtocolNumber, fwd.HandlePacket)
  • internal/amneziawgnet/udp.go:34 — gstack.SetTransportProtocolHandler(udp.ProtocolNumber, func(...) bool {

Everything that leaves the tunnel leaves through a loopback SOCKS5 dial into Xray: RelayTCP issues a SOCKS5 CONNECT (internal/amneziawgnet/relay.go:67), and UDP goes over UDP ASSOCIATE (relay.go:44-45, "udp:true is required: RelayUDP depends on the inbound accepting UDP ASSOCIATE, not just CONNECT"). RFC 1928 defines CONNECT, BIND and UDP ASSOCIATE — there is no verb that can carry an ICMP echo, so ICMP has no representation on that egress path at all. For wireguard inbounds the same shape applies one layer over: this repo's own forwarder is annotated "Adapted from xtls/xray-core's proxy/wireguard/tun.go createForwarder (MIT)" (forwarder.go:22) and its UDP path likewise (udp.go:28-30), with netstack.go:38-41 noting xray-core's proxy/wireguard/netstack.go takes the same gVisor approach — TCP and UDP paths only. (That last part about xray-core is an inference from these comments; I did not read the xray-core source here.)

Why ip_forward + MASQUERADE cannot fix it

There is no kernel interface for those rules to act on. The repo states this directly — internal/amneziawgnet/portfwd.go:5-8:

// real world), and this path's replacement for the retired kernel-module
// architecture's PostUp/PostDown iptables DNAT rules: there's no real OS
// network interface here for DNAT to rewrite packets on, the same root
// reason Phase 3.5's IPv6 alias mechanism couldn't reuse NDP-proxy either.

A 10.8.1.x packet exists only as bytes inside a gVisor stack.Stack in the panel's address space. It never enters the host's IP stack, so it never traverses FORWARD, never hits POSTROUTING, and net.ipv4.ip_forward never applies. That is also why per-client port forwarding had to be reimplemented as real Go listeners instead of DNAT rules.

Client-to-client is a separate, non-ICMP problem too

ping 10.8.1.3 failing is not really an ICMP issue. The TCP forwarder relays every destination into Xray's SOCKS5 inbound, tunnel-internal addresses included (internal/amneziawgnet/manager.go:177-198), and Xray cannot reach them — portfwd.go:12-16:

// through Xray's own SOCKS5 inbound the way the outbound direction does
// (relay.go): Xray runs as a genuinely separate OS process
// (internal/xray/process.go), so it has no visibility into this process's
// private, in-memory netstack at all -- a tunnel-internal address like
// 10.8.1.5:8080 has no route from Xray's own freedom outbound; only code
// holding the actual *stack.Stack can reach it.

So TCP between two peers on the same inbound does not work either, for the same reason. Worth noting because this half needs no kernel work at all — it is a short-circuit inside the stack before the relay — and is much smaller than the ICMP half.

On "kernel mode" as a panel option

That path existed in this fork and was deliberately removed — internal/amneziawg/instance.go:4-10:

// longer manages any OS-level interface itself: that was the kernel-module
// (DKMS) + awg-quick + TPROXY architecture this fork shipped originally,
// retired in favor of an embedded, pure-Go one (amneziawg-go over a gVisor
// netstack, see internal/amneziawgnet) in a hard cutover.

Reintroducing it as a toggle means reintroducing DKMS builds, Secure Boot signing and container-vs-bare-metal divergence, and it would bypass the SOCKS5 relay that currently supplies per-client stats, quota and routing (relay.go:1-6). That is a maintainer-level architectural call, not a small addition — flagging the cost rather than arguing against the request.

One correction on your environment

3x-ui 3.4.0 has no amneziawg protocol. At v3.4.0 the constants in internal/database/model/model.go end at MTProto Protocol = "mtproto"; AmneziaWG Protocol = "amneziawg" was added by commit effcccce ("feat(amneziawg): add native AmneziaWG protocol support (#6105)", 2026-08-24), whose first tag is v3.7.0. So what you tested is a wireguard inbound, possibly configured from an Amnezia client app. It does not change the conclusion — both are userspace and neither transits ICMP — but if you want to re-run your acceptance script against the embedded stack described above, you need v3.7.0 or newer.

Two things I could not settle here, since I cannot run the panel: whether v3.7.0's promiscuous+spoofing NIC (netstack.go:229-232) causes gVisor to answer echo requests addressed to arbitrary destinations — if it does, ping 1.1.1.1 would appear to pass while being a locally forged reply rather than real transit, which your acceptance test could not distinguish; and whether IPv6 behaves identically. Running your four-command script on v3.7.0 and reporting the raw output would settle both.

Related: #3821 (the original report, closed as a question) and #6350, which answered the kernel-vs-userspace question for 3.7.0. Neither shares a defect with this, so this stays open on its own. No documentation page currently states the ICMP limitation — grep -rn -i icmp docs/content/docs/en/ matches only config/transports.mdx:128 (the xicmp UDP mask, unrelated) — so documenting it is arguably the smallest useful step here.

Verdict: Feature request

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:5468653188 --> @github-actions[bot] commented on GitHub (Aug 30, 2026): Your observations are accurate, but the root cause you propose is not the one in the code — and the fallback you suggest (`net.ipv4.ip_forward` + `MASQUERADE` + a subnet route) would change nothing, because no decapsulated tunnel packet ever reaches the host kernel in the first place. Treating this as a valid feature request for ICMP transit + client-to-client, not as a bug, and explaining below exactly where it would have to land. ## Why ICMP does not transit Both WireGuard-family inbounds are userspace, but in two different processes: * `amneziawg` inbounds are terminated inside the **panel** process — `internal/amneziawgnet/netstack.go:1`, "Package amneziawgnet embeds amneziawg-go … directly in the panel process". They are deliberately excluded from the generated Xray config at `internal/web/service/xray.go:177`: ```go if inbound.Protocol == model.MTProto || inbound.Protocol == model.AmneziaWG { continue } ``` * `wireguard` inbounds are handed to **xray-core**: peers are rewritten into xray's shape at `internal/database/model/model.go:364` (`case WireGuard:` → `WireguardClientsToPeers`) and emitted at `internal/web/service/xray.go:246`. In the embedded stack, ICMP *is* registered — `internal/amneziawgnet/netstack.go:62`: ```go TransportProtocols: []stack.TransportProtocolFactory{tcp.NewProtocol, udp.NewProtocol, icmp.NewProtocol6, icmp.NewProtocol4}, ``` That registration is why `ping 10.8.1.1` answers: the userspace stack replies to an echo addressed to its own interface address. But only two transport handlers are ever attached, and neither is ICMP: * `internal/amneziawgnet/forwarder.go:42` — `gstack.SetTransportProtocolHandler(tcp.ProtocolNumber, fwd.HandlePacket)` * `internal/amneziawgnet/udp.go:34` — `gstack.SetTransportProtocolHandler(udp.ProtocolNumber, func(...) bool {` Everything that leaves the tunnel leaves through a loopback SOCKS5 dial into Xray: `RelayTCP` issues a SOCKS5 CONNECT (`internal/amneziawgnet/relay.go:67`), and UDP goes over UDP ASSOCIATE (`relay.go:44-45`, "udp:true is required: RelayUDP depends on the inbound accepting UDP ASSOCIATE, not just CONNECT"). RFC 1928 defines CONNECT, BIND and UDP ASSOCIATE — there is no verb that can carry an ICMP echo, so ICMP has no representation on that egress path at all. For `wireguard` inbounds the same shape applies one layer over: this repo's own forwarder is annotated "Adapted from xtls/xray-core's `proxy/wireguard/tun.go` createForwarder (MIT)" (`forwarder.go:22`) and its UDP path likewise (`udp.go:28-30`), with `netstack.go:38-41` noting xray-core's `proxy/wireguard/netstack.go` takes the same gVisor approach — TCP and UDP paths only. *(That last part about xray-core is an inference from these comments; I did not read the xray-core source here.)* ## Why ip_forward + MASQUERADE cannot fix it There is no kernel interface for those rules to act on. The repo states this directly — `internal/amneziawgnet/portfwd.go:5-8`: ```go // real world), and this path's replacement for the retired kernel-module // architecture's PostUp/PostDown iptables DNAT rules: there's no real OS // network interface here for DNAT to rewrite packets on, the same root // reason Phase 3.5's IPv6 alias mechanism couldn't reuse NDP-proxy either. ``` A `10.8.1.x` packet exists only as bytes inside a gVisor `stack.Stack` in the panel's address space. It never enters the host's IP stack, so it never traverses `FORWARD`, never hits `POSTROUTING`, and `net.ipv4.ip_forward` never applies. That is also why per-client port forwarding had to be reimplemented as real Go listeners instead of DNAT rules. ## Client-to-client is a separate, non-ICMP problem too `ping 10.8.1.3` failing is not really an ICMP issue. The TCP forwarder relays *every* destination into Xray's SOCKS5 inbound, tunnel-internal addresses included (`internal/amneziawgnet/manager.go:177-198`), and Xray cannot reach them — `portfwd.go:12-16`: ```go // through Xray's own SOCKS5 inbound the way the outbound direction does // (relay.go): Xray runs as a genuinely separate OS process // (internal/xray/process.go), so it has no visibility into this process's // private, in-memory netstack at all -- a tunnel-internal address like // 10.8.1.5:8080 has no route from Xray's own freedom outbound; only code // holding the actual *stack.Stack can reach it. ``` So TCP between two peers on the same inbound does not work either, for the same reason. Worth noting because this half needs no kernel work at all — it is a short-circuit inside the stack before the relay — and is much smaller than the ICMP half. ## On "kernel mode" as a panel option That path existed in this fork and was deliberately removed — `internal/amneziawg/instance.go:4-10`: ```go // longer manages any OS-level interface itself: that was the kernel-module // (DKMS) + awg-quick + TPROXY architecture this fork shipped originally, // retired in favor of an embedded, pure-Go one (amneziawg-go over a gVisor // netstack, see internal/amneziawgnet) in a hard cutover. ``` Reintroducing it as a toggle means reintroducing DKMS builds, Secure Boot signing and container-vs-bare-metal divergence, and it would bypass the SOCKS5 relay that currently supplies per-client stats, quota and routing (`relay.go:1-6`). That is a maintainer-level architectural call, not a small addition — flagging the cost rather than arguing against the request. ## One correction on your environment 3x-ui 3.4.0 has no `amneziawg` protocol. At `v3.4.0` the constants in `internal/database/model/model.go` end at `MTProto Protocol = "mtproto"`; `AmneziaWG Protocol = "amneziawg"` was added by commit `effcccce` ("feat(amneziawg): add native AmneziaWG protocol support (#6105)", 2026-08-24), whose first tag is **v3.7.0**. So what you tested is a `wireguard` inbound, possibly configured from an Amnezia client app. It does not change the conclusion — both are userspace and neither transits ICMP — but if you want to re-run your acceptance script against the embedded stack described above, you need v3.7.0 or newer. Two things I could not settle here, since I cannot run the panel: whether v3.7.0's promiscuous+spoofing NIC (`netstack.go:229-232`) causes gVisor to answer echo requests addressed to *arbitrary* destinations — if it does, `ping 1.1.1.1` would appear to pass while being a locally forged reply rather than real transit, which your acceptance test could not distinguish; and whether IPv6 behaves identically. Running your four-command script on v3.7.0 and reporting the raw output would settle both. Related: #3821 (the original report, closed as a question) and #6350, which answered the kernel-vs-userspace question for 3.7.0. Neither shares a defect with this, so this stays open on its own. No documentation page currently states the ICMP limitation — `grep -rn -i icmp docs/content/docs/en/` matches only `config/transports.mdx:128` (the `xicmp` UDP mask, unrelated) — so documenting it is arguably the smallest useful step here. Verdict: Feature request *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4320
No description provided.