大内网战略-tailscale虚拟局域网

前言

Tailscale是基于wireguard的虚拟局域网搭建工具,除开使用官方的服务外,还支持全过程使用自建服务。

此套搭建方式不强制使用HTTPS,支持IP访问,且基于官方原版,不进行额外源码修改

包含HTTPS的部分都可变更为HTTP,关键配置部分有对应说明。

环境

  • Debian以及ubuntu20.04或以上版本
安装本文用到的工具
1
apt install curl wget vim

大体搭建流程

  • 搭建中转服务器derp
  • 搭建协调服务器及协调服务器UI
  • 根据安装对应系统的tailscale客户端
  • 组网成功

协调服务器:配置中心,负责管理设备的登入登出以及下发各类配置。
中转服务器:用于中转流量,提供P2P打洞功能。

大内网的所有服务均不推荐通过docker搭建。

1 自建中转服务器derp

如果是有ipv4的家宽想搭建derp,路由器必须支持nat环回。
否则会导致内网设备无法连接到这个derp

支持nat环回表现为,局域网内可以通过公网IP连接到内网已端口映射设备。

!!!在打开--verify-clients的情况下客户端版本不能低于derp最小支持版本,否则连接会被拒绝!!!

1.1 安装与编译

本节可参考官方文档

安装go编译器

官方推荐使用最新的版本的go进行编译https://golang.org/doc/install,本文使用1.21.4版本的go用于演示。

随着derp的更新,所需的go版本也可能更新,如果出现错误请善用翻译。

1
2
3
4
5
6
7
8
9
10
apt update && apt upgrade
apt install -y wget git openssl curl
wget https://go.dev/dl/go1.21.4.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.4.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
go version
echo "export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> /etc/profile
source /etc/profile
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

编译安装derp

1
go install tailscale.com/cmd/derper@main

会将最新的 DERP 服务器编译安装到$HOME/go/bin.

拷贝执行文件到启动目录下

1
2
mkdir /etc/derp
cp $HOME/go/bin/derper /etc/derp/derper

赋予执行权限

1
chmod +x /etc/derp/derper

配置为系统服务

1
vim /etc/systemd/system/derp.service
1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=TS Derper
After=network.target
Wants=network.target
[Service]
User=root
Restart=always
ExecStart=/etc/derp/derper -a :31446 -stun-port 33478 --verify-clients
RestartPreventExitStatus=1
[Install]
WantedBy=multi-user.target

ecs + :wq 保存

其中31446http服务端口 33478是用于P2P打洞的stunudp服务端口
--verify-clients 会在连接时校验客户端是否已在网络内
使用systemctl <start/stop/restart/status> derpderp进行管理

配置开机自启

1
systemctl enable derp

1.2 derp 启动!

1
systemctl start derp

1.3 通过nginx提供HTTPS

没有域名可以跳过这一步

安装nginx

1
apt install nginx

配置Nginx

配置或路径中的example.com需要换成自己的域名

1
vim /etc/nginx/conf.d/example.com

ecs + :wq 保存

HTTPS配置参考
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
server{
listen 0.0.0.0:443 ssl http2;
#listen [::]:443 ssl http2;
server_name example.com;

ssl_certificate /etc/nginx/ssl/example.com.pem;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;

location / {
proxy_pass http://127.0.0.1:31446;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host derp.test.com;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
}
}

proxy_pass对应derp服务的本机地址,如有调整记得更新。

创建证书文件夹
1
mkdir /etc/nginx/ssl

SSL证书可以自己申请也可以使用acme.shcertbot等工具自动创建

公钥路径 /etc/nginx/ssl/example.com.pem
私钥路径 /etc/nginx/ssl/example.com.key

HTTP配置参考
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
server{
listen 0.0.0.0:80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:31446;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $server_name;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
}
}

proxy_pass对应derp服务的本机地址,如有调整记得更新。
无域名时注释server_name或将server_name指定为固定IP

应用配置变更
1
service nginx force-reload
Nginx报错的解决方案

首次安装nginx基本都会出现,需要配置nginx.conf,用以允许websocket连接。

1
vim /etc/nginx/nginx.conf

http{...}中加入

1
2
3
4
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

ecs + :wq 保存

2 自建协调服务器headscale

2.1 协调服务器headscale搭建

协调服务器的核心,是无界面的后台服务。

通过官方支持的后端 headscale 部署自建协调服务器,这里以0.22.3版本的安装为例

