Share v2ray Connection Over LAN: Setup Guide

Share Your v2ray Connection Over LAN: A Detailed Setup Guide

This guide details how to share your v2ray connection from one computer (the “server”) to other devices on your Local Area Network (LAN). This allows other devices, like phones, tablets, or other computers, to benefit from your vray configuration without needing their own separate v2ray clients. We will cover setup for both Windows and Linux (specifically Ubuntu/Debian-based distributions) as the server machine. We will not be setting up a full-fledged proxy server; instead, we’ll use the inherent capabilities of v2ray and system networking tools.

Prerequisites:

  • Working v2ray Client: You need a functioning v2ray client on the server machine. This guide assumes you have v2ray properly configured and connecting.
  • Administrator Access: You’ll need administrator privileges (or sudo access on Linux) on the server computer.
  • LAN Connection: All devices (server and clients) must be connected to the same local network (Wi-Fi or Ethernet).
  • IP Address Knowledge: You’ll need to know the local IP address of your server machine.
  • Firewall awareness: You may need to adjust your firewall to allow the necessary traffic, as explained in the steps below.

Core Concept:

The key is to configure the v2ray client on the server to listen on 0.0.0.0 (all interfaces) instead of the default 127.0.0.1 (localhost). This allows connections from other devices on the LAN. Then, you’ll configure client devices to use the server’s IP address and the v2ray proxy port as their proxy settings.

Step 1: Find Your Server’s Local IP Address

  • Windows:

    1. Open Command Prompt (search for cmd).
    2. Type ipconfig and press Enter.
    3. Look for the IPv4 Address under your active network adapter (e.g., Ethernet adapter, Wi-Fi adapter). It will likely be something like 192.168.1.x or 10.0.0.x. This is your server’s local IP.
  • Linux (Ubuntu/Debian):

    1. Open a terminal.
    2. Type ip addr or ifconfig and press Enter.
    3. Look for the inet address under your active network interface (e.g., eth0, wlan0). It will be similar to the Windows example. This is your server’s local IP.

Step 2: Modify Your v2ray Client Configuration (Server Side)

This step involves editing your v2ray configuration file (usually config.json). The exact location depends on how you installed v2ray, but it’s commonly in:

  • /etc/v2ray/config.json (Linux – if installed via script or package manager)
  • The v2ray installation directory (Windows or Linux – if manually installed).

You need to change the inbounds section of your configuration. Specifically, you are looking for the listen address. Here’s a breakdown of common inbound types and how to modify them:

  • SOCKS Inbound:

    json
    {
    "inbounds": [
    {
    "port": 10808, // Your chosen port - keep this number!
    "listen": "0.0.0.0", // Changed from 127.0.0.1
    "protocol": "socks",
    "settings": {
    "auth": "noauth", // Or your existing authentication settings
    "udp": true,
    "ip": "127.0.0.1" //This can remain as 127.0.0.1
    },
    "tag": "socks-in"
    }
    ],
    // ... rest of your config ...
    }

    Key Change: listen: "127.0.0.1" -> "0.0.0.0"

  • HTTP Inbound:

    json
    {
    "inbounds": [
    {
    "port": 10809, // Your chosen port - keep this number!
    "listen": "0.0.0.0", // Changed from 127.0.0.1
    "protocol": "http",
    "settings": {},
    "tag": "http-in"
    }
    ],
    // ... rest of your config ...
    }

    Key Change: listen: "127.0.0.1" -> "0.0.0.0"

  • Mixed Inbounds (SOCKS and HTTP): If you have both SOCKS and HTTP inbounds, modify both to listen on 0.0.0.0.

Important Notes on Configuration:

  • port: Note the port number(s) used in your inbounds configuration. You’ll need this for the client devices. The examples use 10808 for SOCKS and 10809 for HTTP, but yours might be different.
  • auth: If your inbounds configuration uses authentication (e.g., “userpass”), you’ll need to provide the username and password on the client devices. For simplicity in a trusted LAN environment, you might consider temporarily using noauth, but be aware of the security implications (anyone on your LAN could use the proxy).
  • "ip": "127.0.0.1" inside the settings of SOCKS: The ip field inside the settings object should generally remain as 127.0.0.1. This refers to the address v2ray uses internally for UDP relay, and it’s usually best left at the loopback address.

Step 3: Restart v2ray (Server Side)

After modifying the configuration file, you must restart the v2ray service for the changes to take effect.

  • Windows: If you’re using a GUI client, there’s usually a “Restart” or “Reload” button. Otherwise, you might need to restart the v2ray service through the Services manager (services.msc).
  • Linux:
    • sudo systemctl restart v2ray (if using systemd)
    • sudo service v2ray restart (if using older init systems)
    • If v2ray was run manually, terminate the process and start it again.

