Shadowrocket WireGuard Setup: PrivateKey, PublicKey, and AllowedIPs Explained

Learn what each WireGuard field in Shadowrocket does, including keys, Address, DNS, MTU, AllowedIPs, and Endpoint, plus common setup mistakes.

At a glance

This guide is for users who already have a WireGuard configuration from their service provider and need to check its settings in Shadowrocket. First distinguish the local identity from the remote identity, then check the tunnel address, destination networks, and UDP endpoint. Finally, use Global Routing to separate connection issues from rule selection issues. Example addresses are for explaining fields only and cannot be used to connect.

1. Understand [Interface] and [Peer]

A WireGuard configuration usually has two sections: [Interface] and [Peer]. The first describes the local tunnel interface; the second describes the remote peer. When entering the configuration in Shadowrocket, match fields by what they mean rather than by their order in the source file. The steps below use iPhone / iPad as an example; field layouts may differ on other platforms.

PrivateKey belongs to the local device; PublicKey under [Peer] belongs to the remote peer. The server must also register the public key for this device and assign it the correct address. Filling in the client-side fields alone does not mean the server has completed the pairing.

32 bytes
Length of the raw WireGuard private key or public key
UDP
Protocol used for WireGuard's outer transport
51820
Example port used in this guide; use the port in your existing configuration

WireGuard private keys, public keys, and optional preshared keys are typically represented as Base64 text. The standard encoding is 44 characters and often ends in =. Matching lengths do not mean the keys serve the same purpose, nor do they prove that a key is valid. Do not treat these fields as passwords, subscription URLs, or certificate contents.

2. How PrivateKey, PublicKey, and PresharedKey correspond

Local identity

PrivateKey
The local private key. Keep it in the local configuration and never send it to anyone troubleshooting the issue.
Local PublicKey
Derived from the local PrivateKey and used by the server to register this device's identity.
Address
The tunnel address assigned to this device by the server, not the server's public address.

If you change the local PrivateKey, update the corresponding public key registered on the server as well.

Remote identity

[Peer] PublicKey
The remote public key, used to identify the peer this device connects to.
PresharedKey
An optional additional shared key; if enabled, it must match at both ends.
Endpoint
The address and UDP port reachable at the remote end.

If your existing configuration has no PresharedKey, do not generate one and add it yourself.

A common mistake is entering the local public key as the remote PublicKey, or using the remote public key as the local PrivateKey. Either error may pass text-format checks but will prevent a valid encrypted session from being established. When checking a key, confirm both which side it belongs to and whether it is public or private.

Do not share your full WireGuard configuration. PrivateKey and PresharedKey are sensitive. When reporting an issue, include field names, error messages, and network symptoms, but remove key contents. If your private key has been exposed, replace it and have the server update the corresponding public key.

3. What Address, DNS, and MTU affect

Address is the local address inside the tunnel, usually with a CIDR prefix, such as 10.66.0.2/32. It is not your current Wi-Fi LAN address or the Endpoint. Do not change it to a new LAN address when switching Wi-Fi networks.

FieldExample or unitWhat to check
Address10.66.0.2/32Use the assigned address; do not widen the prefix length yourself.
DNSDNS server IP addressConfirm that the resolver is reachable and check the DNS settings currently used by Shadowrocket.
MTUBytes, for example 1420Limits the size of inner IP packets in the tunnel; it is not connection speed.

Neither DNS nor Address is an identity field in the WireGuard handshake itself. In common configuration files, these entries are handled by the client or configuration tool. When mapping file contents to Shadowrocket, do not assume every entry automatically overrides the app's global settings. Also check the resolver settings actually in use under Settings → DNS.

If MTU is set too high, small requests may succeed while larger transfers stall, though other network issues can cause the same symptoms. WireGuard encapsulation typically adds 60 bytes over IPv4 and 80 bytes over IPv6. With an underlying MTU of 1500, 1420 is a common starting point that accommodates an IPv6 outer packet, but it is not suitable for every link.

4. AllowedIPs is not Global Routing

In WireGuard, AllowedIPs maps peers to IP prefixes: outgoing traffic uses it to select the peer for a destination address, while incoming traffic uses it to validate the source address of decrypted packets. Traditional tunnel tools may also use it to install system routes. As a rule-based proxy client, Shadowrocket has a separate traffic selection layer.

So AllowedIPs = 0.0.0.0/0, ::/0 means the peer covers the IPv4 and IPv6 address ranges. It does not mean Shadowrocket has selected every device request to send through that peer. Also check the connection toggle, the currently selected connection, Global Routing, and the policy used by your configuration rules.

# Field explanation only; not a complete connection configuration that can be imported as-is.
# The addresses below are documentation examples and do not provide connection service.
[Interface]
Address = 10.66.0.2/32
MTU = 1420

[Peer]
Endpoint = 192.0.2.10:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

The example intentionally leaves out the keys. 0.0.0.0/0 covers IPv4 only; ::/0 covers IPv6. If you specify only 10.66.0.0/24, that peer covers only that subnet; it should not be expected to carry arbitrary public internet traffic. Configure IPv6 only if the server supports it and it is included in your existing allocation.