官方仓库地址: https://github.com/juanfont/headscale/releases

1
2
wget --output-document=headscale.deb \
https://github.com/juanfont/headscale/releases/download/v0.22.3/headscale_0.22.3_linux_amd64.deb

这是仓库里的deb包下载链接,下载速度慢的自行百度加速站转换地址后下载。

安装
1
sudo dpkg --install headscale.deb
设置开机自启动
1
sudo systemctl enable headscale
编辑配置
1
nano /etc/headscale/config.yaml

ctrl+x退出,Y/N+回车,保存或放弃修改

酌情调整的配置
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
...
server_url: http[s]://example.com # 客户端连接的服务地址(改成自己的)
...
listen_addr: 127.0.0.1:8080 # 监听的地址,不使用反向代理时请改为0.0.0.0:8080
...
# 使用的IP前缀,如无特殊需求不建议修改(只能在100.64.0.0/10以及fd7a:115c:a1e0::内自定义),IPV4与IPV6调换方向用以优先显示IPV4地址。
ip_prefixes:
- 100.64.0.0/10
- fd7a:115c:a1e0::/48
...
derp:
...
urls:
- https://controlplane.tailscale.com/derpmap/default # 官方中转,不使用可以注释
- https://example.com/d/derp.json # 自定义中转服务器列表,语法与官方derpMap语法基本相同,详见后续的协调服务器UI搭建,这里可以先把域名换成自己的。
...
dns_config:
# Whether to prefer using Headscale provided DNS or use local.
# 优先使用headscale的dns配置还是客户端本地的dns配置
override_local_dns: true

# List of DNS servers to expose to clients.
# DNS服务器列表
nameservers:
- 223.5.5.5 # 阿里云公共DNS
- 8.8.8.8 # 谷歌公共DNS
...
# Whether to use [MagicDNS](https://tailscale.com/kb/1081/magicdns/).
# Only works if there is at least a nameserver defined.
# 魔法dns,启用之后可以通过 主机名.用户名.下方设置的base_domain,进行互访
magic_dns: true

# Defines the base domain to create the hostnames for MagicDNS.
# `base_domain` must be a FQDNs, without the trailing dot.
# The FQDN of the hosts will be
# `hostname.user.base_domain` (e.g., _myhost.myuser.example.com_).
# 魔法DNS的基础域名
base_domain: example.com

你可能会发现headscale有提供内置的derp,但是不建议启用它。

headscale的feat(derp)中对headscale的内置derp验证客户端(--verify-clients)支持仅为未来计划。

--verify-clients用于在连接时校验客户端是否合法组网,所以不启用--verify-clients与在互联网上裸奔无异(

关于dns_config配置的额外说明

extra_records类似hosts可用于指定域名的A记录,目前的支持似乎不太完整,请参考官方文档慎用其他记录类型。

1
2
3
4
5
6
7
extra_records:
- name: "mirrors.cloud.aliyuncs.com"
type: "A"
value: "100.100.2.136"
- name: "localhost"
type: "A"
value: "127.0.0.1"

restricted_nameservers用于指定域名及其子域名通过哪一个DNS进行独立解析

1
2
3
4
5
restricted_nameservers:
chenxuan.local:
- 1.1.1.1
chenxuan.test:
- 4.4.4.4

在上述restricted_nameservers配置下chenxuan.localwww.chenxuan.local会通过1.1.1.1这个DNS服务器来解析域名。

万事俱备 headscale 启动!
1
sudo systemctl start headscale

没有报错就表示正常启动了。

自此完成协调服务器后端搭建。

2.2 协调服务器UI

一个简单的界面能极大的优化使用体验。

这里选用的是,headscale-ui(https://github.com/gurucomputing/headscale-ui)

创建目录

1
2
3
4
# UI目录
mkdir /var/www/tailscale
# derp节点配置目录
mkdir /var/www/tailscale/conf

下载解压UI

1
2
wget https://github.com/gurucomputing/headscale-ui/releases/download/2023.01.30-beta-1/headscale-ui.zip
unzip -d /var/www/tailscale headscale-ui.zip

安装nginx

1
apt install nginx unzip

配置Nginx

如果协调与中继服务部署在同一台服务器上,并且复用域名,或许可以参考issue

配置或路径中的example.com需要换成自己的域名

1
vim /etc/nginx/conf.d/example.com

ecs + :wq 保存

HTTPS配置参考
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
server{
listen 0.0.0.0:443 ssl http2;
#listen [::]:443 ssl http2;
server_name example.com;

ssl_certificate /etc/nginx/ssl/example.com.pem;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;

location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $server_name;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
}

location /web {
index index.html;
alias /var/www/tailscale/web;
}

location /admin {
rewrite ^/(.*) https://example.com/web permanent;
}

location /d {
alias /var/www/tailscale/conf;
autoindex on;
}
}

proxy_pass对应协调服务器本机地址,如有调整记得更新。

创建证书文件夹
1
mkdir /etc/nginx/ssl

SSL证书可以自己申请也可以使用acme.shcertbot等工具自动创建

公钥路径 /etc/nginx/ssl/example.com.pem
私钥路径 /etc/nginx/ssl/example.com.key

HTTP配置参考
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
server{
listen 0.0.0.0:80;
server_name example.com;

location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $server_name;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
}

location /web {
index index.html;
alias /var/www/tailscale/web;
}

location /admin {
rewrite ^/(.*) https://example.com/web permanent;
}

location /d {
alias /var/www/tailscale/conf;
autoindex on;
}
}