Step 4: Configure Firewall (Server Side – IMPORTANT!)

You need to allow incoming connections on the v2ray port(s) you configured.

  • Windows Firewall:

    1. Open “Windows Defender Firewall with Advanced Security”.
    2. Click “Inbound Rules” -> “New Rule…”.
    3. Choose “Port” and click “Next”.
    4. Select “TCP” (or UDP if you configured UDP relay and want to share it).
    5. Enter your v2ray port number(s) (e.g., 10808, 10809) in “Specific local ports”.
    6. Click “Next”.
    7. Choose “Allow the connection”.
    8. Click “Next”.
    9. Select the network profiles (usually “Private” is sufficient for a home LAN).
    10. Click “Next”.
    11. Give the rule a name (e.g., “v2ray LAN Access”) and click “Finish”.
  • Linux (Ubuntu/Debian – using ufw):

    1. Open a terminal.
    2. sudo ufw allow <port_number>/tcp (e.g., sudo ufw allow 10808/tcp). Repeat for each port.
    3. sudo ufw allow <port_number>/udp (if you’re using UDP and want to share it).
    4. sudo ufw reload (to apply the changes).
      If you are using iptables directly (less common for simple setups), you’ll need to craft the appropriate iptables rules. This is beyond the scope of this basic guide.

Step 5: Configure Client Devices

Now, configure your other devices to use the server’s IP address and v2ray port as their proxy. The exact steps vary depending on the operating system and application.

  • System-Wide Proxy (Windows):

    1. Go to Settings -> Network & Internet -> Proxy.
    2. Under “Manual proxy setup”, turn on “Use a proxy server”.
    3. Enter your server’s local IP address in the “Address” field.
    4. Enter your v2ray SOCKS port (e.g., 10808) or HTTP port (e.g., 10809) in the “Port” field.
    5. You can optionally enter exceptions (addresses that shouldn’t use the proxy) in the “Exceptions” field.
    6. Click “Save”.
  • System-Wide Proxy (macOS):

    1. Go to System Preferences -> Network.
    2. Select your active network connection (Wi-Fi or Ethernet).
    3. Click “Advanced…”.
    4. Go to the “Proxies” tab.
    5. Select either “SOCKS Proxy” or “Web Proxy (HTTP)” depending on which inbound you’re using.
    6. Enter your server’s local IP address and v2ray port in the appropriate fields.
    7. Click “OK” and then “Apply”.
  • System-Wide Proxy (Android):

    1. Go to Wi-Fi settings. Long press the connected Wi-Fi network.
    2. Tap ‘Modify network’ or ‘Advanced options’.
    3. Tap ‘Proxy’ and select ‘Manual’.
    4. Enter the server’s IP in ‘Proxy hostname’.
    5. Enter the v2ray SOCKS or HTTP port in ‘Proxy port’.
    6. Save the changes.
  • System-Wide Proxy (iOS):

    1. Go to Wi-Fi settings. Tap the ‘i’ icon next to the connected Wi-Fi network.
    2. Scroll down to ‘HTTP Proxy’ and select ‘Manual’.
    3. Enter the server’s IP in ‘Server’.
    4. Enter the v2ray SOCKS or HTTP port in ‘Port’.
    5. Save the changes.
  • Application-Specific Proxy: Some applications (e.g., browsers, Telegram) have their own proxy settings. Configure these within the application using the server’s IP address and v2ray port. For example, in Firefox: Options -> General -> Network Settings -> Settings…

Troubleshooting:

  • Can’t Connect:

    • Double-check your server’s local IP address.
    • Verify that v2ray is running on the server.
    • Ensure the firewall on the server is allowing connections on the correct port(s).
    • Check the client device’s proxy settings (IP address and port).
    • Temporarily disable any other firewalls or security software on both the server and client to rule them out.
    • Check the v2ray logs on the server for any error messages.
  • Slow Connection: Sharing a connection can introduce some overhead. Make sure your server machine has sufficient resources (CPU, memory) and a good internet connection.

  • UDP Not Working: If you’re using UDP relay and it’s not working, ensure:

    • You’ve configured UDP relay correctly in your v2ray configuration.
    • You’ve allowed UDP traffic on the server’s firewall.
    • The client application supports UDP proxying.

This comprehensive guide provides a solid foundation for sharing your v2ray connection over your LAN. Remember to prioritize security, especially if your network isn’t fully trusted. Always be mindful of the potential risks of opening ports and adjust your firewall and authentication settings accordingly. Good luck!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top