我想创建一个 OpenConnect VPN 服务器。我遵循这教程一步一步然而,虽然我能够使用客户端连接到开放连接服务器,但问题是我无法访问互联网(在客户端)连接到服务器后。
我认为这应该是 IP 转发问题。这是我设置 ipforwarding 所采取的步骤:
- 使用以下三个命令启用 IP 转发:
echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/60-custom.conf
echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.d/60-custom.conf
echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.d/60-custom.conf
- 最后
sudo sysctl -p /etc/sysctl.d/60-custom.conf
- 配置 ufw规则之前并添加了以下内容:
# NAT table rules *nat :POSTROUTING ACCEPT [0:0] -A POSTROUTING -s 10.10.10.0/24 -o eth0 -j MASQUERADE # End each table with the 'COMMIT' line or these rules won't be processed COMMIT # allow forwarding for trusted network -A ufw-before-forward -s 10.10.10.0/24 -j ACCEPT -A ufw-before-forward -d 10.10.10.0/24 -j ACCEPT
- 最后我重新启动并启用了 ufw。
但是,当我输入时,sudo iptables -t nat -L POSTROUTING
并没有显示如下内容:
它向我展示了这一点:
我不知道为什么要.ap-northeast-2.compute.internal
在 ips 末尾添加这些。可能是因为这个吗?
请注意,我使用的是 AWS vps(我也检查了 lightsail 防火墙)、Ubuntu 20 操作系统和最新版本的 ocserv。我还通过 VPN 转发所有流量,包括 DNS。ocserv
配置如下:
auth = "plain[passwd=/etc/ocserv/ocpasswd]"
tcp-port = 443
## Comands for SSL/TLS certifications
try-mtu-discovery = true
cert-user-oid = 0.9.2342.19200300.100.1.1
compression = true
default-domain = sub.mydomain.xyz
ipv4-network = 10.10.10.0
ipv4-netmask = 255.255.255.0
ipv6-subnet-prefix = 64
tunnel-all-dns = true
dns = 8.8.8.8
dns = 1.1.1.1
#route = 10.0.0.0/8
#route = 172.16.0.0/12
#route = 192.168.0.0/16
#route = fd00::/8
#route = default
以下是从客户端到我的服务器的 tracert 的结果。
Tracing route to sub.mydomain.xyz [x.x.x.x]
over a maximum of 30 hops:
1 1 ms 1 ms <1 ms 192.168.1.1
2 43 ms 42 ms 43 ms 100.101.0.1
3 44 ms 42 ms 42 ms 172.19.16.65
4 43 ms 44 ms * 172.19.17.73
5 46 ms 44 ms * 172.19.17.41
6 47 ms 45 ms 44 ms 10.202.6.192
7 48 ms 45 ms 44 ms 10.21.212.10
8 118 ms 116 ms 115 ms 85.132.90.169
9 * * * Request timed out.
10 130 ms 166 ms 140 ms 188.43.209.206
11 * * * Request timed out.
12 * * * Request timed out.
13 * * * Request timed out.
14 * * * Request timed out.
15 * * * Request timed out.
16 267 ms 273 ms 267 ms 101.203.89.179
17 * * * Request timed out.
18 * * * Request timed out.
19 291 ms 363 ms 357 ms 54.239.52.99
20 * * * Request timed out.
21 * * * Request timed out.
22 298 ms 294 ms 294 ms 54.239.122.82
23 296 ms 297 ms 301 ms 52.93.248.146
24 297 ms 326 ms 362 ms 52.93.248.149
25 303 ms 296 ms 316 ms 54.239.122.109
26 304 ms 310 ms 390 ms 54.239.122.4
27 * * * Request timed out.
28 * * * Request timed out.
29 * * * Request timed out.
30 * * * Request timed out.