Skip to content

Random port nodes

Instead of a fixed port, a node can hand out a different random port on every subscription refresh. This makes it harder to block the node by a single port, and users never need to re-import their subscription when the port "changes" — it was always drawn from the same range.

This is a different mechanism from the Backend Port range / weekly port reset feature — that one rotates which port the backend software itself listens on over time. This feature rotates which port is handed to the user on each subscription pull, while the backend keeps listening the same way throughout.

How it works

The node's Single Entry Port field (client_port) accepts a single port, a range (20000-40000), or a comma-separated list (20000,20002,20004). Every time a subscription is generated, one port is picked at random from whatever you put there — the backend itself still only listens on one real port (Backend Port / backend_port).

For a directly-connected node, that means traffic arriving on any port in the range has to actually reach the one real backend port — which is done with a forwarding script on the node.

Quick setup

This matches the built-in Shadowsocks-RANDOM-PORT node template (available from Create Node → From Template):

  1. On the node, set:

    • Backend Port: a single fixed port, e.g. 12345
    • Backend Port range: a range containing just that port, e.g. 12345-12345
    • Single Entry Port: the range you want users randomized across, e.g. 20000-40000
  2. On the node's VPS, forward the whole range down to the real backend port:

    bash
    wget -N --no-check-certificate https://v2raysocks.com/assets/files/ipt.sh && chmod +x ipt.sh && bash ipt.sh

If the node is behind a relay instead of direct-connect, run iptables-pf.sh on the relay machine instead — see XrayR as backend → Port Forwarding for both scripts.

Per-IP device limiting doesn't work correctly on a relayed random-port node, since every connection appears to come from the relay's IP.

Rotating across multiple relays too

To randomize across several relay servers (not just ports on one server), use Multiple Entry Lists with the Multiple Entry Mode set to "Randomly deliver one entry each time". Each line is address:port:remark, and the port part accepts the same single/range/list format as Single Entry Port:

1.2.3.4:20000-40000:Relay 1
5.6.7.8:20000-40000:Relay 2

On each subscription pull, one line is picked at random, then a random port from that line's port set is picked — so both the relay and the port can change between refreshes.