proxy_pass对应协调服务器本机地址,如有调整记得更新。
无域名时注释server_name或将server_name指定为固定IP

应用配置变更
1
service nginx force-reload
Nginx报错的解决方案

首次安装nginx基本都会出现,需要配置nginx.conf,用以允许websocket连接。

1
vim /etc/nginx/nginx.conf

http{...}中加入

1
2
3
4
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

ecs + :wq 保存

配置中转服务器列表derp.json

1
vim /var/www/tailscale/conf/derp.json
有域名参考配置

更多配置参考官方文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"Regions": {
"901": {
"RegionID": 901,
"RegionCode": "Server901",
"RegionName": "Server901",
"Nodes": [{
"Name": "901a",
"RegionID": 901,
"STUNPort": 33478,
"DERPPort": 31446,
"HostName": "example.com"
}]
}
}
}

STUNPort stun端口,用于P2P打洞
DERPPort derp的https端口,中转流量等
HostName 域名

无域名参考配置

更多配置参考官方文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"Regions": {
"901": {
"RegionID": 901,
"RegionCode": "Server901",
"RegionName": "Server901",
"Nodes": [{
"Name": "901a",
"RegionID": 901,
"STUNPort": 33478,
"DERPPort": 31446,
"IPv4": "服务器IP",
"InsecureForTests": true,
}]
}
}
}

InsecureForTests用于禁用ssl验证,官方并不推荐启用这一设置,这可能导致中间人攻击。
在没有域名或ssl证书的情况下必须启用该设置

重新加载nginx配置

1
service nginx force-reload

2.3 访问UI页面

通过上述配置,这时应该可以访问到UI界面了。

要想通过UI进行配置,还需要稍稍进行一些配置。

1
http://example.com

headscale密钥获取

1
headscale apikeys create --expiration 30d

创建了一个30天有效期的密钥

此密钥是配置密码,请妥善保管,可以通过headscale apikeys相关命令进行管理。

配置密钥

在ui上配置

1
Settings -> Headscale API Key -> 输入获取的密钥 -> Test Server Settings

之后便可以使用UI来配置Headscale

3 客户端连接自建协调服务器

大部分的安装包可以到此处下载: https://pkgs.tailscale.com/stable/

本节可参考 官方文档

3.1 Window

管理员powershell运行指令

1
2
3
4
New-ItemProperty -Path 'HKLM:\Software\Tailscale IPN' -Name UnattendedMode -PropertyType String -Value always
New-ItemProperty -Path 'HKLM:\Software\Tailscale IPN' -Name LoginURL -PropertyType String -Value https://YOUR-HEADSCALE-URL
New-ItemProperty -Path 'HKCU:\Software\Tailscale IPN' -Name UnattendedMode -PropertyType String -Value always
New-ItemProperty -Path 'HKCU:\Software\Tailscale IPN' -Name LoginURL -PropertyType String -Value https://YOUR-HEADSCALE-URL

https://YOUR-HEADSCALE-URL 对应协调服务器地址

随后可在UI上登录,或者在命令行登录。

如若未生效,请在 任务管理器->服务->tailscale 处右键重启服务

1
tailscale login --login-server https://YOUR-HEADSCALE-URL

server_url 对应协调服务器地址

完整登录流程可以参考Linux小节~

