V2Ray JSON Config Explained: Inbounds, Outbounds, and Routing

Learn how a V2Ray JSON config is structured, from log, inbounds, and outbounds to routing and DNS, with clear explanations of key fields and common patterns.

At a glance

For readers who can use a client but are checking the core's JSON config for the first time. Using a V2Fly V4-style config, this guide covers two proxy inbounds that listen only on the local machine and two outbounds. Follow tags to trace a request and distinguish startup failures from routing mistakes and DNS issues.

Top-level structure: objects vs. arrays

The core config's outermost level is a JSON object. inbounds and outbounds are arrays because a process can have multiple inbounds and outbounds. log, routing, and dns are objects, while routing.rules is an array. The order of top-level fields in the file does not determine where traffic goes first, but the order of rules and outbounds can affect the result.

App requestLocal inboundRouting ruleSelected outbound

Inbounds and outbounds: protocols define their roles

For an inbound, listen and port specify where the core accepts local requests, while protocol determines the proxy type the app should use to connect. For an outbound, protocol determines how requests are handled. The protocols on each side don't have to match. The ports below are examples, not fixed software defaults or remote server ports.

10808
Example SOCKS inbound port
10809
Example HTTP inbound port

Local SOCKS inbound

listen
127.0.0.1
port
10808
protocol
socks
tag
local-socks

Select SOCKS5 in the app; this listen address and port are not an HTTP proxy endpoint.

Direct outbound

protocol
freedom
tag
direct
settings.domainStrategy
AsIs

The core connects directly to the destination; this does not mean the app bypasses the local inbound.

Troubleshooting: check the proxy type, then the port

A local port accepting a TCP connection only means a program is listening. If the app sends HTTP proxy requests to a SOCKS inbound, correct the proxy type and port in the app first—don't change the outbound rules.

Routing: follow tags to find the outbound

This example uses blackhole for requests to the reserved test domain example.test and freedom for requests that don't match. There is no remote proxy node, and the test domain doesn't need a working DNS record: the exact-domain rule can match as long as the inbound request contains that domain. To test a direct connection, use a destination you can reach.

{
  "log": { "loglevel": "warning" },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 10808,
      "protocol": "socks",
      "tag": "local-socks",
      "settings": { "auth": "noauth", "udp": false }
    },
    {
      "listen": "127.0.0.1",
      "port": 10809,
      "protocol": "http",
      "tag": "local-http",
      "settings": {}
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "tag": "direct",
      "settings": { "domainStrategy": "AsIs" }
    },
    {
      "protocol": "blackhole",
      "tag": "blocked",
      "settings": {}
    }
  ],
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "domain": ["full:example.test"],
        "outboundTag": "blocked"
      }
    ]
  }
}

DNS: separate routing lookups from outbound lookups

dns configures the resolver the core can use; it does not change the system DNS for the entire computer. routing.domainStrategy determines whether routing looks up an IP address to match a domain, while freedom's settings.domainStrategy determines how that outbound handles domains. The fields have the same name but belong to different levels; changing one does not change the other.

FieldExample settingWhat it does
dns.servers["localhost"]Sets the resolver source for the built-in DNS; this example uses the local system resolver.
routing.domainStrategyIPIfNonMatchIf no domain rule matches, try resolving the destination domain and match by IP.
freedom's settings.domainStrategyAsIsThe direct outbound does not proactively use built-in DNS to resolve domains to IP addresses; the system may still resolve the domain when connecting.

The complete example above uses AsIs for routing, which is enough to match the original domain received by the core. If the app resolves the domain before connecting to the SOCKS inbound and sends only the destination IP, the domain rule has no domain to match. To test this rule, configure the app to pass the domain to the proxy; adding dns.servers alone won't restore the original domain from an IP address.

Logs: troubleshoot by failure stage

With log.loglevel set to warning, routine logs focus on warnings and errors. To troubleshoot a single request, temporarily switch to info, or debug if needed, then restore the original value after recording what changed. Compare the logs against the request time, and remove unnecessary destination addresses, account identifiers, and subscription details before sharing them.

  1. The core won't start: First check whether the JSON can be parsed. This example uses standard JSON: put keys and strings in double quotes, with no comments or trailing commas. Once the syntax is valid, check field nesting, protocol names, and whether the current core supports that configuration.
  2. The core starts, but the app can't connect: Confirm that the core loaded the config you just edited, and check whether the current process is listening on 127.0.0.1:10808 and 127.0.0.1:10809. If another program is using a port, switch to an available one and update the app's proxy settings to match.
  3. The request reaches the core, but the result is wrong: First check whether the core received a domain or an IP address. Then find the first matching rule in order and confirm that outboundTag points to the expected outbound. If direct was selected but the connection still fails, check DNS resolution and destination reachability; not every timeout is a routing issue.

When reviewing the config, change one field at a time and repeat the same request. This makes it easier to tell whether the app has started using the correct port or was connecting all along but selecting the wrong outbound.

Client Downloads