How to Set Up V2Ray Proxy on Ubuntu 22.04/20.04 Server

This tutorial is going to show you how to set up V2Ray proxy server on Ubuntu 22.04/20.04. V2Ray is a lightweight, fast, and secure Socks5 proxy to bypass Internet censorship. We will learn how to set up the server side and how to configure the desktop client on Ubuntu/Windows.

V2Ray Features

  • Lightweight and fast. In my test, I can watch YouTube 4K videos with V2Ray. YouTube is blocked in my country (China).
  • Runs on Linux and most BSD servers.
  • There is official V2Ray client software for Linux, macOS, Windows, and BSD. For Android and iOS, there are third-party apps available.
  • Easy to set up for system administrators
  • V2Ray can be configured to operate on TCP port 443 and uses standard TLS protocol to encrypt network traffic. It looks like a standard HTTPS protocol, which makes it hard to be blocked.
  • V2Ray is more than a simple proxy tool. It’s designed as a platform that developers can use to build new protocols and tools.

Requirements

To follow this tutorial, you will need a VPS (Virtual Private Server) that can access blocked websites freely (Outside of your country or Internet filtering system). I recommend Kamatera VPS, which features:

  • 30 days free trial.
  • Starts at $4/month (1GB RAM)
  • High-performance KVM-based VPS
  • 9 data centers around the world, including the United States, Canada, UK, Germany, The Netherlands, Hong Kong, and Isreal.

Follow the tutorial linked below to create your Linux VPS server at Kamatera.

Once you have a VPS running Ubuntu 22.04/20.04, follow the instructions below.

Step 1: Install V2Ray on Ubuntu 22.04/20.04 Server

SSH into your remote Ubuntu server. If you are running Ubuntu 22.04/20.04, then I recommend manually installing V2Ray, because the v2ray package in the repository has a problem when starting it up. Run the following command to install dependency packages.

sudo apt install curl unzip

Download the official V2Ray install script. (I don’t usually recommend installing software with third-party scripts, but this is the install script provided by official V2Ray developers, so I use it.)

curl -O https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh

Run the install script.

sudo bash install-release.sh

Check status:

sudo systemctl status v2ray

sudo systemctl status v2ray

If it’s not running, then restart it.

sudo systemctl restart v2ray

Enable auto-start at system boot time.

sudo systemctl enable v2ray

Step 2: Set Up NTP Time Sync

It’s very important that your server has accurate time, or V2Ray can fail. This is to ensure the best security for users. Check the time on your server.

timedatectl

Sample output:

v2ray ntp time sync

As you can see, my server system clock is synchronized. If this is not the case on your server, please follow the tutorial linked below to set up NTP time synchronization.

Step 3: Configure V2Ray on the Server

Edit V2Ray configuration file with a command-line text editor such as Nano.

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

Delete everything in this file, then add the following lines. Replace the id with some random characters in UUID format. You can use an online UUID generator.

{
  "inbounds": [{
    "port": 10086,
    "protocol": "vmess",
    "settings": {
      "clients": [
        { 
          "id": "b831381d-6324-4d53-ad4f-8cda48b30811",
          "level": 1,
          "alterId": 64
        }
      ]
    }
  }],
  "outbounds": [{
    "protocol": "freedom",
    "settings": {}
  },{
    "protocol": "blackhole",
    "settings": {},
    "tag": "blocked"
  }]
}

Save and close the file. V2Ray server will listen on port 10086. Then restart V2Ray for the changes to take effect.

sudo systemctl restart v2ray

Check listening ports.

sudo ss -lnpt | grep v2ray

Sample output:

LISTEN 0      4096                 *:10086            *:*    users:(("v2ray",pid=701205,fd=3))

Step 4: Configure Firewall

If you are using iptables firewall on your server, then you need to allow traffic to the TCP port V2Ray is listening on. For example, if port 10086 is being used by V2Ray, then run the following command:

sudo iptables -I INPUT -p tcp --dport 10086 -j ACCEPT

If you are using UFW firewall, then run the following commands:

sudo ufw allow 10086/tcp

Step 5: Install and Configure V2Ray on Client Computer

Linux Desktop

Please follow the same procedure in step 1 to install V2Ray on Linux desktop. Once it’s done, edit the configuration file.

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

Delete everything in this file, then add the following lines.

{
    "inbounds": [
        {
            "port": 1090, 
            "listen": "127.0.0.1",
            "protocol": "socks",
            "settings": {
                "udp": true
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "vmess",
            "settings": {
                "vnext": [
                    {
                        "address": "server_ip_address",
                        "port": 10086, 
                        "users": [
                            {
                                "id": "b831381d-6324-4d53-ad4f-8cda48b30811"
                            }
                        ]
                    }
                ]
            }
        },
        {
            "protocol": "freedom",
            "tag": "direct"
        }
    ],
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "ip": [
                    "geoip:private"
                ],
                "outboundTag": "direct"
            }
        ]
    }
}

Replace server_ip_address with your actual server IP address. The id parameter on V2Ray client must match the id parameter on V2Ray server. It’s like a pre-shared password.

