Skip to content
Vincent's Notes
Go back

SAKURA VPS International QoS Issues

by Vincent Yang

日本的 SAKURA Internet Inc. (AS9370) 即使在近些年大不如前,但仍然因为其 IP 质量(接近日本家庭宽带),再加上无限流量,备受玩家喜爱。当然这家的机子也并不好买,需要日本的真实地址,以及日本的手机号。

主播在大概半年之前注册了一个 SAKURA 和 WebARENA Indigo 帐号,一直在使用 SAKURA VPS,一直存在的问题就是从中国到日本根本跑不满限速的 100Mbps。因为存在国际 QoS 的问题。

如何解决国际 QoS 问题

这个方案也一样适用于 Indigo。简单来说,就是用一台主流的商宽 VPS (比如 GreenCloudVPS) 和 SAKURA 建立 GRE 隧道,然后将国际入站的流量先到 GreenCloudVPS,再从 GreenCloudVPS 的 GRE Tunnel 到 SAKURA,这样就能绕过 SAKURA 的国际 QoS 了。

玩 GRE Tunnel 的前提是你的云服务商没有禁用 Protocol 47。

在两个服务器上加载 GRE module:

sudo modprobe ip_gre
echo "ip_gre" | sudo tee -a /etc/modules

例如服务器 A 公网 IP:23.191.8.1,服务器 B 公网 IP:23.191.8.2。内网地址:10.0.0.110.0.0.2

接下来在服务器 A 上添加一个 GRE 接口:

nano /etc/network/interfaces
auto tun-gre
iface tun-gre inet static
    address 10.0.0.1
    netmask 255.255.255.252
    pre-up ip tunnel add tun-gre mode gre remote 23.191.8.2 local 23.191.8.1 ttl 255
    post-up ip link set dev tun-gre mtu 1450
    post-down ip tunnel del tun-gre

在服务器 B 上同样添加 GRE 接口:

nano /etc/network/interfaces
auto tun-gre
iface tun-gre inet static
    address 10.0.0.2
    netmask 255.255.255.252
    pre-up ip tunnel add tun-gre mode gre remote 23.191.8.1 local 23.191.8.2 ttl 255
    post-up ip link set dev tun-gre mtu 1450
    post-down ip tunnel del tun-gre

测试 GRE Tunnel 是否成功:

在服务器 A 上:

ping 10.0.0.2

像我这样就是成功了,而且两个服务器之间有着非常优秀的网络质量。

ping 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=1.79 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=1.80 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=1.89 ms
64 bytes from 10.0.0.2: icmp_seq=4 ttl=64 time=1.83 ms
64 bytes from 10.0.0.2: icmp_seq=5 ttl=64 time=1.77 ms
64 bytes from 10.0.0.2: icmp_seq=6 ttl=64 time=1.88 ms
64 bytes from 10.0.0.2: icmp_seq=7 ttl=64 time=1.68 ms
64 bytes from 10.0.0.2: icmp_seq=8 ttl=64 time=1.87 ms
64 bytes from 10.0.0.2: icmp_seq=9 ttl=64 time=1.81 ms
64 bytes from 10.0.0.2: icmp_seq=10 ttl=64 time=1.92 ms
64 bytes from 10.0.0.2: icmp_seq=11 ttl=64 time=1.71 ms
64 bytes from 10.0.0.2: icmp_seq=12 ttl=64 time=1.77 ms
64 bytes from 10.0.0.2: icmp_seq=13 ttl=64 time=1.99 ms
64 bytes from 10.0.0.2: icmp_seq=14 ttl=64 time=1.71 ms
^C
--- 10.0.0.2 ping statistics ---
14 packets transmitted, 14 received, 0% packet loss, time 13021ms
rtt min/avg/max/mdev = 1.680/1.814/1.987/0.083 ms

最后只要配置 nftables 将流量从服务器 A 的 GRE Tunnel 转发到服务器 B 的 GRE Tunnel 即可。

nano /etc/nftables.conf
#!/usr/sbin/nft -f

flush ruleset

table ip my_proxy_forward {
    # 处理入站 DNAT
    chain prerouting {
        type nat hook prerouting priority dstnat; policy accept;

        # 将发往 A:32767 的流量转发到 B 的隧道地址 10.0.0.2
        tcp dport 32767 dnat to 10.0.0.2
        udp dport 32767 dnat to 10.0.0.2
        # 将发往 A:26002 的流量转发到 B 的隧道地址 10.0.0.2
        tcp dport 26002 dnat to 10.0.0.2
        udp dport 26002 dnat to 10.0.0.2
    }

    # 处理出站 SNAT (Masquerade)
    chain postrouting {
        type nat hook postrouting priority srcnat; policy accept;

        # 确保回程流量通过隧道:
        # 当流量发往 B 的隧道 IP 时,将源地址改为 A 的隧道 IP (10.0.0.1)
        ip daddr 10.0.0.2 oifname "tun-gre" masquerade
    }
}

最后启动 nftables 即可

sudo nft -f /etc/nftables.conf

Share this post:

Previous Post
JR East Japan Billing Issue
Next Post
Block Inbound Traffic from Mainland China

Comments 0

Finished reading? Why not leave a word.