My Struggle with the Firewall

I kept running into the same problem while studying: Baidu was not turning up the material I needed, while Wikipedia and experienced developers’ blogs were much easier to find through Google. A reliable way to reach those resources started to feel essential.

After one too many searches for a usable free VPN, I decided to rent a VPS and build a service of my own. What follows is my record of the tutorials, experiments, and things that went wrong. My image-hosting script was mistaken for a DDoS attack and restricted to ten uploads a day, so I have described some steps without screenshots.

1. Shadowsocks + BBR Plus

I started with this Vultr and Shadowsocks tutorial.

First I needed a VPS: essentially, a server rented from a hosting company. The guide recommends Vultr, which seemed reasonable to me, although the $2.50/month plan was no longer available and I could only find the $5/month option.

eknvMSjBmhf84I2.png

Watch out for the IPv6-only option. As its name suggests, it can only reach sites that support IPv6. It is fine for experimenting, though an Alibaba Cloud student VPS might also do for that.

The rest of the server setup is mostly clicking through the screens. Eventually you reach these options:

9YZAJGc8W2Uj47E.png

I did not find these especially useful, but options 1 and 3 were free, so I left them enabled.

I even created another server just to demonstrate the process. If that helps someone reach more of the wider world, it was worth the trouble.

Once the server is ready, connect to it over SSH.

My first setup combines Shadowsocks with bbr plus, so I installed the latter first.

The installer script is:

1
wget --no-check-certificate -O tcp.sh https://github.com/cx9208/Linux-NetSpeed/raw/master/tcp.sh && chmod +x tcp.sh && ./tcp.sh

The script has Chinese-language prompts, which made the next part much easier for me.

DNM6ThaB2r8jU7o.png

Choose option 2. Once it finishes installing, it asks for a restart before continuing; run reboot.

After the server comes back, start the script again:

1
./tcp.sh

This time, select the option that enables the corresponding BBR acceleration.

In this context, think of BBR as a TCP optimization. If TCP itself is unfamiliar, a networking primer will help. BBR Plus is an enhanced version, and the menu also includes a modified BBR variant.

The menu also offers LotServer. These accelerators can help, but the network route still matters, and UDP is a different story—as I discovered later.

With BBR configured, it was time to install Shadowsocks, or SS. Its installer takes care of most of the work.

The installer script is:

1
wget — no-check-certificate -O shadowsocks.sh https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks.sh

The installation is easy to follow. All that scrolling text in a black-and-white terminal also looks suitably dramatic if you want to pretend to be a hacker in public.

When it finishes, it highlights four details in red. Save them: the client will need every one.

1
2
3
4
Your Server IP        :  12.34.56.78
Your Server Port : xxxx
Your Password : xxxxxx
Your Encryption Method: xxxxxxxxxxxxx

The usual commands for controlling the service are:

1
2
3
Start:   /etc/init.d/shadowsocks start
Restart: /etc/init.d/shadowsocks restart
Stop: /etc/init.d/shadowsocks stop

Next, download a Shadowsocks client:

https://shadowsocks.org/en/download/clients.html

Run shadowsocks.exe as administrator and enter the four values from the installer. Then right-click the paper-plane icon to choose global or PAC mode. Update the PAC list first if you use PAC: it sends domestic sites directly and uses the proxy for foreign sites.

If the settings look right but there is still no connection, check the server’s firewall. On CentOS, the ports you need may be closed.

These commands open the chosen port for TCP and UDP:

1
2
3
firewall-cmd --zone=public --add-port=xxxx(your-port)/tcp --permanent
firewall-cmd --zone=public --add-port=xxxx(your-port)/udp --permanent
firewall-cmd --reload

To check which ports are open afterward:

1
firewall-cmd --list-port

shadowsock + bbr plus + kcptun

The first setup worked, but its speed still depended heavily on the TCP route. My roommate suggested kcptun as another way to speed it up. I later deleted that setup, so this section has no screenshots.

The one-click installer is:

1
wget --no-check-certificate https://github.com/kuoruan/shell-scripts/raw/master/kcptun/kcptun.sh && chmod +x ./kcptun.sh && ./kcptun.sh

Its installer also has Chinese prompts and default settings. If you are unsure what to choose, following the defaults is a reasonable starting point.

The server is only half of the setup: you also need a receiving endpoint on the local machine.

The client setup is described at https://ssr.tools/588 (you will need access to that site).

The basic idea is to carry the original TCP traffic over UDP, so a TCP-focused optimization such as BBR may not help that part of the connection. The extra packets trade bandwidth for speed. In my test, a single request did not feel much different, but YouTube and downloads went from roughly 2,000 to 14,000 kbps.

That speed came with a catch. More packets mean more recognizable traffic and more bandwidth for the ISP to carry. The connection could be throttled or its port blocked; repeated blocks could eventually take the IP address offline as well.

During sensitive periods, I would sometimes set one up in the morning only to find it blocked by afternoon. A replacement could disappear again by evening.

v2ray

When Shadowsocks traffic began to be identified, I moved on to V2Ray. It meant dealing with more configuration, but at that point I was willing to try anything that stayed up.

I found an installation script to get the server started:

1
2
3
wget https://install.direct/go.sh
chmod +x ./go.sh
./go.sh

