Best Method to Setup V2Ray Server on Linux Ubuntu 20.04

How to Setup V2Ray Server on Linux (Ubuntu 20.04)

V2Ray is a powerful tool to increase privacy over the Internet. Ubuntu 20.04 is the most suitable Linux distribution for installing V2Ray.

It is possible to Install V2Ray on Linux, Windows, Mac, Android, and iOS. You are recommended to install V2Ray manually.

SSH into your remote Ubuntu server and follow the below steps to install and configure V2Ray Proxy on Ubuntu 20.04:

  1. Install V2Ray on Ubuntu.
  2. Set up NTP time Synchronization.
  3. Configure V2Ray for Ubuntu.
  4. Configure Reverse Proxy.
  5. Enable HTTPS.
  6. Configure Firewall.
  7. Configure V2Ray Client on Linux.

Prerequisites to Setup V2Ray Server on Linux Ubuntu

To Install and Config V2Ray server on Ubuntu, your machine needs to meet all the below specifications:

  • A Server running Ubuntu VPS.
  • A non-root user with sudo privileges.

Steps to Set up V2Ray on Ubuntu 20.04

Update your system using the below commands and follow the below-required steps to set up V2Ray on Ubuntu:

sudo apt-get update

sudo apt-get upgrade

Step 1: Download V2Ray and Install it on Ubuntu

Run the command below to install dependency packages:

sudo apt install curl unzip

To download the official V2Ray install script, and run it, type:

curl -O
sudo bash

The V2Ray installation script is now available. When you are finished download V2Ray for Ubuntu, you can check the final status:

sudo systemctl status v2ray

If something is not working, you need to restart it:

sudo systemctl restart v2ray

Then, if you prefer an auto-start at your system boot time, you must enable it:

sudo systemctl enable v2ray

Step 2: Accurate the Server Time

Time constraints are very strict for V2ray. If you do not set up NTP time sync, the V2Ray might fail. It helps to enhance users’ security.

You must ensure that the time is accurate enough because the absolute value of the time difference between the client and the server cannot exceed two minutes.

First, run the command below to check the current time of your server:


Your server system clock must be synchronized. Otherwise, set up NTP time synchronization and then continue the steps below.

Step 3: Configure V2Ray on Ubuntu 20.04

Use your preferred text editor to edit the V2Ray configuration file. Here, we use Nano.

sudo nano /usr/local/etc/v2ray/config.json

