How to Configure Custom Inbound Protocols in v2rayN (SOCKS, HTTP, TUN)

You configure SOCKS, HTTP, and TUN inbounds through the Config.Inbound collection and TunModeItem settings, which the V2rayInboundService and SingboxInboundService translate into core-specific JSON during runtime.

v2rayN is a Windows GUI client for V2Ray and Xray cores that stores listener configurations in the guiN.config file. Understanding how to configure custom inbound protocols lets you customize local proxy ports, enable UDP forwarding, and activate system-wide TUN mode routing.

Understanding the Inbound Architecture

The inbound configuration pipeline in v2rayN follows a strict Model-View-ViewModel (MVVM) pattern before reaching the core.

The Model Layer: InItem and TunModeItem

All inbound settings persist in ConfigItems.cs. The InItem class defines the primary SOCKS/HTTP listener properties:

public class InItem
{
    public int LocalPort { get; set; } = 10808;
    public string Protocol { get; set; } = "mixed";
    public bool UdpEnabled { get; set; } = true;
    public bool SniffingEnabled { get; set; } = true;
    public List<string> DestOverride { get; set; } = new() { "http", "tls" };
    public bool AllowLANConn { get; set; }
    public bool SecondLocalPortEnabled { get; set; }
    // ... additional properties
}

For TUN mode, the TunModeItem class holds system-level routing parameters including EnableTun, AutoRoute, StrictRoute, Stack, Mtu, and EnableIPv6Address.

Protocol Enumeration

The EInboundProtocol enum in EInboundProtocol.cs defines available protocol identifiers:

public enum EInboundProtocol
{
    socks = 0,
    socks2 = 1,
    socks3 = 2,
    pac = 3,
    api = 4,
    api2 = 5,
    mixed = 6,
    speedtest = 7
}

UI and ViewModel Binding

The OptionSettingViewModel.cs bridges user input to the model. Its SaveCmd method writes changes back to _config.Inbound.First(), while the corresponding OptionSettingWindow.axaml provides text boxes for port configuration and toggles for UDP, sniffing, and LAN access.

Core Config Builders

When v2rayN starts a connection, two services generate the actual core configuration:

  • V2rayInboundService.cs – The BuildInbound() method converts InItem objects into V2Ray JSON, always using the mixed protocol to handle both SOCKS and HTTP traffic simultaneously.
  • SingboxInboundService.cs – Performs the same conversion for the Sing-Box core and additionally injects TUN inbounds when EnableTun is true.

Configuring SOCKS and HTTP Inbounds

v2rayN exposes a single inbound UI because the underlying mixed protocol supports both SOCKS5 and HTTP proxies on the same port.

Via the Settings Interface

  1. Navigate to Settings → Inbound Settings.
  2. Set the Local Listening Port (default 10808).
  3. Enable UDP (UdpEnabled) for UDP proxying support.
  4. Keep Sniffing enabled to allow automatic protocol detection via the DestOverride rules.

When saved, OptionSettingViewModel updates _config.Inbound[0], and V2rayInboundService.GenInbounds() produces the following V2Ray JSON:

{
  "tag": "socks",
  "port": 10808,
  "protocol": "mixed",
  "settings": {
    "udp": true
  },
  "sniffing": {
    "enabled": true,
    "destOverride": ["http", "tls"]
  }
}

Creating an HTTP-Only Inbound

Since the UI defaults to mixed, creating a dedicated HTTP-only listener requires manual configuration. After exporting the full configuration (Export → Full Config), modify the inbounds array in the generated JSON:

{
  "tag": "http-only",
  "port": 8080,
  "protocol": "http",
  "settings": {}
}

The core-config builders prepend their auto-generated mixed inbound, so custom entries are preserved in the final configuration.

Enabling TUN Mode

TUN mode creates a virtual network interface for system-wide traffic capture, available only when using the Sing-Box core.

Configuration Steps

  1. Open Settings → Tun Mode Settings.
  2. Check Enable TUN (bound to TunModeItem.EnableTun in StatusBarViewModel.cs).
  3. Configure:
    • Auto Route: Automatically configure system routing table
    • Strict Route: Enforce strict routing rules
    • Stack: Choose system, gvisor, or mixed
    • MTU: Default 1500 bytes
    • IPv6: Enable IPv6 address assignment

