Skip to content

Internet Setup Example

hexian000 edited this page Jun 29, 2023 · 8 revisions

1. Setup SQM (server-side)

git clone https://github.com/tohojo/sqm-scripts
cd sqm-scripts
sudo make install
# check nic name
ip a
# assuming the name is "eth0"
sudo cp /etc/sqm/default.conf /etc/sqm/eth0.iface.conf
sudo nano /etc/sqm/eth0.iface.conf
# assuming 50 Mbps uplink
# UPLINK=50000
# DOWNLINK=0

# assuming systemd
sudo systemctl enable sqm@eth0
sudo systemctl start sqm@eth0

# check status
sudo systemctl status sqm@eth0

2. Generate preshared key

./kcptun-libev --genpsk xchacha20poly1305_ietf

Copy the key.

3. Write server config

{
    "kcp_bind": ":10080",
    "connect": "127.0.0.1:1080",
    "http_listen": "127.0.1.1:8081",
    "kcp": {
        "mtu": 1400,
        "sndwnd": 1024,
        "rcvwnd": 1024,
        "nodelay": 2,
        "interval": 50,
        "resend": 0,
        "nc": 1
    },
    "udp": {
        "sndbuf": 1048576,
        "rcvbuf": 1048576
    },
    "method": "xchacha20poly1305_ietf",
    "psk": "// paste the key",
    "loglevel": 3,
    "obfs": "dpi/tcp-wnd",
    "user": "nobody"
}

4. Write client config

{
    "listen": ":1080",
    "kcp_connect": "203.0.113.1:10080",
    "kcp": {
        "mtu": 1400,
        "sndwnd": 1024,
        "rcvwnd": 1024,
        "nodelay": 2,
        "interval": 50,
        "resend": 0,
        "nc": 1
    },
    "udp": {
        "sndbuf": 1048576,
        "rcvbuf": 1048576
    },
    "method": "xchacha20poly1305_ietf",
    "psk": "// paste the key",
    "loglevel": 3,
    "obfs": "dpi/tcp-wnd",
    "user": "nobody"
}

5. Calculate the window size

# server side
sudo ./kcptun-libev -c server.json
# client side
sudo ./kcptun-libev -c client.json -v -v
# wait up to 1 minute to read the RTT value in logs
rx bandwidth = kcp.rcvwnd * kcp.mtu / RTT
tx bandwidth = kcp.sndwnd * kcp.mtu / RTT

For example:

kcp.*wnd := 1024 packets
kcp.mtu := 1400 bytes
RTT = 170 ms
max bandwidth ~= 8.0 MiB/s

Hint: Smaller bandwidth usually results in more stable service latency.

6. Start the service

# server side
sudo ./kcptun-libev -c server.json
# client side
sudo ./kcptun-libev -c client.json