SagerNet / SagerNet/sing-box

Feature Request: Allow specifying SOCKS5 UDP ASSOCIATE advertised IP

Open
#3,619 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Go
Stars
38.2k
Forks
4.6k
Avg merge
19d 15h
Merged PRs (30d)
1

Description

Summary

Request an option to explicitly configure the IP address returned in the SOCKS5 UDP ASSOCIATE response.

This is required for cloud environments where the server listens on a private NIC IP but exposes traffic through a public EIP/SNAT address.


Background

According to the SOCKS5 protocol, when a client issues a UDP ASSOCIATE command, the server replies with an IP:PORT indicating where the client should send UDP packets.

In many cloud environments (Alibaba Cloud ECS, AWS EC2, GCP, etc.):

  • The server listens on a private NIC IP (e.g. 172.x.x.x)
  • Outbound traffic is SNATed to a public EIP
  • The private NIC IP is not reachable from the client

When sing-box returns the private NIC IP in the UDP ASSOCIATE reply, the client sends UDP packets to an unreachable address, causing SOCKS5 UDP to fail completely.


Current Behavior

  • sing-box automatically selects the IP address used in the SOCKS5 UDP ASSOCIATE reply
  • Users cannot override this value
  • In SNAT / cloud NAT environments, SOCKS5 UDP is unusable

Expected Behavior

Provide a configuration option that allows users to explicitly specify the IP address advertised in the SOCKS5 UDP ASSOCIATE response.

Conceptual example:

{
  "type": "socks",
  "listen": "::",
  "listen_port": 1080,
  "udp_advertise_ip": "PUBLIC_EIP"
}
Scope of this option
  • Only affects the IP returned to the client in the UDP ASSOCIATE reply

  • Does not change:

    • Actual UDP source IP
    • Routing logic
    • NAT / SNAT behavior

This is purely a protocol-level advertisement setting.


Comparison

xray-core provides similar functionality via:

"settings": {
  "udp": true,
  "ip": "PUBLIC_EIP"
}

This setting has proven necessary and effective in cloud NAT environments.


Use Cases

  • Cloud servers with SNAT (Alibaba Cloud ECS, AWS EC2, GCP)
  • Docker / containerized deployments
  • Servers with private NIC + public EIP
  • Multi-IP hosts

Without this capability, SOCKS5 UDP cannot function correctly in these environments.


Notes

  • This request aligns with SOCKS5 protocol semantics
  • It improves usability without impacting existing behavior
  • Default behavior can remain unchanged if the option is not set

Thank you for considering this feature request.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the SOCKS5 UDP ASSOCIATE handling and the SOCKS inbound configuration entry point. Verify that a configured advertised IP changes only the IP in the UDP ASSOCIATE response, while existing UDP routing, source addressing, and default behavior remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.