September 24, 2023
Some people need a quick and free way to access a V2Ray or Xray server.
At the same time, other people are willing to provide free V2Ray or Xray servers, if they are in the public interest.
One thing that puts people off from providing free V2Ray or Xray servers is that you are effectively acting as an exit node. Whatever anyone does on your server can be blamed on you.
The architecture in this post addresses this problem. It makes it safer for anyone to offer free public-interest V2Ray or Xray servers.
+----------+ +--------+--------+ | *ray | | *ray | Tor | | Client +------->+ Server + Client +------> TOR | | | | | +----------+ +--------+--------+
The free server accepts V2Ray or Xray traffic, but forces it into the Tor network. The risk is shunted to the knowledgeable and well-resourced organizations who host Tor exit nodes.
Also, since Tor will be slower than a commercial VPN, your server will not be exploited by cheap people who want a VPN but want someone else to pay for it. Note also that Tor handles only TCP traffic.
The remainder of this post shows you how to set up the server and gives an example of installing a client.
Install the prerequisite package to access the Tor repositories:
apt install -y apt-transport-https
Create /etc/apt/sources.list.d/tor.list
like the example below (the distribution here is Ubuntu 22.04, which is why the distribution is jammy
):
deb [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org jammy main
deb-src [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org jammy main
Get the Tor signing key:
wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor | tee /usr/share/keyrings/tor-archive-keyring.gpg >/dev/null
Install Tor:
apt update && apt install -y tor deb.torproject.org-keyring
By default, Tor listens for SOCKS traffic on port 9050
:
systemctl status tor@default
ss -tulpn | grep 9050
Install the latest version of Xray to host your V2Ray or Xray server:
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install --beta -u root
(If you are using V2Ray instead of Xray, use https://github.com/v2fly/fhs-install-v2ray.)
Generate UUID:
xray uuid
Example:
22e22181-0fe1-4fb1-8fcf-f12c0c59e531
Generate public-private key pair:
xray x25519
Example:
Private key: QIqQz_iI2QNV_2CFnxJJurFwre6mxL5XEjA70LZqRGk
Public key: _J7qLmphZmLBayaKx0djjYt8KT0c_EfEmV2M4KAxniA
Generate short id:
openssl rand -hex 8
Example:
73459cc25fe18a97
Edit the Xray configuration file /usr/local/etc/xray/config.json
. Make it look like this.
{ "routing": { "domainStrategy": "IPIfNonMatch", "rules": [ { "type": "field", "ip": [ "geoip:private" ], "outboundTag": "block" } ] }, "inbounds": [ { "listen": "0.0.0.0", "port": 443, "protocol": "vless", "settings": { "clients": [ { "id": "22e22181-0fe1-4fb1-8fcf-f12c0c59e531", "flow": "" } ], "decryption": "none" }, "streamSettings": { "network": "h2", "security": "reality", "realitySettings": { "show": false, "dest": "www.cisco.com:443", "xver": 0, "serverNames": [ "www.cisco.com" ], "privateKey": "QIqQz_iI2QNV_2CFnxJJurFwre6mxL5XEjA70LZqRGk", "shortIds": [ "73459cc25fe18a97" ] } } } ], "outbounds": [ { "protocol": "socks", "tag": "tor", "settings": { "servers": [ { "address": "127.0.0.1", "port": 9050 } ] } }, { "protocol": "blackhole", "tag": "block" } ] }
Restart Xray with your configuration:
systemctl restart xray && systemctl status xray
Supply the server parameters to the public. You can also supply them as a URI-style vmess://
or vless://
link, or as a QR code. Most clients can import server parameters from a URI or on-screen QR code.
Clients are available for many platforms. Here are some examples:
We will give detailed installation instructions for v2rayN for Windows.
Open a browser and visit https://github.com/2dust/v2rayn, a GUI client supporting Xray, V2Ray, Shadowsocks, and other protocols.
Scroll down and click Releases in the sidebar.
The topmost release will be the most recent.
Scroll down to the Assets section, and expand the list of Assets.
Download v2rayN-With-Core.zip
.
The .zip
file is saved to your Downloads
folder.
Right-click on the .zip
file, and select Extract All....
The inner folder is extracted.
In the extracted folder, click v2rayN.exe
to launch the application.
Click the up-arrow at the bottom right of your Windows desktop to bring up the icons in the system tray.
Click the v2rayN icon to bring up the GUI panel.
If you want to change the interface language, click the three dots button in the menu.
You can choose between Simplified Chinese, Traditional Chinese, English, Farsi, and Russian.
Now right-click on the v2rayN icon in the system tray, and select the bottom-most option to exit v2rayN.
Go back to the extracted folder, and click v2rayN.exe
again to re-launch the application.
Again click the v2rayN icon to bring up the GUI panel.
Now the interface is in English.
Right-click on the v2rayN icon in the system tray, and you will see that the context menu is also in English.
From the Server menu, you can add servers manually, from a URL in the Windows clipboard, or from a QR code on the screen.
Make sure your QR code is on the screen, then you can import a server definition from the on-screen QR code.
Right-click on the v2rayN icon in the system tray, and you can optionally Set system proxy, which means you won't have to set individual browsers to use the proxy server.
Open a browser and visit some websites. If you wish, you can check your apparent IP address by visiting https://check.torproject.org.
When you have finished browsing, right-click on the v2rayN icon in the system tray, and select Exit.