When activated, SingboxInboundService injects an inbound based on the embedded template Global.TunSingboxInboundFileName:

{
  "type": "tun",
  "tag": "tun",
  "listen_port": 10808,
  "auto_route": true,
  "strict_route": false,
  "stack": "system",
  "mtu": 1500,
  "inet6_address": "fddd::1/64"
}

This inbound is appended after the SOCKS listener, allowing routing rules to reference "inbound": "tun" for traffic segregation.

Advanced: Multiple Local Ports and Manual Configuration

Secondary SOCKS Port

Enable SecondLocalPortEnabled in the inbound settings to generate an additional listener. The port calculates automatically as LocalPort + (int)EInboundProtocol.socks2 (typically 10809 when the primary is 10808). This secondary port uses identical protocol settings but allows separate routing rule targeting via the socks2 tag.

Direct Configuration File Editing

Advanced users can edit guiN.config directly in the application data folder:

{
  "Inbound": [
    {
      "LocalPort": 10808,
      "Protocol": "mixed",
      "UdpEnabled": true,
      "SniffingEnabled": true,
      "DestOverride": ["http", "tls"],
      "AllowLANConn": false,
      "SecondLocalPortEnabled": true
    }
  ],
  "TunModeItem": {
    "EnableTun": true,
    "AutoRoute": true,
    "Stack": "gvisor",
    "Mtu": 1400
  }
}

Restart v2rayN after manual edits to trigger a configuration rebuild.

Programmatic Configuration Examples

Adding a Custom HTTP Inbound via C#

using ServiceLib.Models;
using ServiceLib.Enums;

var config = AppManager.Instance.Config;

var httpInbound = new InItem
{
    LocalPort = 8080,
    Protocol = EInboundProtocol.mixed.ToString(),
    UdpEnabled = false,
    SniffingEnabled = true,
    DestOverride = new List<string> { "http", "tls" },
    AllowLANConn = true
};

config.Inbound.Add(httpInbound);
AppManager.Instance.SaveConfig();

Enabling TUN Mode Programmatically

var cfg = AppManager.Instance.Config;

cfg.TunModeItem.EnableTun = true;
cfg.TunModeItem.AutoRoute = true;
cfg.TunModeItem.Stack = "gvisor";
cfg.TunModeItem.Mtu = 1400;
cfg.TunModeItem.EnableIPv6Address = true;

AppManager.Instance.SaveConfig();

Summary

  • Inbound storage: All SOCKS/HTTP settings persist in the Config.Inbound collection as InItem objects defined in ConfigItems.cs.
  • Protocol handling: The mixed protocol in EInboundProtocol enables simultaneous SOCKS5 and HTTP support on a single port.
  • TUN configuration: TUN mode settings reside in TunModeItem and are processed by SingboxInboundService.cs to generate virtual interface configurations.
  • Persistence: Changes save to guiN.config and reload on application restart.
  • Extensibility: Manual JSON edits and programmatic InItem creation allow custom inbound definitions beyond the standard UI options.

Frequently Asked Questions

Can I separate HTTP and SOCKS into different ports?

Yes, but not through the standard UI. You must manually edit the generated core configuration JSON to add a separate inbound with "protocol": "http" on your desired port, or programmatically add a second InItem with a distinct LocalPort. The V2rayInboundService preserves custom inbounds when rebuilding configurations.

Why does v2rayN use the "mixed" protocol instead of "socks"?

According to the source in V2rayInboundService.cs, the mixed protocol is the only V2Ray inbound type that handles both SOCKS5 and HTTP traffic simultaneously on a single port. This reduces configuration complexity while maintaining compatibility with applications that expect either protocol type.

How do I enable IPv6 support in TUN mode?

Set EnableIPv6Address to true in TunModeItem (accessible via Settings → Tun Mode Settings or programmatically). When SingboxInboundService builds the configuration, it includes IPv6 interface addresses in the generated TUN inbound JSON, allowing IPv6 traffic to traverse the virtual interface.

Where does v2rayN store inbound configuration changes?

All changes persist in guiN.config located in the application data directory. The OptionSettingViewModel.SaveCmd method serializes the Config object (including the Inbound collection and TunModeItem) to this file, which is then deserialized during application startup to restore settings.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →