Cross the GFW Using V2Ray

After Shadowsocks died, I'd been using Astrill VPN for some time. But it's not so ideal. The speed cannot be guaranteed and I always needed to try different servers to find one with fast speed. So again I decided to set up my own server to cross the GFW.

The technology I chose is V2Ray. It turns out to be a genius decision. For the past few months it always worked reliably. Here is what needs to be done to set up V2Ray.

Most importantly you need a VPS abroad and mine is from Linode JP. Most importantly you need to make sure the server is not blocked by GFW. You could use this tool to check. I also have a NAT from CloudIPLC, which is optional. I will talk more about it in later post. Now let's focus on the fundamentals. Both servers have x86-64 architecture and Ubuntu 18.04 as OS.

Although V2Ray doesn't distinguish between server and client like Shadowsocks does, it still needs consistency. You'd better use the same version for them. Here I'm using version 4.27.0.

Set up V2Ray on the VPS abroad

The first thing is to install V2Ray on the server. You need two files to do so. One is install-release.sh and the other is v2ray-linux-64.zip. After that run the command below to install V2Ray. Don't forget to add execute permission to the script file.

wget https://github.com/v2ray/v2ray-core/releases/download/v4.27.0/v2ray-linux-64.zip
wget https://movier.github.io/files/install-release.sh
chmod +x install-release.sh
./install-release.sh -l v2ray-linux-64.zip

After that, according to the instructions, you may need to run the commands below.

systemctl enable v2ray
systemctl start v2ray

Next we need to configure V2Ray. The path to the configuration file is /usr/local/etc/v2ray/config.json.

{
    "inbounds": [
        {
            "port": 10086,
            "protocol": "vmess",
            "settings": {
                "clients": [
                    {
                        "id": "738b9584-82cd-40a6-810d-25b3c2133961"
                    }
                ]
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom",
            "settings": {}
        }
    ]
}

As you can see, the content is super simple. Just replace the port and client id with your own value.

Finally V2Ray needs to be restarted to make the configurations work.

service v2ray restart

Set up V2Ray on Mac

After setting up the server, we need a client to test it. Here I'm using Mac. It's super simple to set up V2Ray on Mac. You just need Mac version for V2Ray which is v2ray-macos-64.zip in my case. Unzip is and edit the configuration file config.json in the directory.

{
    "inbounds": [
        {
            "port": 1080,
            "listen": "127.0.0.1",
            "protocol": "socks",
            "settings": {
                "udp": true
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "vmess",
            "settings": {
                "vnext": [
                    {
                        "address": "8.8.8.8",
                        "port": 10086,
                        "users": [
                            {
                                "id": "738b9584-82cd-40a6-810d-25b3c2133961"
                            }
                        ]
                    }
                ]
            }
        },
        {
            "protocol": "freedom",
            "tag": "direct",
            "settings": {}
        }
    ],
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "outboundTag": "direct",
                "domain": [
                    "geosite:cn"
                ]
            },
            {
                "type": "field",
                "outboundTag": "direct",
                "ip": [
                    "geoip:cn",
                    "geoip:private"
                ]
            }
        ]
    }
}

Three values need to be set accordingly, which are address, port and user id. After that you can open v2ray executable file to start V2Ray. To test it, you can either set system proxy or use Proxy SwitchyOmega in Chrome.

If you are lucky enough, you can cross the GFW now.