March 09, 2023

Configuring VPN v2ray on Linux server

Words

749

Time

1m 9s

Contributors

45

Words read

14.8k


Jump to research

Composed by

Profile picture

h. a.

Views

1899

Version history

h. a., 607d ago

Have an opinion? Send us proposed edits/additions and we may incorporate them into this article with credit.

V2Ray

V2Ray

V2Ray is a protocol designed to bypass censorship, making it the most reliable option for a Linux VPN server [3] . It is easily configurable with a GUI using v2-ui/x-ui [4] , and it supports spoofing websites using SNI [8] . Additionally, pairing V2Ray with BBR can increase speed significantly [3] . Configuring V2Ray on a Linux server requires downloading an install script and setting up appropriate ownership for configuration and authentication files [10] . Once installed, you'll need to enable TUN/TAP Adapter and IP forwarding in the kernel and alter DNS resolver settings to avoid DNS leak [5, 10].
OpenVPN

OpenVPN

It seems that OpenVPN is a good option for configuring VPN v2ray on a Linux server [2] . It is lightweight and very fast and easy to setup [3] , and can be baked into the kernel on the client side for more security than OpenVPN or Shadowsocks [3] . Setting it up requires installing OpenVPN, configuring the firewall to allow TCP traffic over port 943 and UDP traffic over port 1194 [9] , as well as disabling IPv6 to set up an OpenVPN tunnel [9] . It also requires setting up appropriate ownership for all configuration and authentication files to run the OpenVPN server daemon under a non-root account [9] , and downloading prebuilt server and client configuration file templates [9] .
ShadowsocksR

ShadowsocksR

It seems that ShadowsocksR is a network proxy which is good and easy to setup for a simple proxy. People say that it is less reliable than v2ray, and not as stable in China. It is not as fast as Shadowsocks or v2ray, but it may be faster than OpenVPN or ShadowsocksR [6] .
WireGuard

WireGuard

WireGuard is a full-on VPN and seems to be the most lightweight and fastest option for configuring a VPN server on Linux. It is said to be easier to setup than OpenVPN or Shadowsocks and can be baked into the kernel on the client side for more security than those protocols. [6] Additionally, it can be enabled with the firewall-cmd command and started with systemctl enable --now openvpn-server@OVPNserver2020.service [10] , making it a viable option when configuring a VPN v2ray on Linux server.
BBR

BBR

It seems BBR is a network protocol enhancement which can improve the speed and stability of v2ray. People say that with BBR, v2ray is more reliable in China and can be used to bypass censorship. It also supports more masking protocols than Shadowsocks or ShadowsocksR [1] , and has better performance than OpenVPN [2] . It can be baked into the kernel on the client side for more security than OpenVPN or Shadowsocks [6] . Setting up BBR alongside v2ray is apparently recommended for faster speed [7] .
All answers