The installer highlights the connection details—uuid, alter_id, IP, and port. Make a note of them for the client:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  inflating: /tmp/v2ray/config.json  
creating: /tmp/v2ray/doc/
inflating: /tmp/v2ray/doc/readme.md
inflating: /tmp/v2ray/geoip.dat
inflating: /tmp/v2ray/geosite.dat
creating: /tmp/v2ray/systemd/
inflating: /tmp/v2ray/systemd/v2ray.service
creating: /tmp/v2ray/systemv/
inflating: /tmp/v2ray/systemv/v2ray
inflating: /tmp/v2ray/v2ctl
extracting: /tmp/v2ray/v2ctl.sig
inflating: /tmp/v2ray/v2ray
extracting: /tmp/v2ray/v2ray.sig
inflating: /tmp/v2ray/vpoint_socks_vmess.json
inflating: /tmp/v2ray/vpoint_vmess_freedom.json
PORT:xxxxx
UUID:cd0e558d-18a5-4077-b5ec-3b3c14a760c7
Created symlink from /etc/systemd/system/multi-user.target.wants/v2ray.service to /etc/systemd/system/v2ray.service.
V2Ray v4.20.0 is installed.

The guide I followed is here:

https://www.4spaces.org/digitalocean-build-v2ray-0-1/

The guide also links to clients; download the one for your device.

Unlike the earlier client setup, V2Ray is configured through a file. Open it on the server:

1
vi /etc/v2ray/config.json

Plenty of people are comfortable editing this straight in Vim. I usually prefer a simple editor or VS Code.

If you are new to Vim, a wall of JSON without highlighting or bracket matching can be disorienting. Here are the basics I needed:

Press a to enter insert mode. When you are done, press Esc, type :wq—including the colon—and press Enter to save and quit.

My own workaround is to leave insert mode, select from the cursor to the end with vG (lowercase v, uppercase G), and copy the text into VS Code. After editing, I put it back into the server file.

The configuration has to be valid JSON. If the format is unfamiliar, a JSON guide or validator can help you check it.

Here is what the result looks like:

1VjIWMCsX6kt4iO.png

The speed fluctuates between about 2,000 and 10,000 kbps for me. It is not spectacular, but the connection is stable enough that I keep it as a backup.

One problem caught me out:

If listen is not specified, the service may listen on IPv6 while the client is connecting over IPv4. The result can look like a successful connection with no internet access. Here is the server configuration change I used:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"inbounds": [
{
"port": 16823,
"protocol": "vmess",
"listen":"12.34.56.78",// Add your server IP here
"settings": {// Leave the settings below unchanged
"clients": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId": 64
}
]
},
"streamSettings": {
"network": "tcp"
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}

v2ray + mkcp

The stable V2Ray setup was useful, but after getting used to UDP acceleration, ordinary TCP felt slow again.

Once I had seen the faster connection, it was hard to settle for the slower one.

Fortunately, V2Ray has a UDP transport of its own. It can be enabled by changing both the server and client configuration files.

The official examples show what those two sides look like:

Server:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
"inbounds": [
{
"port": 16823,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId": 64
}
]
},
"streamSettings": {
"network": "mkcp", // mkcp and kcp are equivalent here
"kcpSettings": {// This kcpSettings section may be omitted
"uplinkCapacity": 5,
"downlinkCapacity": 100,
"congestion": true,
"header": {
"type": "none"
}
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}

Client:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{
"inbounds": [
{
"port": 1080,
"protocol": "socks",
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"settings": {
"auth": "noauth"
}
}
],
"outbounds": [
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "serveraddr.com",
"port": 16823,
"users": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId": 64
}
]
}
]
},
"streamSettings": {
"network": "mkcp",
"kcpSettings": {// This kcpSettings section may be omitted; setting it can cause errors
"uplinkCapacity": 5,
"downlinkCapacity": 100,
"congestion": true,
"header": {
"type": "none"
}
}
}
}
]
}

Do not paste these examples in unchanged. Read the descriptions and adjust the values for your own server and client.

After making the changes, I saw the speed improve.

Unfortunately, that did not solve the blocking problem: during sensitive periods a setup created in the morning could still be gone by afternoon.

v2ray + mkcp + udp2raw

The recurring problem seemed to be the volume and recognizable pattern of UDP traffic. My next experiment was udp2raw, which can disguise UDP as TCP. In my experience, that setup lasted longer.

The project documentation is in Chinese and explains the options.

I found another one-click script for installation:

1
bash <(curl -s -L https://233blog.com/udp2raw.sh)

The local udp2raw client passes traffic to its server counterpart, disguising the UDP traffic between them.

The project’s own documentation explains the options better than I can, so I will leave the detailed usage to that guide.

There are a few practical snags: the local client needs its own running window, closing SSH can stop the server process, and a phone is awkward to use with this arrangement.

I tackled the server process first. nohup did not work for me, so I tried screen instead.

Many Linux systems already include screen. Start a session with screen, then run the server inside it:

1
sudo ./udp2raw_amd64 -s -l 0.0.0.0:4096  -r 127.0.0.1:7777   -k "passwd" --raw-mode faketcp   --cipher-mode xor  -a

Press ctrl+a, followed by d, to detach from the session.

You can then see the session information:

1
2
[detached from 1883.pts-0.vultr]
[root@vultr ~]

To return, use screen -p xxxx, substituting the number shown for your session.

The client side still needs somewhere to run. A virtual machine or a VB script is one option, though neither makes phone access particularly convenient.

My preferred workaround is to run the udp2raw client on a domestic VPS or another domestic machine with a fixed IP.

Point V2Ray at that client machine’s address and the port chosen for udp2raw, leaving the other settings as they were. That makes the setup usable from both a computer and a phone.

Here is the resulting speed while watching YouTube in 4K:

hqu8rWc1JEpyOlK.png

Ultimate approach: V2Ray + WS + TLS + CDN

I have not tried this last combination myself. As I understand it, the idea is to put the VPS behind a domain and make the traffic resemble an HTTPS website. That is four layers in all; if even that gets blocked, I am out of ideas.