3.2 Linux

安装tailscale

1
curl -fsSL https://tailscale.com/install.sh | sh

启用tailscale并设置协调服务器

1
tailscale up --login-server=协调服务器地址

如果此前已经连接了官方服务,可以使用tailscale logout登出

服务器地址示例:http://example.com、https://example.com、http://ip:8080

执行命令后会响应出一串地址,就像下面这样

1
https://xxxxxx/register/nodekey:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

复制nodekey及后续信息

1
nodekey:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

随后登陆headscale-ui进行配置

在配置Device前需要在User View创建至少一个用户!

1
Device View -> New Device -> Select User -> ✓

添加后稍等片刻linux命令行会显示登录成功

这样就加入了网络

最好给节点改个好记的名字,这样可以通过协调服务器配置的魔法DNS来互访,而不用记IP(

3.3 Docker

不推荐

1
2
3
4
5
6
7
8
9
10
docker pull tailscale/tailscale:latest
docker run -d --name=tailscaled \
--restart=always \
-v /var/lib:/var/lib \
-v /dev/net/tun:/dev/net/tun \
-e TS_STATE_DIR=/var/lib/tailscale \
-e TS_AUTH_ONCE=true \
-e TS_EXTRA_ARGS="--login-server=协调服务器地址" \
--network=host --cap-add=NET_ADMIN --cap-add=NET_RAW \
tailscale/tailscale
查看状态
1
docker exec tailscaled tailscale status

status可以替换为set等其他tailscale支持的客户端指令与参数。

通常启动后会提示进行设备注册,注册后可正常使用。

注册可参考Linux客户端段落

3.4 其它配置

接受路由

用于不同网段间通信,发布了多个子网的可以启用,出口节点不启用可能会无法路由流量。

1
tailscale set --accept-routes=true

解决DNS冲突

由于我部署了一个在tailscale网络内部的dns解析服务,所以有时候会出现DNS冲突。

1
2
3
tailscale set --accept-dns=false
tailscale down
tailscale up

一般用户大抵用不到……

将节点设为出口节点

本节可参考官方文档

在设为出口节点以后,该节点还需要启用IP转发

已经注册的节点设为出口节点
1
sudo tailscale set --advertise-exit-node
启用IP转发

启用 IP 转发时,确保防火墙设置为默认拒绝流量转发。
这是常见防火墙(例如ufwfirewalld)的默认设置,可确保您的设备不会路由您不希望的流量。

如果 Linux 系统有/etc/sysctl.d目录,请使用:

1
2
3
echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf
echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf
sudo sysctl -p /etc/sysctl.d/99-tailscale.conf

否则,使用:

1
2
3
echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p /etc/sysctl.conf

将本地子网添加到路由中

通告子网路由
1
tailscale set --advertise-routes=192.168.0.0/24,192.168.1.0/24

将上例中的子网替换为适合您的网络的子网。支持 IPv4 和 IPv6 子网。

协调服务器启用路由

下述操作可以通过UI完成 Device View -> 点开一个需要启用路由的设备 -> Device Routes -> pending/active(暂停或激活)

检查路由表

1
headscale routes list

启用路由

1
headscale routes enable -r ID

4 正文参考资料

本文与视频有许多不同,注意甄别。

5 一些或许有用的解决方案

5.1 Https兼容性修补

在参考视频的评论区发现--verify-clients可能会因不使用带域名的HTTPS导致不进行客户端校验的情况,故提出此修补方案。

生成自定义ssl证书

1
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout /etc/derp/derp.test.com.key -out /etc/derp/derp.test.com.crt -subj "/CN=derp.test.com" -addext "subjectAltName=DNS:derp.test.com"

调整中继系统服务配置

停止中继服务derp
1
2
systemctl disable derp
systemctl stop derp
修改derp配置
1
vim /etc/systemd/system/derp.service
1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=TS Derper
After=network.target
Wants=network.target
[Service]
User=root
Restart=always
ExecStart=/etc/derp/derper -a :31446 -http-port 31445 -stun-port 33478 -hostname derp.test.com -certmode manual -certdir /etc/derp --verify-clients
RestartPreventExitStatus=1
[Install]
WantedBy=multi-user.target

-a :31446用于指定HTTPS端口
虽然用不到http服务,但是需要占用一个端口,默认占用80,所以需要设置http-port防止占用失败的启动报错。

启动derp
1
2
systemctl enable derp
systemctl start derp
修改nginx配置

proxy_passhttp修改为https,并添加proxy_ssl_verify off;用于忽略derpssl证书。

修改proxy_set_header的值为derp.test.com

1
2
3
4
5
6
7
8
9
server{
..
location / {
proxy_pass https://127.0.0.1:31446;
proxy_ssl_verify off;
proxy_set_header Host derp.test.com;
...
}
}

proxy_set_header用于伪装域名,其值与生成证书时指定的域名有关

重新加载nginx配置
1
service nginx force-reload

5.2 通过acme.sh自动获取SSL证书

这里使用阿里云dns为示例,其他服务器商请善用搜索引擎。

大抵区别只是创建AccessKey与配置密钥这两步

创建AccessKey

首先在阿里云 AccessKey管理 页面创建AccessKey

安装acme.sh

1
curl  https://get.acme.sh | sh

配置密钥

1
2
export Ali_Key="你的key"
export Ali_Secret="你的secret"

安装证书

其中example.com的部分需要替换为自己的域名,需要为每个域名各运行一次。

1
2
3
4
5

~/.acme.sh/acme.sh --issue --dns dns_ali -d example.com \
--key-file /etc/nginx/ssl/example.com.key \
--fullchain-file /etc/nginx/ssl/example.com.pem \
--reloadcmd "service nginx force-reload"

生成ssl并安装到nginx(会自动续签)

5.3 关于阿里云服务器部署可能出现的问题以及解决方案

问题简述

Tailscale使用的网段100.64.0.0/10(100.64.0.1-100.127.255.254)

该网段为运营商级NAT(Carrier Grade NAT, CGNAT),与阿里云使用的网段冲突只是其一。

关键在于Tailscale为了解决安全问题,在防火墙网络规则里加入了丢弃该网段网络数据的规则。

导致使用该网段通信的阿里云应用无法连接,其中包括DNS解析、APT包下载以及云助手等功能

服务器默认DNS无法连接进一步导致依赖域名解析的服务无法运行

解决方案零,最推荐的方案

摆烂方案,修改DNS为其它可信DNS。并给包管理器换源。

代价是无法使用一些阿里云的功能。

解决方案一

此方案存在安全隐患,不推荐使用

在启动tailscale时加入--netfilter-mod=off

该设置会取消设置丢弃100.64.0.0/10网段的防火墙规则

解决方案二

该方案在重新启动tailscale后失效。
原因是 tailscale 会在启动时添加一个高优先级的iptables规则,先一步把包丢弃了。

headscaledns_config下添加:

需要参考阿里云文档 配置云助手Agent网络权限 获取需要允许的部分IP数据,示例中添加的是阿里云广州的权限。

1
2
3
4
5
6
7
8
9
10
extra_records:
- name: "mirrors.cloud.aliyuncs.com"
type: "A"
value: "100.100.2.136"
- name: "cn-guangzhou.axt.aliyun.com"
type: "A"
value: "100.100.0.4"
- name: "aliyun-client-assist-cn-guangzhou.oss-cn-guangzhou-internal.aliyuncs.com"
type: "A"
value: "100.115.33.49"
1
2
3
4
# 查看当前DNS地址
resolvectl status
# 查看当前软件包下载地址
nslookup mirrors.cloud.aliyuncs.com

通过防火墙规则允许该网段内关键阿里云服务的连接。

1
2
3
4
5
6
7
# 创建规则
sudo iptables -N ts-input-whitelist
# 添加允许的ip(软件包、云助手连接、云助手更新)
sudo iptables -I ts-input-whitelist -s 100.100.2.136 -j ACCEPT
sudo iptables -I ts-input-whitelist -s 100.100.0.4 -j ACCEPT
sudo iptables -I ts-input-whitelist -s 100.115.33.49 -j ACCEPT
iptables -I INPUT -j ts-input-whitelist

需通过iptables -L INPUT确认ts-input-whitelist处于ts-input前方
否则会优先处理ts-input的丢弃操作
每次tailscale的重新启动都可能导致优先级发生变化

解决方案三

[[tailscale 解决阿里云服务器受影响的问题]]

本节参考

6 关于ACL

headscale支持通过acl控制网络访问。

在默认情况下任何用户都可以访问任意连入网络的设备

同时与tailscale不同的是,在打上标签之后用户不会被置空,但用户规则依然部分有效(允许ping)。

后续可能会出一篇新的文章探讨ACL的配置。