V2Ray (VMesss) only uses UUID. Add the following lines after deleting everything in this file. Substitute a random string in UUID format for the ID.

  "log": {
    "loglevel": "warning",
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log"
  "inbounds": [
      "port": 10000,
      "protocol": "vmess",
      "settings": {
        "clients": [
            "id": "<span style="color: #008000;">b831381d-6324-4d53-ad4f-8cda48b30811</span>",
            "alterId": 64
      "streamSettings": {
        "network": "ws",
        "wsSettings": {
        "path": "/ray"
  "outbounds": [
      "protocol": "freedom",
      "settings": {}

When you are done, save and close the file. The V2Ray server will listen on the Port 10000.

For the modifications to take effect, restart V2Ray:

sudo systemctl restart v2ray

To check the listening port, run:

sudo ss -lnpt | grep v2ray

Step 4: Configure Reverse Proxy

Your Web server uses a reverse proxy. At this step, you can set up Nginx as Reverse Proxy on Ubuntu.

To do this, install the Nginx web server and create a virtual host file for V2Ray:

sudo apt install nginx

sudo nano /etc/nginx/conf.d/v2ray.conf

Add the following lines to this file.

Note: Keep in mind to replace with your domain name. You can also use a subdomain.

server {
  listen 80;
  server_name    <span style="color: #008000;"></span>;

  index index.html;
  root /usr/share/nginx/html/;

  access_log /var/log/nginx/v2ray.access;
  error_log /var/log/nginx/v2ray.error;

    location /ray { # Consistent with the path of V2Ray configuration
      if ($http_upgrade != "websocket") { # Return 404 error when WebSocket upgrading negotiate failed
          return 404;
      proxy_redirect off;
      proxy_pass; # Assume WebSocket is listening at localhost on port of 10000
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $host;
      # Show real IP in v2ray access.log
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

When you are finished, save and close the file.

Use the command below to test the recent Nginx configuration you have done:

sudo nginx -t

If you view no error, reload Nginx by running the following command:

sudo systemctl reload nginx

Step 5: Enable HTTPS

To ensure that your national firewall remains unaware that you are using a proxy, activate HTTPS.

To do this, install the latest version of the Let’s Encrypt client certbot from the Snap store:

sudo apt install snapd
sudo snap install certbot --classic

To get a free Let’s Encrypt certificate, run:

sudo /snap/bin/certbot --webroot -i nginx --agree-tos --hsts --staple-ocsp -d -e -w /usr/share/nginx/html/

Your Nginx web server will automatically install it after it has been received.

Step 6: Configure Firewall

  • If using iptables firewall:

Allow traffic to the TCP port 443:

sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT
  • If using UFW firewall:

Run the command below to configure the firewall on your Ubuntu system:

sudo ufw allow 443/tcp

Step 7: Configure V2Ray Client on Linux

It is time for the V2Ray Ubuntu client install. To download the latest V2Ray for 64-bit Linux, get the file and unzip it.

In your considered text editor or terminal, edit the V2Ray configuration file:


Insert the template below, replacing the placeholders with your real values.

  "log": {
    "loglevel": "warning"
  "inbounds": [{
    "port": 1080,
    "listen": "",
    "tag": "socks-inbound",
    "protocol": "socks",
    "settings": {
      "auth": "noauth",
      "udp": false,
      "ip": ""
    "sniffing": {
      "enabled": true,
      "destOverride": ["http", "tls"]
  "outbounds": [{
    "protocol": "vmess",
    "settings": {
      "vnext": [{
        "address": "YY.YY.YY.YY", 
        "port": 443,
        "users": [
          { "id": " b831381d-6324-4d53-ad4f-8cda48b30811",
            "alterId": 233 }
    "streamSettings": {
      "network": "ws",
      "security": "tls",
      "tlsSettings": {
        "allowInsecure": false,
        "serverName": ""
      "wsSettings": {
        "path": "/8snasdr9",
        "headers": {
          "Host": ""
    "protocol": "freedom",
    "settings": {},
    "tag": "direct"
    "protocol": "blackhole",
    "settings": {},
    "tag": "blocked"
  "routing": {
    "domainStrategy": "IPOnDemand",
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "blocked"
        "type": "field",
        "domain": ["geosite:category-ads"],
        "outboundTag": "blocked"
  "dns": {
    "hosts": {
      "": "",
      "": "",
      "": "",
      "": ""
    "servers": [
        "address": "",
        "port": 53,
        "domains": [
  "policy": {
    "levels": {
      "0": {
        "uplinkOnly": 0,
        "downlinkOnly": 0
    "system": {
      "statsInboundUplink": false,
      "statsInboundDownlink": false,
      "statsOutboundUplink": false,
      "statsOutboundDownlink": false
  "other": {}

Save and close the file.

To start the V2Ray client, run:

cd ~/Downloads/v2ray-linux-64

./v2ray -config=config.json

Keep V2Ray open in the terminal and leave it running.

Launch Firefox. Click Settings in the Network Settings section to configure the network as follows:

  • Select Manual proxy configuration.
  • Fill in in SOCKS Host.
  • Fill in 1080 in the Port.
  • Select SOCKS v5.
  • Check Proxy DNS when using SOCKS v5.

Press OK. Requests are now routed through Firefox to the V2Ray client, which forwards them to the V2Ray server.

V2Ray is now ready to use.

How to Use V2Ray on Linux Ubuntu

To work with V2Ray on Linux, you can use the below commands:

V2Ray Command Operation
v2ray info View V2Ray configuration information
v2ray configChange V2Ray configuration
v2ray linkGenerate V2Ray configuration file link
v2ray infolinkGenerate V2Ray configuration information link
v2ray qrGenerate V2Ray configuration QR code link
v2ray ssChange Shadowsocks configuration
v2ray ssinfoView Shadowsocks configuration information
v2ray ssqrGenerate Shadowsocks Configure QR code link
v2ray statusView V2Ray running status
v2ray startStart V2Ray
v2ray stopstop V2Ray
v2ray restart restart V2Ray
v2ray logView V2Ray Run log
v2ray updateUpdate V2Ray
v2ray update.shupdate V2Ray management script
v2ray uninstallUninstall V2Ray

Why Use V2Ray on Ubuntu 20.04?

With the help of the strong and adaptable program V2Ray, you get beyond Internet filtering and visit websites that are restricted.

Installing V2Ray on Ubuntu serves you the following benefits:

  • Bypass Censorship.
  • Lightweight.
  • Fast speed.
  • Secure Encryption (AES-128, AES-256, and ChaCha20).
  • Flexible Routing.
  • difficult to block.
  • Developer-Friendly.

Is V2Ray better than Shadowsocks?

V2Ray is a sophisticated version of the Shadowsocks.

Both are the secure and popular tools used for bypassing internet censorship and ensuring secure communication. However, consider that:

  • Shadowsocks is just a simple and single proxy tool, but V2Ray is designed as a complicated platform for developers.
  • The deployment process for Shadowsocks is simpler than that of V2Ray, which requires more complex setups.
  • V2Ray is more than a protocol and supports various protocols.
  • V2Ray comes with advanced features and customization.


By hiding your IP address, V2Ray shields your online activities from spies and hackers who attempt to view your browser history.

To install and configure V2Ray on the client computer, follow the same process as Step 1 and install V2Ray on a Linux desktop.

Consider that the V2Ray server’s and the client’s id parameters have to match.

Leave a Reply

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