Running V2Ray VPN Service via WebSocket and Gcore Services

Running V2Ray VPN Service via WebSocket and Gcore Services

This guide will walk you through setting up the V2Ray proxy tool with the WebSocket protocol and Gcore services. A Gcore Basic VM instance will act as your V2Ray server, while Gcore DNS, CDN, and DDoS Protection will provide a fast and reliable connection via WebSocket. A significant advantage of this approach is the ability to run your own V2Ray server on a virtual machine for only €3.2 per month, while benefiting from additional Gcore services for free.

In short, the connection between a user and the internet will be organized as follows:

  • A V2Ray client is deployed on a user device.
  • The V2Ray client connects to a V2Ray server deployed on Gcore Basic VM using DDoS-protected CDN and DNS.
  • This connection gives the user secure access to a required website.

Once you’ve completed the installation process, here’s how your device will interact with websites you visit:

Data flow diagram showing V2Ray connection to a website established using Gcore services
Figure 1: Data flow diagram for V2Ray connection based on Gcore services

There is one prerequisite you need to complete before beginning this guide. To use DNS and CDN, you need to have a domain already registered. The domain will be delegated to Gcore authoritative NS servers.

What Is V2Ray?

V2Ray is a free proxy tool that secures your internet connection and is widely used as a VPN service. It supports multiple protocols, customizable routing, obfuscation, and reverse proxy features. V2Ray is compatible with various platforms, including Windows, macOS, Linux, and mobile devices. The tool is maintained by the V2Fly open-source community, ensuring it stays up to date.

What Is WebSocket?

WebSocket is a computer communication protocol that enables full-duplex, two-way communication channels over a single Transmission Control Protocol (TCP) connection. This advanced technology supports real-time, event-driven communication between a server and a client (such as a web browser.)

Key benefits of WebSocket include:

  • Full-duplex communication: Allows both client and server to send and receive data simultaneously, a significant advantage over the traditional request-and-response model of HTTP.
  • Low latency: Designed for rapid communication, making it ideal for real-time applications.

By combining V2Ray with the WebSocket protocol, you achieve a faster and more stable internet connection.

How to Set Up V2Ray via WebSocket

Setting up V2Ray requires the following steps:

  1. Create a virtual machine (VM) in the Gcore Customer Portal under Edge Cloud.
  2. Connect to your VM and update the OS.
  3. Install the V2Ray server on your VM.
  4. Access the V2Ray server GUI (graphical user interface.)
  5. Configure DNS.
  6. Configure CDN.
  7. Set up a node in the V2Ray server.
  8. Connect to your server from your local machine.

Basic Gcore DDoS Protection is a built-in feature of Basic VM, so you don’t need to configure it.

Let’s go through all the steps in order.

Step 1: Create a Virtual Machine for a V2Ray Server

  1. Log into your Gcore Customer Portal and navigate to the Basic VM section. If you don’t yet have an account, sign up first.
  2. Choose a region for your VM. For this article, we’ll use Frankfurt.
Region selection window for VM setup in Gcore, highlighting Frankfurt
Figure 2: Choose a region for the VM
  1. Configure the VM as follows:

Region: Frankfurt
OS: Ubuntu 23.04
Flavor: Basic VM, 1 vCPU / 1GB RAM / 25GB SSD
SSH Key: Select your public SSH key or generate a new one.
Name: v2rayserver (or whatever you want.)

  1. After configuration, click Create Basic VM. The VM will appear in the “Virtual Instances” list. Wait for the VM’s status to change from “Creating” to “Power on.”
Virtual Instances window showing a new VM with “Power on” status
Figure 3: The newly created VM with “Power on” status

Note the highlighted IP address in Figure 3: this is the public IP address we’ll use in Step 2 to connect to the VM.

  1. In the same Basic VM section, go to Networking > Firewall and click the default firewall. You can choose one of two options when adding inbound rules: a) set “All TCP” and “All UDP” for TCP and UDP ports, or b) add specific inbound rules:
  • TCP rule with port 3321
  • TCP rule with port 80
  • UDP rule with port 3321

This is what the inbound rules should look like:

Firewall settings window displaying newly added inbound rules
Figure 4: The firewall settings

Step 2: Connect to Your Basic VM and Update OS

Before installing a V2Ray server, you need to update the Basic VM operating system.

  1. To connect to your VM, open your CLI and use the following command, inserting the public IP address of your VM:
ssh ubuntu@<V2Ray server public IP address>

Example:

ssh ubuntu@176.119.203.30
  1. After you’re connected, update your OS using the following command:
sudo su
root@v2rayserver:/home/ubuntu# apt update

Note: From this step on, instead of “v2rayserver”, you should see/use your server’s name.

Step 3: Install the V2Ray Server on Your VM

The easiest way to install the V2Ray server is by using the official V2Ray installation script. To do that, run the following command:

root@v2rayserver:/home/ubuntu# bash &lt;(curl -Ls https://raw.githubusercontent.com/vaxilu/x-ui/master/install.sh)

The V2Ray GUI and CLI tools only have a Chinese version. If you don’t know Chinese, don’t worry. Just follow our instructions.

During the installation, you’ll need to configure the server’s account name, password, and panel access port. This is how it looks in our example:

出于安全考虑,安装/更新 完成后需要强制修改端口与账户密码
确 认是否继 续? (Confirm to continue?) [y/n]:y
请设置您的账户名 (Please set your account name):v2ray
您的账户名将设定为:v2ray
请设置您的账户密码 (Please set your account password):v2raypassword
您的账户密码将设定为:v2raypassword
请设置面板访问端口 (Please set the panel access port):5000
您的面板访问端口将设定为:5000

