How To Install V2ray On Amazon EC2 And Google Cloud Ubuntu Linux

V2ray is similar but better than ShadowSocks. This article will tell you how to install v2ray on an Ubuntu Linux server. It also tells you how to use the v2ray client to access the v2ray server. Before start, you should know that v2ray has strict requirements on time. It is required that the absolute value of the time difference between the server and the client cannot exceed 2 minutes, so you must ensure that the time is accurate enough. Fortunately, v2ray does not require consistent time zones on server and client.

1. Update Linux Server Date Time.

  1. Get Linux server current date-time.
    $ date
    Thu Feb 27 11:48:59 UTC 2020
  2. Change Linux date time and time zone.
    date --set="Fri Jun 28 15:05:15 CST 2020"
    

2. Install V2ray On Ubuntu Linux Server.

  1. First, you should install unzip manually. Otherwise, the v2ray installation will fail.

    $ sudo apt install unzip
  2. Change to the root user.
    $ sudo su
    
    [email protected]:/home/ubuntu#
  3. Install v2ray on Linux server.
    # bash <(curl -L -s https://install.direct/go.sh)
    Installing V2Ray v4.22.1 on x86_64
    Downloading V2Ray: https://github.com/v2ray/v2ray-core/releases/download/v4.22.1/v2ray-linux-64.zip
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100   608  100   608    0     0   2068      0 --:--:-- --:--:-- --:--:--  2068
    100 11.6M  100 11.6M    0     0  3171k      0  0:00:03  0:00:03 --:--:-- 3619k
    Archive:  /tmp/v2ray/v2ray.zip
      inflating: /usr/bin/v2ray/geoip.dat  
      inflating: /usr/bin/v2ray/geosite.dat  
      inflating: /usr/bin/v2ray/v2ctl    
      inflating: /usr/bin/v2ray/v2ray    
    PORT:28922
    UUID:f8fa304d-2c38-4941-ad6e-442a925d74d5
    Archive:  /tmp/v2ray/v2ray.zip
      inflating: /etc/systemd/system/v2ray.service  
    Created symlink /etc/systemd/system/multi-user.target.wants/v2ray.service → /etc/systemd/system/v2ray.service.
    V2Ray v4.22.1 is installed.
    
  4. If you meet the below error when running the above shell script, then you need to browse https://github.com/v2fly/fhs-install-v2ray to see the new v2ray install method.
    # bash <(curl -L -s https://install.direct/go.sh)
    ERROR: This script has been DISCARDED, please switch to fhs-install-v2ray project.
    HOW TO USE: https://github.com/v2fly/fhs-install-v2ray
    TO MIGRATE: https://github.com/v2fly/fhs-install-v2ray/wiki/Migrate-from-the-old-script-to-this
  5. Below are the new v2ray install steps.
    # first install curl
    # apt update
    # apt install curl
    
    # download v2ray install shell script file.
    # curl -O https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh
    # curl -O https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh
    
    # install v2ray.
    # bash install-release.sh
    
    # install geoip.dat, geosite.dat
    # bash install-dat-release.sh
    
    # if you want to remove v2ray
    # bash install-release.sh --remove
    
  6. (Update 2021/02/12 ) The new v2ray installation shell script has been changed to bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh). You should execute the above command in a terminal to install v2ray. From the below command output, we can see the new v2ray configuration file is located at ExecStart=/usr/local/bin/v2ray -config /usr/local/etc/v2ray/config.json. And v2ray has been created as a Linux service daemon, which means it will be auto-started when the Linux OS startup. You can see the v2ray.service file in /etc/systemd/system directory.
    # bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
    ......
    ......
    warning: The following are the actual parameters for the v2ray service startup.
    warning: Please make sure the configuration file path is correctly set.
    ~~~~~~~~~~~~~~~~
    [Unit]
    Description=V2Ray Service
    Documentation=https://www.v2fly.org/
    After=network.target nss-lookup.target
    
    [Service]
    User=nobody
    CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
    AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
    NoNewPrivileges=true
    ExecStart=/usr/local/bin/v2ray -config /usr/local/etc/v2ray/config.json
    Restart=on-failure
    RestartPreventExitStatus=23
    
    [Install]
    WantedBy=multi-user.target
    # In case you have a good reason to do so, duplicate this file in the same directory and make your customizes there.
    # Or all changes you made will be lost!  # Refer: https://www.freedesktop.org/software/systemd/man/systemd.unit.html
    [Service]
    ExecStart=
    ExecStart=/usr/local/bin/v2ray -config /usr/local/etc/v2ray/config.json
    ~~~~~~~~~~~~~~~~
    warning: The systemd version on the current operating system is too low.
    warning: Please consider to upgrade the systemd or the operating system.
    
    installed: /usr/local/bin/v2ray
    installed: /usr/local/bin/v2ctl
    installed: /usr/local/share/v2ray/geoip.dat
    installed: /usr/local/share/v2ray/geosite.dat
    installed: /usr/local/etc/v2ray/config.json
    installed: /var/log/v2ray/
    installed: /var/log/v2ray/access.log
    installed: /var/log/v2ray/error.log
    installed: /etc/systemd/system/v2ray.service
    installed: /etc/systemd/system/[email protected]
    removed: /tmp/tmp.GjBcqyHO19
    info: V2Ray v4.34.0 is installed.
    info: V2Ray v4.34.0 is installed.
    You may need to execute a command to remove dependent software: apt purge curl unzip
    Please execute the command: systemctl enable v2ray; systemctl start v2ray
    
    # apt purge curl unzip
    # systemctl enable v2ray; systemctl start v2ray
    Created symlink /etc/systemd/system/multi-user.target.wants/v2ray.service → /etc/systemd/system/v2ray.service.
    
    # ps -ef|grep v2ray
    nobody    2643     1  0 02:43 ?        00:00:00 /usr/local/bin/v2ray -config /usr/local/etc/v2ray/config.json
    root      2659  2113  0 02:44 pts/1    00:00:00 grep --color=auto v2ray
    
  7. Use vim to edit the v2ray configuration file. The file path is /etc/v2ray/config.json or /usr/local/etc/v2ray/config.json.
    # vim /etc/v2ray/config.json
    
    or
    
    # vim /usr/local/etc/v2ray/config.json
    
  8. Go to https://www.uuidgenerator.net to generate a new unique id and replace it in the above config.json file inbounds —> settings —> clients —> id value. The port number is also decided by yourself. For more configuration settings, please read the article V2ray Configuration Overview.
    {
      "inbounds": [{
        "port": 10086,
        "protocol": "vmess",
        "settings": {
          "clients": [
            {
              "id": "10fdwe3c8-uyer3-df343-t256-df89f7df8",
              "level": 1,
              "alterId": 64
            }
          ]
        }
      }],
      "outbounds": [{
        "protocol": "freedom",
        "settings": {}
      },{
        "protocol": "blackhole",
        "settings": {},
        "tag": "blocked"
      }],
      "routing": {
        "rules": [
          {
            "type": "field",
            "ip": ["geoip:private"],
            "outboundTag": "blocked"
          }
        ]
      }
    }
  9. Enable v2ray auto-start when os starts.
    # systemctl enable v2ray
  10. Run command systemctl start v2ray to start v2ray service.
    systemctl start | stop | restart v2ray