All answers

  • V2Ray
  • OpenVPN
  • ShadowsocksR
  • WireGuard
  • BBR
  • Nginx
  • cURL
  • Clash for Windows
  • OpenWRT
  • ADW
  • Linux VPN server
  • UUID
  • SNI
  • Trojan
  • DNS lookup
  • Installation

    Installing v2ray on a Linux server is easy and can be done with a few commands. You can use the command "bash <(curl -L -s https://install.direct/go.sh)" [1] for Ubuntu and Debian, or the command "yum install openvpn" [9] for CentOS to install OpenVPN. For further security, consider installing BBR alongside v2ray [6] .

    Configuration

    Configuring v2ray requires editing the configuration file, replacing the id with some random characters in UUID format [4] , and setting up a virtual host file for V2Ray [4] . Additionally, you should update the Linux Server Date Time with the command "$ date" [5] , so that your connection is more secure and reliable.

    Protocols

    When considering which protocol to use with your v2ray server, Trojan is recommended as it can provide faster connection speed than Shadowsocks or ShadowsocksR [6] . Furthermore, SNI (Server Name Indication) should be used to trick ISP into thinking the connection is to a specific website [8] .

    Encryption

    Using OpenVPN as the connection protocol will ensure that all traffic is encrypted, while TUN/TAP Adapter should be enabled to ensure that IP forwarding in kernel works properly [9] . It is also important to disable IPv6 so as to set up an OpenVPN tunnel successfully [9] .

    Bypassing Mainland Address

    Bypass mainland address can be done in the app settings by selecting "Bypass mainland address" under "Predefined rules" and exporting the rules to the config file [1] . This will allow socks/http proxy to send all traffic directly while proxying everything else to vmess. Furthermore, consider subscribing to a paid premium VPN service or setting up a free VPN for added security measures [7] .

    Jump to top

    Research

    Source: "Configure your OpenVPN server on Linux | Openso..." (from web, opensource.com)

    • Create a configuration file
      • Set the sysctl value net.ipv4.ip_forward = 1 to enable routing
      • Set up appropriate ownership for all configuration and authentication files to run the OpenVPN server daemon under a non-root account
      • Set OpenVPN to start with the appropriate configuration file
      • Configure your firewall
    • Use prebuilt server and client configuration file templates
      • Download script from website to set up appropriate directories and set up ownership
      • Edit OVPNserver2020.conf and OVPNclient2020.ovpn to include your IP addresses
    • Set up file ownership
      • Create a user called openvpn that is a member of a group named openvpn and set the ownership of everything in /etc/openvpn to this user and group
    • Firewall
      • Enable the OpenVPN service with the firewall-cmd command
    • Start your server
      • Use systemctl enable --now openvpn-server@OVPNserver2020.service to start your OpenVPN server and make it start automatically after a reboot

    Source: "Some questions about my v2ray server." (from reddit, r/VPN)

    • Use a script to install v2ray without needing to get a domain
    • Use v2ray’s GUI to configure any website as the spoofed site
      • Use v2-ui/x-ui, which gives the GUI experience when configuring the v2ray server
      • To spoof, fill in the SNI field with the desired website
    • Use Trojan as the connection protocol
      • Transport protocol should be TCP
    • Use SNI(Server name indication) to trick the ISP into thinking the connection is to a specific website
      • ISP can give the special package for Zoom because they have basic DPI
      • ISP don’t bother to verify if the domain actually resolves for the VPS IP
    • Use Windows V2ray client settings
      • Follow the instructions for the Windows V2ray client settings

    Source: "V2ray openvpn" (from reddit, r/dumbclub)

    • Use a VPN provider
      • It will save time and money
      • Can buy packages from providers for 15-30rmb per month
    • Configure a remote VPS with V2Ray
      • Use the setting: socks-proxy x.x.x.x xxx
      • Change the public IP of the server and update the DNS to see the new address
    • Route the connection to a commercial VPN’s IP
      • Tunnel openvpn through v2ray for faster connection
      • One encryption point and 2 decryption points as opposed to encrypt/decrypt/encrypt/decrypt
      • Cloudflare and DNS lookup for a domain can add 100m/s ish when added together

    Source: "How to Set Up and Manage a Linux VPN Server Usi..." (from web, www.hostinger.com)

    • Installing OpenVPN on a Linux VPN Server
      • Prerequisites: Account with root access or sudo privileges, configure the firewall to allow TCP traffic over port 943, UDP traffic over port 1194
      • For Ubuntu and Debian: Update indexes using apt, install ca-certificates wget net-tools gnupg, download client from OpenVPN website using wget command, and install OpenVPN Access Server
      • For CentOS: Install OpenVPN Access Server using yum
      • After installation, enable TUN/TAP Adapter and enable IP forwarding in the kernel
      • Disable IPv6 to set up an OpenVPN tunnel
      • Alter DNS resolver settings to avoid DNS leak
    • Connecting to Other Devices
      • Install and connect the OpenVPN Client for Windows
      • Install and connect the OpenVPN Client for macOS
      • Install and connect the OpenVPN Client for Linux
      • Install and connect the OpenVPN Client for Android
      • Install and connect the OpenVPN Client for iOS

    Source: "ShadowsocksR vs v2ray vs WireGuard?" (from reddit, r/dumbclub)

    • v2ray
      • V2ray is an undetectable protocol for bypassing the censorship and is the best one out of the three (shadowsocks, v2ray, WireGuard).
      • It is most reliable, and governments have not yet found a way to block it.
      • It is recommended to install BBR alongside v2ray for faster speed.
    • Shadowsocks
      • It is a network proxy and a more proper comparison would be between Shadowsocks and v2ray.
      • It is good and easy to setup for a simple proxy.
    • WireGuard
      • It is a full on VPN.
      • It is lightweight and very fast and easy to setup.
      • It can be baked into the kernel on the client side for more security than OpenVPN or Shadowsocks.

    💭  Looking into

    What are the best ways to test the connection of a VPN server?

    💭  Looking into

    What are the benefits of setting up a private VPN server?

    💭  Looking into

    What are the detailed steps to install OpenVPN and cURL programs?

    💭  Looking into

    What are the exact steps to select Bypass mainland address?

    💭  Looking into

    What is the exact syntax for the command to save the config output to a config.json file?

    Source: "How to Set Up a VPN Server on Linux | Step-by-s..." (from web, proprivacy.com)

    • Setting up a private Linux VPN server
      • Need to install OpenVPN and cURL programs
      • Need to download a VPN installation script, make it executable and run it
      • Make sure you have sudo privileges or root access
      • Allow TCP traffic over port 943, and UDP traffic over port 1194
    • Install OpenVPN on client computer and the OpenVPN extension for the network manager
    • Download configuration file from server
    • Copy configuration file to OpenVPN client folder
    • Add configuration file to the Network Manager
    • Test the connection
    • Test for IP, IPv4, IPv6, DNS and WebRTC leaks
    • Consider subscribing to a paid, premium VPN service
    • Consider setting up a free VPN
    • Benefits of setting up private VPN server include: being in complete control of your traffic, streaming remotely, accessing files and applications remotely, no risk of data-logging, easier to spot and combat intrusions, more traceability back to yourself.

    Source: "How To Install V2ray On Amazon EC2 And Google C..." (from web, www.dev2qa.com)

    Source: "How to Set Up V2Ray Proxy on Ubuntu 22.04/20.04..." (from web, www.linuxbabe.com)

    • Install V2Ray on Ubuntu 22.04/20.04 Server
      • Download the official V2Ray install script
      • Run the install script
      • Check status of V2Ray
      • Restart V2Ray
      • Enable auto-start at system boot time
    • Set Up NTP Time Sync
      • Check the time on your server
      • Follow the tutorial to set up NTP time synchronization
    • Configure V2Ray on the Server
      • Edit V2Ray configuration file
      • Replace the id with some random characters in UUID format
    • Configure Reverse Proxy
      • Install Nginx web server
      • Create a virtual host file for V2Ray
      • Replace example.com with your own domain name

    Source: "How to setup your own v2ray server on a VPS" (from reddit, r/dumbclub)

    • Setting up a v2ray server on a VPS
      • Tutorial can be found at https://privacymelon.com/v2ray-setup-guide/
      • Can use Clash for Windows as a v2ray client
      • Slower than Shadowsocks or ShadowsocksR, but more stable and has more variations and masking protocols
      • More stable in China
    • Setting up a v2ray client on OpenWRT router
      • No experience with this, but may be possible
    • Setting up a v2ray client on Windows Server
      • Can be done on ADW

    Source: "Please help me using vmess and v2ray on linux" (from reddit, r/dumbclub)

    • Construct the entire client config
      • This includes an inbound (e.g. socks) and the vmess outbound
      • Save the output of the config to a config.json file
      • Use the command “v2ray -c config.json”, or start it in the background with a systemd service
    • Bypass mainland address
      • In the app settings select “Bypass mainland address” under “Predefined rules”
      • This will export the rules to the config file
      • The socks/http proxy can send all traffic to it, which will send Chinese traffic directly while proxying everything else to vmess.

    💭  Looking into

    What is the best way to configure VPN v2ray on a Linux server?