Step 4: Connect to the V2Ray Server GUI

  1. To access the V2Ray server GUI, open a web browser and enter the URL of your V2Ray server:

http://<V2Ray server public IP address>:5000

Here’s an example:

http://176.119.203.30:5000

You’ll see the login window:

Login window of the V2Ray Server GUI for username and password entry
Figure 5: The V2Ray Server GUI login window
  1. Enter the username and password that you chose in Step 3. You will see this dashboard:
V2Ray Server GUI dashboard displaying server resource metrics
Figure 6: The V2Ray Server GUI

Step 5: Configure DNS

We will use Gcore free public DNS with a delegated domain to create a new record for the V2Ray server.

  1. Send us a request for DNS activation. You’ll receive an email notification when Gcore DNS is activated.
  2. Create a new zone for your domain. The newly-created DNS zone will be displayed in the All zones section, and its status should be “Delegated”.
Gcore Customer Portal “All zones” section showing a delegated DNS zone
Figure 7: The delegated zone
  1. Add a new A record with the following configuration:

Type (Required): A
Name: <whatever name you want>.<your domain>
IPv4 address (Required): <V2Ray server public IP address>

Note: For the name, you may want to use the particular purpose for which this VM will be used or the region chosen.

Click Add.

Configuration example:

Window displaying configuration of a new A record for V2Ray server
Figure 8: The new A record configuration

Step 6: Configure CDN

  1. Navigate to the CDN section of the Gcore Customer Portal and click Create CDN resource.
  1. Choose the option “Accelerate and protect entire site” and click Confirm.
Window for selecting a CDN acceleration option in the Gcore Customer Portal
Figure 9: Choose an acceleration type
  1. Enter the name you chose in step 5.3 above, and click Confirm.
Window for entering the name of the site for CDN acceleration
Figure 10: Type the site name
  1. Review your DNS records and click Confirm.
Window showing all DNS records for the configured site
Figure 11: The DNS records list
  1. If all the steps have been completed successfully, the CDN resource and DNS zone will be automatically created for the site you specified in the step “Enter site name” above.
Window displaying the created CDN resource and associated DNS zone
Figure 12: The CDN resource and DNS zone are created
  1. Click Confirm and then Open resource settings. You’ll see this window:
Settings window for configuring CDN resource in Gcore
Figure 13: Configure the CDN resource settings
  1. Go to the settings for “Origin” and set the “Origin Source” port as 3321.
Window for setting Origin Source port in CDN resource settings
Figure 14: Set an Origin Source port
  1. In the “Origin shielding” section, enable SSL and select the Let’s Encrypt option.
SSL configuration window for CDN with Let’s Encrypt selected
Figure 15: Enable SSL with the Let’s Encrypt option

WebSocket is now configured. It will take up to twenty minutes for SSL to apply to all CDN nodes.

Step 7: Configure Your Node in the V2Ray Server

The next step is to configure your node.

  1. Go to the V2Ray Server GUI, open the second tab in the menu on the left, and click the blue “+” to open the node settings.
V2Ray Server GUI window for node configuration settings
Figure 16: Open the node settings
  1. Set the following parameters as they’re filled in the image below, except “id” which is filled in automatically. Then, press the blue button at the bottom-right corner.
Configured node settings in the V2Ray Server GUI
Figure 17: Configure the node

Step 8: Connect to Your Server From Your Local Machine

  1. Install the V2Ray client on your device using the appropriate guide.

We’ll use the macOS client V2Box as an example; the details are also applicable to other clients.

  1. Next, copy the server configuration as a QR code. Open the V2Ray node section (step 7.1,) click the first option on the left, and choose the first item in the drop-down list.
V2Ray Server GUI displaying the list of servers
Figure 18: The V2Ray server list

Click Copy.

Window showing button and QR code to copy V2Ray server config
Figure 19: Copy the server configuration
  1. Open the V2Ray client, click “+”, and choose the first option in the list to import the configuration.
V2Ray client window with import button for server configuration
Figure 20: Import the server configuration

The configuration profile will then appear in the Configs list.

Configs list in V2Ray client showing imported server configuration
Figure 21: The Configs list with the imported configuration
  1. Click the pencil icon to edit the profile. Change the Address field to your CDN/DNS name, set port 443, enable TLS, and leave the other fields as they are.
Window for editing V2Ray client configuration profile settings
Figure 22: Edit the Config profile

Scroll down and click the blue button to save changes.

Configuration profile window in V2Ray client with ’Save’ button
Figure 23: Save changes

Go to the home page and swipe the “Slide to connect” toggle. You’ll see this window:

Screen confirming successful connection establishment in V2Ray client
Figure 24: The connection is established

Congratulations! You have successfully configured V2Ray on your local machine.

You can now check your new IP address and location using www.whatismyip.com:

Screen showing new IP and location verified via whatismyip.com
Figure 25: Check your new IP via www.whatismyip.com

Conclusion

Using V2Ray in combination with Gcore Basic VM, DNS, CDN, and DDoS protection enhances your internet connection’s security, speed, and resilience, offering a superior alternative to configurations that rely on a single virtual machine to run a V2Ray server.

To learn more about the products we’ve used and their features, please visit their respective Gcore pages:

Try Gcore Basic VM

Subscribe to our newsletter

Stay informed about the latest updates, news, and insights.