Save and close the file.  Then restart V2Ray for the changes to take effect.

sudo systemctl restart v2ray

Check listening ports.

sudo ss -lnpt | grep v2ray

Sample output:

LISTEN 0      4096       127.0.0.1:1090       0.0.0.0:*    users:(("v2ray",pid=495211,fd=3))

V2Ray client listens on port 1090 (for web browsers) and will redirect requests to the V2Ray server, which is listening on port 10086.

Windows

Windows users can download V2Ray client from its Github release page. Click the Show all assets link, then you can find the V2Ray Windows ZIP file.

Unzip the file. You will find a config.json file. Use NotePad or your favorite text editor to open this file. Delete everything in this file, then add the following lines.

{
    "inbounds": [
        {
            "port": 1090, 
            "listen": "127.0.0.1",
            "protocol": "socks",
            "settings": {
                "udp": true
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "vmess",
            "settings": {
                "vnext": [
                    {
                        "address": "server_ip_address",
                        "port": 10086, 
                        "users": [
                            {
                                "id": "b831381d-6324-4d53-ad4f-8cda48b30811"
                            }
                        ]
                    }
                ]
            }
        },
        {
            "protocol": "freedom",
            "tag": "direct"
        }
    ],
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "ip": [
                    "geoip:private"
                ],
                "outboundTag": "direct"
            }
        ]
    }
}

Replace server_ip_address with your actual server IP address. The id parameter on V2Ray client must match the id parameter on V2Ray server. It’s like a pre-shared password.

Save and close the file. Then open Window Powershell and run the following command to start v2ray, assuming the v2ray-windows-64 folder is extracted in your Desktop folder.

. \\Desktop\v2ray-windows-64\v2ray run

Step 6: Configure Web Browser to Use V2Ray Proxy

To make your program use V2Ray proxy, the program must support SOCKS proxy. Programs like Firefox, Google Chrome and Dropbox allow users to use proxy. I will show you how to configure Firefox and Google Chrome.

Firefox

In Firefox, go to Edit > Preferences > General (or Tools -> Options -> General). Then scroll down to the bottom and click Settings in Network Setting.

In the Connection Settings window, select manual proxy configuration. Then select SOCKS v5 because V2Ray is a Socks5 proxy. Enter 127.0.0.1 in the SOCKS Host field and 1090 in the port field. Make sure Proxy DNS when using SOCKS v5 is enabled. Click OK to apply these modifications.

Firefox v2ray proxy settings

Google Chrome

I recommend installing the Proxy SwitchyOmega extension to manage proxies for Google Chrome.

google chrome Proxy SwitchyOmega

Once the extension is installed in Google Chrome, configure a proxy server as follows:

  • Choose the SOCKS5 protocol.
  • Set 127.0.0.1 as the server address.
  • Set 1090 as the port number.

google chrome v2ray proxy settings

Apply the changes. Then click the extensions icon on the upper-right corner and click Proxy SwithyOmega.

proxy swithy omega shadowsocks-libev

By default, SwithyOmega uses the operating system’s proxy settings. We need to change it from system proxy to proxy.

switchyomega default proxy

Now your proxy should be working.

Step 7: DNS Leak Test

Go to dnsleaktest.com. You will see your V2Ray server’s IP address, which indicates that your V2Ray proxy is working.

v2ray dns leak test

Click the Standard test. Make sure your local ISP isn’t in the test results.

shadowsocks-libev ubuntu 17.10

Step 8: Enable TCP BBR

TCP BBR is a TCP congestion control algorithm that can drastically improve connection speed. Run the following two commands to enable TCP BBR algorithm.

echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.d/60-custom.conf

echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.d/60-custom.conf

Then apply the changes with the below command. The -p option will load sysctl settings from /etc/sysctl.d/60-custom.conf file. This command will preserve our changes across system reboots.

sudo sysctl -p /etc/sysctl.d/60-custom.conf

How to Upgrade V2Ray

Simply run the install script again.

sudo bash install-release.sh

Wrapping Up

That’s it! I hope this tutorial helped you install V2Ray proxy on Ubuntu. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks 🙂

Rate this tutorial
[Total: 3 Average: 5]

6 Responses to “How to Set Up V2Ray Proxy on Ubuntu 22.04/20.04 Server

  • Thank you very much for this tutorial, I’m from Iran and at least 25% of people who access to Internet is via v2ray.

  • Hi, I had sent you a query to your email – from thalazywebmaster [aht] gmail – whats your tot on email replies 🙂

  • hi, thanks for sharing. could you tell us the name of the 3rd party apps for Android/iOS? free or paid?

    and how secure is V2Ray compare to others like OpenVPN and Softether?

  • casperpda
    5 days ago

    Thanks for Sharing, would you please advise how can we connect from iPhone and Android. I try to use the shadowrocket app on iOS but its not connecting. Appreciate your assistance to provide the steps.

  • casperpda
    3 seconds ago

    Hello, Would you please upgrade the guide to run behind Cloudflare.

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here