3. Install And Configure V2ray Client.

You can go to the official v2ray client download page to get the v2ray client which matches your needs. I use macOS & Windows, so I will tell you how to use V2RayX on macOS and how to use v2rayN-Core on Windows.

3.1 How to configure v2ray client V2RayX on macOS.

Below are the steps about how to use V2RayX on macOS

  1. Download, install and start V2RayX.
  2. Click the V2RayX icon at Mac top menu bar, then click Configure… menu item.
    v2rayx-configure-menu-
  3. Input v2ray server ip address ( or domain name ), server port number, User ID in the red line input box, input a name in the Tag input box, click OK button to save it. Do not need to modify other fields.
    v2rayx-configure-dialog
  4. Now this newly added v2ray server will be shown in V2RayX —> Server list, check it.
  5. Check the V2RayX —> Global Mode menu item.
  6. You can add multiple v2ray servers, if you do not want to use it, you can click V2RayX —> Unload core. If you want to use it again, you can first select it in V2RayX —> Server list, then click V2RayX —> Load core menu.
  7. For more v2ray configuration, please go to V2ray Configuration Overview. Client and server use the same configuration file. But client’s inbounds settings should map to server outbounds settings vice versa.

3.2 How to configure v2ray client v2rayN-Core on Windows.

  1. Download the newest v2rayN version from the Github website.
  2. Just download the v2rayN-Core.zip file, do not need to download the v2rayN.zip file.
  3. Unzip the v2rayN-Core.zip file to a local folder.
  4. Double click the file v2rayN-Core / v2rayN.exe to run it, then it will open the VMess server list window.
  5. Click the menu item Servers —> Add [VMess] Server to open the Edit Or Add[VMess] Server window.
  6. Input the server domain name/ip in the address input textbox.
  7. Input the server listening port number (443 for HTTPS) in the port input textbox.
  8. Input the v2ray server UUID in the id input textbox.
  9. Input the v2ray server alterId in the alterId input textbox.
  10. Select auto from the security drop-down list.
  11. Select ws from the transport —> network drop-down list.
  12. Select none from the transport —> type drop-down list.
  13. Input the server domain name in the transport —> host input text area.
  14. Input the v2ray server path in the transport —> path input text area. The path value should not start with /, if you meet any error, you can add the / in front of the path value. You should get the path value from the v2ray server configuration.
  15. Select tls from the transport —> tls drop-down list.
  16. Select false from the transport —> allowInsecure drop-down list.
  17. Click the OK button to save the VMess server configuration.
  18. To use the created VMess server in v2rayN-Core, you can right-click it and click the menu item Set As Activate Server(Enter) in the popup menu list.
  19. To use the VMess server as a proxy server, you can right-click the v2rayN icon on the windows tray icon area, then click System Proxy —> Auto Config System Proxy menu item.
  20. To use your local network, you can right-click the v2rayN icon on the windows tray icon area, then click System Proxy —>  Remove System Proxy menu item.

4. Add V2ray Server Port Number In Amazon Or Google Cloud Firewall.

If you use Amazon AWS or google cloud Linux VPS server, generally, your v2ray server port number should be blocked by amazon or google cloud firewall by default. So you should add the port number in amazon AWS or google cloud firewall to allow it.

4.1 Amazon AWS.

Please refer to section 5. Edit EC2 Linux Instance Used Security Group. in the article How To Install ShadowSocks Server On Amazon EC2 Linux

4.2 Google Cloud.

Please refer to section 1. Create A Firewall Rule In Google Cloud. in the article How To Install ShadowSocks On Google Cloud Linux

Below is the youtube video about this article https://youtu.be/TTh38HPl6BA.

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x