These rules belong in the [Rule] section; do not paste them into AllowedIPs. Rules are matched in order. If an earlier DIRECT rule matches, a later proxy policy will not handle that request.

5. What to enter for Endpoint and PersistentKeepalive

Endpoint is the remote address your device first needs to reach over its current network. It can be an IP address or hostname, followed by a port. In a standard configuration, it looks like 192.0.2.10:51820. If the editor has separate address and port fields, enter them separately instead of pasting the full value into both fields.

  1. Do not add https:// to the address field, append a webpage path, or paste subscription query parameters.
  2. In a standard configuration, put IPv6 endpoints in square brackets, for example [2001:db8::10]:51820, so the colons in the address are not mistaken for the port separator.
  3. Confirm that the remote end is listening on the configured UDP port. A successful TCP port check does not prove that the UDP port with the same number is reachable.
  4. For a hostname, first confirm it can be resolved before the connection is established. Avoid relying on DNS inside a tunnel that is not up yet.

PersistentKeepalive is measured in seconds and sends keepalive packets as needed to maintain NAT or firewall state. 25 is a common setting, not a requirement. If unset or set to 0, periodic keepalives are generally disabled. It is not a connection timeout and cannot fix an incorrect public key or a port the server has not allowed.

If the connection drops only after switching between Wi-Fi and cellular, note when the switch occurred, whether the connection can be re-established, and whether UDP is reachable before deciding whether keepalives are needed. Do not try to fix identity or endpoint problems by continually shortening the keepalive interval.

6. Add the configuration in Shadowrocket and verify it step by step

These steps assume you already have a valid configuration. This site does not provide, sell, or recommend nodes or subscriptions. If the settings came from your own subscription, check the original details from your service provider first. Subscription updates may overwrite connection fields, so record the current values before troubleshooting to avoid losing manual changes on the next update.

  1. Select the protocol

    Go to Home → “+” → Type → WireGuard. To edit an existing connection, open it from Home and check its Type first. Do not enter passwords or identifiers for other protocols in WireGuard key fields.

  2. Check the identities

    Enter the local PrivateKey, the remote PublicKey, and the PresharedKey only if required by the configuration. Also confirm that the server has registered the local public key.

  3. Check the addresses

    Check Address, Endpoint, and the port. If the editor does not have a separate field for an item in the original configuration, first confirm where that item belongs in the current client. Do not put it in a different field just because the field name seems similar.

  4. Test temporarily

    Save and select the connection. Under Home → Global Routing → Proxy, test the same known-reachable destination and check the connection status and logs. Do not treat a latency result in the list as a complete service test.

  5. Restore your rules

    After testing, go to Home → Global Routing → Config and confirm which configuration is enabled and which policy matches the destination. If automatic reconnection is interfering with the test, also check Settings → On Demand.

On Demand controls automatic connections when its conditions are met; it does not replace AllowedIPs or [Rule]. If you turn it off while troubleshooting, note its original settings and restore them after testing. This helps avoid mistaking automatic reconnection for a manual connection toggle that is not working.

Config

Recommended

Handles traffic according to the active configuration rules. A rule may select DIRECT or a policy that uses WireGuard. Not every unmatched request automatically goes through the proxy; the final behavior depends on FINAL.

Best for: everyday rule-based routing after verifying the protocol.

Proxy

Handles traffic in a proxy mode, which can reduce the effect of rule-based routing on your test. The selected policy must still point to the connection under test, and this does not bypass system traffic scope, remote permissions, or WireGuard settings.

Best for: temporarily checking whether a problem is related to rule selection.

Direct

Handles traffic in a direct mode and can serve as a baseline for your local network. If the destination is reachable this way, that does not prove the WireGuard configuration is correct; the test may not have used that connection.

Best for: checking whether a destination is reachable directly on your current local network.

7. Narrow down the issue based on symptoms

Do not assume WireGuard has completed a handshake just because the connection toggle is on. The toggle shows the client connection state, but you still need to verify remote identity matching, UDP traffic in both directions, and data transfer to the specific destination. The steps below are a troubleshooting sequence, not a diagnosis based on any single symptom.

Observed symptomCheck firstNext step
No working communicationPublic key registration at both ends, PresharedKey, Endpoint, and UDP portAsk your service provider to check the server listener and peer registration.
IP address works, but domain name failsDNS reachability and the actual resolution pathCompare the resolution result for the same destination; avoid comparing different services.
Small requests work, but large transfers stallPath MTU, packet loss, and remote-side limitsKeep the other settings unchanged, adjust only MTU, and repeat the same test.
Proxy works, but Config does notActive configuration, matching rules, and policy selectionCheck whether DIRECT or another policy matches the destination first.
Settings changed after a subscription updateField values before and after the update, and server-side assignmentsCheck what the subscription source returns; do not keep overwriting settings your service provider has changed.

When contacting your service provider, include your operating system, network type, the conditions that trigger the issue, the field names you checked, and redacted error logs. Do not send your PrivateKey or PresharedKey. If the server has changed a public key, port, or address assignment, update the corresponding fields and retest starting with the protocol.

Download Shadowrocket