当前位置: 首页>后端>正文

Tailscale 基础教程:Headscale 的部署方法和使用教程

Tailscale 鏄竴绉嶅熀浜?WireGuard 鐨勮櫄鎷熺粍缃戝伐鍏凤紝瀹冨湪鐢ㄦ埛鎬佸疄鐜颁簡 WireGuard 鍗忚锛岀浉姣斾簬鍐呮牳鎬?WireGuard 鎬ц兘浼氭湁鎵€鎹熷け锛屼絾鍦ㄥ姛鑳藉拰鏄撶敤鎬т笂涓嬩簡寰堝ぇ鍔熷か锛?/p>

  • 寮€绠卞嵆鐢?
    • 鏃犻渶閰嶇疆闃茬伀澧?/li>
    • 娌℃湁棰濆鐨勯厤缃?/li>
  • 楂樺畨鍏ㄦ€?绉佸瘑鎬?
    • 鑷姩瀵嗛挜杞崲
    • 鐐瑰鐐硅繛鎺?/li>
    • 鏀寔鐢ㄦ埛瀹℃煡绔埌绔殑璁块棶璁板綍
  • 鍦ㄥ師鏈夌殑 ICE銆丼TUN 绛?UDP 鍗忚澶栵紝瀹炵幇浜?DERP TCP 鍗忚鏉ュ疄鐜?NAT 绌块€?/li>
  • 鍩轰簬鍏綉鐨勬帶鍒舵湇鍔″櫒涓嬪彂 ACL 鍜岄厤缃紝瀹炵幇鑺傜偣鍔ㄦ€佹洿鏂?/li>
  • 閫氳繃绗笁鏂癸紙濡?Google锛?SSO 鏈嶅姟鐢熸垚鐢ㄦ埛鍜岀閽ワ紝瀹炵幇韬唤璁よ瘉

绠€鑰岃█涔嬶紝鎴戜滑鍙互灏?Tailscale 鐪嬫垚鏄洿涓烘槗鐢ㄣ€佸姛鑳芥洿瀹屽杽鐨?WireGuard銆?/p>

Tailscale 基础教程:Headscale 的部署方法和使用教程,第1张

鍏夋湁杩欎簺杩樹笉澶燂紝浣滀负涓€涓櫧瀚栧厷锛屽挶鏇村叧蹇冪殑鏄?strong>鍏嶈垂涓?strong>寮€婧?/strong>銆?/p>

Tailscale 鏄竴娆惧晢涓氫骇鍝侊紝浣嗕釜浜虹敤鎴锋槸鍙互鐧藉珫鐨勶紝涓汉鐢ㄦ埛鍦ㄦ帴鍏ヨ澶囦笉瓒呰繃 20 鍙扮殑鎯呭喌涓嬫槸鍙互鍏嶈垂浣跨敤鐨勶紙铏界劧鏈変竴浜涢檺鍒讹紝姣斿瀛愮綉缃戞鏃犳硶鑷畾涔夛紝涓旀棤娉曡缃涓瓙缃戯級銆傞櫎 Windows 鍜?macOS 鐨勫浘褰㈠簲鐢ㄧ▼搴忓锛屽叾浠?Tailscale 瀹㈡埛绔殑缁勪欢锛堝寘鍚?Android 瀹㈡埛绔級鏄湪 BSD 璁稿彲涓嬩互寮€婧愰」鐩殑褰㈠紡寮€鍙戠殑锛屼綘鍙互鍦ㄤ粬浠殑 GitHub 浠撳簱鎵惧埌鍚勪釜鎿嶄綔绯荤粺鐨勫鎴风婧愮爜銆?/p>

瀵逛簬澶ч儴浠界敤鎴锋潵璇达紝鐧藉珫 Tailscale 宸茬粡瓒冲浜嗭紝濡傛灉浣犳湁鏇撮珮鐨勯渶姹傦紝姣斿鑷畾涔夌綉娈碉紝鍙互閫夋嫨浠樿垂銆?/p>

鍘熸枃閾炬帴锛歨ttps://icloudnative.io/posts/how-to-set-up-or-migrate-headscale/

鎴戝氨涓嶆兂浠樿垂琛屼笉琛岋紵琛岋紝涓嶈繃寰楀線涓嬬湅銆?/strong>

Headscale 鏄粈涔?/h2>

Tailscale 鐨勬帶鍒舵湇鍔″櫒鏄笉寮€婧愮殑锛岃€屼笖瀵瑰厤璐圭敤鎴锋湁璇稿闄愬埗锛岃繖鏄汉瀹剁殑鎽囬挶鏍戯紝鍙互鐞嗚В銆傚ソ鍦ㄧ洰鍓嶆湁涓€娆惧紑婧愮殑瀹炵幇鍙?Headscale锛岃繖涔熸槸鍞竴鐨勪竴娆撅紝甯屾湜鑳藉彂灞曞.澶с€?/p>

Headscale 鐢辨娲茶埅澶╁眬鐨?Juan Font 浣跨敤 Go 璇█寮€鍙戯紝鍦?BSD 璁稿彲涓嬪彂甯冿紝瀹炵幇浜?Tailscale 鎺у埗鏈嶅姟鍣ㄧ殑鎵€鏈変富瑕佸姛鑳斤紝鍙互閮ㄧ讲鍦ㄤ紒涓氬唴閮紝娌℃湁浠讳綍璁惧鏁伴噺鐨勯檺鍒讹紝涓旀墍鏈夌殑缃戠粶娴侀噺閮界敱鑷繁鎺у埗銆?/p>

Headscale 閮ㄧ讲

浣跨敤 Sealos 涓€閿儴缃?/h3>

濡傛灉浣犲珜涓嬮潰澶暱涓嶇湅锛屽彲浠ラ€夋嫨鐩存帴浣跨敤 Sealos 搴旂敤妯℃澘涓€閿儴缃诧紝鏈夋墜灏辫锛屽暐閮戒笉闇€瑕佽缃€?/p>

鐩存帴澶嶅埗涓嬮潰鐨勯摼鎺ョ矘璐村埌娴忚鍣ㄦ墦寮€ Sealos 鐨勫簲鐢ㄦā鏉块儴缃茬晫闈細

  • https://template.cloud.sealos.io/deploy?templateName=headscale

濡傛灉鎮ㄦ槸绗竴娆℃墦寮€ Sealos锛岄渶瑕佸厛娉ㄥ唽鐧诲綍璐﹀彿銆?/p>

鐒跺悗鐐瑰嚮銆岄儴缃插簲鐢ㄣ€嶆寜閽紑濮嬮儴缃层€傞儴缃插畬鎴愬悗锛屼綘浼氱湅鍒颁袱涓簲鐢紝涓€涓槸 Headscale锛屽彟涓€涓垯鏄?Headscale 鍙鍖栫晫闈€?/p>

Tailscale 基础教程:Headscale 的部署方法和使用教程,第2张

鐐瑰嚮 Headscale 搴旂敤鐨勩€岃鎯呫€嶈繘鍏ヨ鎯呴〉闈€傚唴缃戠鍙?8080 瀵瑰簲鐨勫缃戝湴鍧€灏辨槸 Headscale 鐨勫叕缃戝煙鍚嶃€?/p>

Tailscale 基础教程:Headscale 的部署方法和使用教程,第3张

Headscale 鍏綉鍩熷悕鍚庨潰璺熶笂璺緞 /admin/ 鍗冲彲鎵撳紑鍙鍖栫晫闈€?/p>

Tailscale 基础教程:Headscale 的部署方法和使用教程,第4张

鍦?Linux 涓婇儴缃?/h3>

鍦?Linux 涓婄殑閮ㄧ讲姝ラ灏辩◢寰鏉傜偣浜?/p>

鐞嗚涓婃潵璇村彧瑕佷綘鐨?Headscale 鏈嶅姟鍙互鏆撮湶鍒板叕缃戝嚭鍙e氨琛岋紝浣嗘渶濂戒笉瑕佹湁 NAT锛屾墍浠ユ帹鑽愬皢 Headscale 閮ㄧ讲鍦ㄦ湁鍏綉 IP 鐨勪簯涓绘満涓娿€?/p>

棣栧厛闇€瑕佸埌鍏?GitHub 浠撳簱鐨?Release 椤甸潰涓嬭浇鏈€鏂扮増鐨勪簩杩涘埗鏂囦欢銆?/p>

$ wget --output-document=/usr/local/bin/headscale \
   https://github.com/juanfont/headscale/releases/download/v<HEADSCALE VERSION>/headscale_<HEADSCALE VERSION>_linux_<ARCH>

$ chmod +x /usr/local/bin/headscale

鍒涘缓閰嶇疆鐩綍锛?/p>

$ mkdir -p /etc/headscale

鍒涘缓鐩綍鐢ㄦ潵瀛樺偍鏁版嵁涓庤瘉涔︼細

$ mkdir -p /var/lib/headscale

鍒涘缓绌虹殑 SQLite 鏁版嵁搴撴枃浠讹細

$ touch /var/lib/headscale/db.sqlite

鍒涘缓 Headscale 閰嶇疆鏂囦欢锛?/p>

$ wget https://github.com/juanfont/headscale/raw/main/config-example.yaml -O /etc/headscale/config.yaml
  • 淇敼閰嶇疆鏂囦欢锛屽皢 server_url 鏀逛负鍏綉 IP 鎴栧煙鍚嶃€?strong>濡傛灉鏄浗鍐呮湇鍔″櫒锛屽煙鍚嶅繀椤昏澶囨銆傛垜鐨勫煙鍚嶆棤娉曞妗堬紝鎵€浠ユ垜灏辩洿鎺ョ敤鍏綉 IP 浜嗐€?/li>
  • 濡傛灉鏆傛椂鐢ㄤ笉鍒?DNS 鍔熻兘锛屽彲浠ュ厛灏?magic_dns 璁句负 false銆?/li>
  • server_url 璁剧疆涓?http://<PUBLIC_ENDPOINT>:8080锛屽皢 <PUBLIC_ENDPOINT> 鏇挎崲涓哄叕缃?IP 鎴栬€呭煙鍚嶃€?/li>
  • 寤鸿鎵撳紑闅忔満绔彛锛屽皢 randomize_client_port 璁句负 true銆?/li>
  • 鍙嚜瀹氫箟绉佹湁缃戞锛屼篃鍙悓鏃跺紑鍚?IPv4 鍜?IPv6锛?
    ip_prefixes:
      # - fd7a:115c:a1e0::/48
      - 100.64.0.0/16
    

鍒涘缓 SystemD service 閰嶇疆鏂囦欢锛?/p>

# /etc/systemd/system/headscale.service
[Unit]
Description=headscale controller
After=syslog.target
After=network.target

[Service]
Type=simple
User=headscale
Group=headscale
ExecStart=/usr/local/bin/headscale serve
Restart=always
RestartSec=5

# Optional security enhancements
NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=strict
ProtectHome=yes
ReadWritePaths=/var/lib/headscale /var/run/headscale
AmbientCapabilities=CAP_NET_BIND_SERVICE
RuntimeDirectory=headscale

[Install]
WantedBy=multi-user.target

鍒涘缓 headscale 鐢ㄦ埛锛?/p>

$ useradd headscale -d /home/headscale -m

淇敼 /var/lib/headscale 鐩綍鐨?owner锛?/p>

$ chown -R headscale:headscale /var/lib/headscale

淇敼閰嶇疆鏂囦欢涓殑 unix_socket锛?/p>

unix_socket: /var/run/headscale/headscale.sock

Reload SystemD 浠ュ姞杞芥柊鐨勯厤缃枃浠讹細

$ systemctl daemon-reload

鍚姩 Headscale 鏈嶅姟骞惰缃紑鏈鸿嚜鍚細

$ systemctl enable --now headscale

鏌ョ湅杩愯鐘舵€侊細

$ systemctl status headscale

鏌ョ湅鍗犵敤绔彛锛?/p>

$ ss -tulnp|grep headscale

tcp LISTEN 0 1024 [::]:9090 [::]:* users:(("headscale",pi

d=10899,fd=13))

tcp LISTEN 0 1024 [::]:50443 [::]:* users:(("headscale",pi

d=10899,fd=10))

tcp LISTEN 0 1024 [::]:8080 [::]:* users:(("headscale",pi

d=10899,fd=12))

鍒涘缓鐢ㄦ埛

鍛戒护琛?/h3>

Tailscale 涓湁涓€涓蹇靛彨 tailnet锛屼綘鍙互鐞嗚В鎴愮鎴凤紝绉熸埛涓庣鎴蜂箣闂存槸鐩镐簰闅旂鐨勶紝鍏蜂綋鐪嬪弬鑰?Tailscale 鐨勫畼鏂规枃妗o細What is a tailnet銆侶eadscale 涔熸湁绫讳技鐨勫疄鐜板彨 user锛屽嵆鐢ㄦ埛銆傛垜浠渶瑕佸厛鍒涘缓涓€涓?user锛屼互渚垮悗缁鎴风鎺ュ叆锛屼緥濡傦細

$ headscale user create default

鏌ョ湅鍛藉悕绌洪棿锛?/p>

$ headscale user list

ID | Name | Created

1 | default | 2022-03-09 06:12:06

濡傛灉浣犳槸閫氳繃 Sealos 涓€閿儴缃茬殑 Headscale锛屽彲浠ュ湪 Headscale 搴旂敤鐨勮鎯呴〉闈㈢偣鍑诲彸渚х殑銆岀粓绔€嶆寜閽繘鍏?Headscale 瀹瑰櫒鐨勭粓绔細

Tailscale 基础教程:Headscale 的部署方法和使用教程,第5张

鐒跺悗鍦ㄧ粓绔腑鎵ц涓婅堪鍛戒护鍒涘缓 user銆?/p>

鍙鍖栫晫闈?/h3>

Headscale-Admin 闇€瑕侀€氳繃 API Key 鏉ユ帴鍏?Headscale锛屾墍浠ュ湪浣跨敤涔嬪墠鎴戜滑闇€瑕佸厛鍒涘缓涓€涓?API key銆傚湪 Headscale 搴旂敤鐨勮鎯呴〉闈㈢偣鍑诲彸渚х殑銆岀粓绔€嶆寜閽繘鍏?Headscale 瀹瑰櫒鐨勭粓绔細

Tailscale 基础教程:Headscale 的部署方法和使用教程,第5张

鐒跺悗鎵ц浠ヤ笅鍛戒护鍒涘缓 API Key锛?/p>

$ headscale apikey create

灏?Headscale 鍏綉鍩熷悕鍜?API Key 濉叆 Headscale-Admin 鐨勮缃〉闈紝鍚屾椂鍙栨秷鍕鹃€?Legacy API锛岀劧鍚庣偣鍑汇€孲ave銆嶏細

Tailscale 基础教程:Headscale 的部署方法和使用教程,第7张

鎺ュ叆鎴愬姛鍚庯紝鐐瑰嚮宸﹁竟渚ф爮鐨勩€孶sers銆嶏紝鐒跺悗鐐瑰嚮銆孋reate銆嶅紑濮嬪垱寤虹敤鎴凤細

Tailscale 基础教程:Headscale 的部署方法和使用教程,第8张

Tailscale 瀹㈡埛绔帴鍏?/h2>

鐩墠闄や簡 iOS 瀹㈡埛绔紝鍏朵粬骞冲彴鐨勫鎴风閮芥湁鍔炴硶鑷畾涔?Tailscale 鐨勬帶鍒舵湇鍔″櫒銆?/p>

OS 鏄惁鏀寔 Headscale
Linux Yes
OpenBSD Yes
FreeBSD Yes
macOS Yes
Windows Yes 鍙傝€?Windows 瀹㈡埛绔枃妗?
Android Yes
iOS Yes

鎴戜滑鍏堟潵鐪嬩笅 Linux 骞冲彴鐨勬帴鍏ャ€?/p>

Linux

Tailscale 瀹樻柟鎻愪緵浜嗗悇绉?Linux 鍙戣鐗堢殑杞欢鍖咃紝浣嗗浗鍐呯殑缃戠粶浣犳噦寰楋紝杞欢婧愭牴鏈敤涓嶄簡銆傚ソ鍦ㄥ畼鏂硅繕鎻愪緵浜嗛潤鎬佺紪璇戠殑浜岃繘鍒舵枃浠讹紝鎴戜滑鍙互鐩存帴涓嬭浇銆備緥濡傦細

$ wget https://pkgs.tailscale.com/stable/tailscale_1.22.2_amd64.tgz

瑙e帇锛?/p>

$ tar zxvf tailscale_1.22.2_amd64.tgz
x tailscale_1.22.2_amd64/
x tailscale_1.22.2_amd64/tailscale
x tailscale_1.22.2_amd64/tailscaled
x tailscale_1.22.2_amd64/systemd/
x tailscale_1.22.2_amd64/systemd/tailscaled.defaults
x tailscale_1.22.2_amd64/systemd/tailscaled.service

灏嗕簩杩涘埗鏂囦欢澶嶅埗鍒板畼鏂硅蒋浠跺寘榛樿鐨勮矾寰勪笅锛?/p>

$ cp tailscale_1.22.2_amd64/tailscaled /usr/sbin/tailscaled
$ cp tailscale_1.22.2_amd64/tailscale /usr/bin/tailscale

灏?systemD service 閰嶇疆鏂囦欢澶嶅埗鍒扮郴缁熻矾寰勪笅锛?/p>

$ cp tailscale_1.22.2_amd64/systemd/tailscaled.service /lib/systemd/system/tailscaled.service

灏嗙幆澧冨彉閲忛厤缃枃浠跺鍒跺埌绯荤粺璺緞涓嬶細

$ cp tailscale_1.22.2_amd64/systemd/tailscaled.defaults /etc/default/tailscaled

鍚姩 tailscaled.service 骞惰缃紑鏈鸿嚜鍚細

$ systemctl enable --now tailscaled

鏌ョ湅鏈嶅姟鐘舵€侊細

$ systemctl status tailscaled

Tailscale 鎺ュ叆 Headscale锛?/p>

# 濡傛灉浣犳槸鍦ㄨ嚜宸辩殑鏈嶅姟鍣ㄤ笂閮ㄧ讲鐨勶紝璇峰皢 <HEADSCALE_PUB_ENDPOINT> 鎹㈡垚浣犵殑 Headscale 鍏綉 IP 鎴栧煙鍚?
$ tailscale up --login-server=http://<HEADSCALE_PUB_ENDPOINT>:8080 --accept-routes=true --accept-dns=false

# 濡傛灉浣犳槸浣跨敤 Sealos 涓€閿儴缃茬殑锛岃灏?<HEADSCALE_PUB_ENDPOINT> 鎹㈡垚涓婃枃鎻愬埌鐨?Sealos 涓殑 Headscale 鍏綉鍩熷悕
$ tailscale up --login-server=https://<HEADSCALE_PUB_ENDPOINT> --accept-routes=true --accept-dns=false

浣犱篃鍙互鍦?Headsca-Admin 鐨?Deploy 鐣岄潰鑾峰彇鎺ュ叆鍛戒护锛?/p>

Tailscale 基础教程:Headscale 的部署方法和使用教程,第9张

杩欓噷鎺ㄨ崘灏?DNS 鍔熻兘鍏抽棴锛屽洜涓哄畠浼氳鐩栫郴缁熺殑榛樿 DNS銆傚鏋滀綘瀵?DNS 鏈夐渶姹傦紝鍙嚜宸辩爺绌跺畼鏂规枃妗o紝杩欓噷涓嶅啀璧樿堪銆?/p>

鎵ц瀹屼笂闈㈢殑鍛戒护鍚庯紝浼氬嚭鐜颁笅闈㈢殑淇℃伅锛?/p>

To authenticate, visit:

    https://qgemohpy.cloud.sealos.io/register/mkey:e13651ddbfc269513723f1afd6f42465e56922b67ecea8f37d61a35b1b357e0c

鍦ㄦ祻瑙堝櫒涓墦寮€璇ラ摼鎺ワ紝灏变細鍑虹幇濡備笅鐨勭晫闈細

Tailscale 基础教程:Headscale 的部署方法和使用教程,第10张

灏嗗叾涓殑鍛戒护澶嶅埗绮樿创鍒?headscale 鎵€鍦ㄦ満鍣ㄧ殑缁堢涓紝骞跺皢 USERNAME 鏇挎崲涓哄墠闈㈡墍鍒涘缓鐨?user銆?/p>

$ headscale nodes register --user default --key 905cf165204800247fbd33989dbc22be95c987286c45aac3033937041150d846
Machine register

娉ㄥ唽鎴愬姛锛屾煡鐪嬫敞鍐岀殑鑺傜偣锛?/p>

$ headscale nodes list

ID | Name | NodeKey | Namespace | IP addresses | Ephemeral | Last seen | Onlin

e | Expired

1 | coredns | [Ew3RB] | default | 100.64.0.1 | false | 2022-03-20 09:08:58 | onlin

e | no

鍥炲埌 Tailscale 瀹㈡埛绔墍鍦ㄧ殑 Linux 涓绘満锛屽彲浠ョ湅鍒?Tailscale 浼氳嚜鍔ㄥ垱寤虹浉鍏崇殑璺敱琛ㄥ拰 iptables 瑙勫垯銆傝矾鐢辫〃鍙€氳繃浠ヤ笅鍛戒护鏌ョ湅锛?/p>

$ ip route show table 52

鏌ョ湅 iptables 瑙勫垯锛?/p>

$ iptables -S
-P INPUT DROP
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-N ts-forward
-N ts-input
-A INPUT -j ts-input
-A FORWARD -j ts-forward
-A ts-forward -i tailscale0 -j MARK --set-xmark 0x40000/0xffffffff
-A ts-forward -m mark --mark 0x40000 -j ACCEPT
-A ts-forward -s 100.64.0.0/10 -o tailscale0 -j DROP
-A ts-forward -o tailscale0 -j ACCEPT
-A ts-input -s 100.64.0.5/32 -i lo -j ACCEPT
-A ts-input -s 100.115.92.0/23 ! -i tailscale0 -j RETURN
-A ts-input -s 100.64.0.0/10 ! -i tailscale0 -j DROP

$ iptables -S -t nat
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-A ts-postrouting -m mark --mark 0x40000 -j MASQUERADE

macOS

macOS 鏈?3 绉嶅畨瑁呮柟娉曪細

  • 鐩存帴閫氳繃搴旂敤鍟嗗簵瀹夎锛屽湴鍧€锛歨ttps://apps.apple.com/ca/app/tailscale/id1475387142銆傚墠鎻愭槸浣?strong>闇€瑕佷竴涓編鍖?ID銆傘€傘€?/li>
  • 涓嬭浇瀹夎鍖呯洿鎺ュ畨瑁咃紝缁曡繃搴旂敤鍟嗗簵銆?/li>
  • 瀹夎寮€婧愮殑鍛戒护琛屽伐鍏?tailscale 鍜?tailscaled銆傜浉鍏抽摼鎺ワ細https://github.com/tailscale/tailscale/wiki/Tailscaled-on-macOS銆?/li>

杩欎笁绉嶅畨瑁呭寘鐨勬牳蹇冩暟鎹寘澶勭悊浠g爜鏄浉鍚岀殑锛屽敮涓€鐨勫尯鍒湪浜庡湪浜庢墦鍖呮柟寮忎互鍙婁笌绯荤粺鐨勪氦浜掓柟寮忋€?/p>

搴旂敤鍟嗗簵閲岀殑搴旂敤杩愯鍦ㄤ竴涓簲鐢ㄦ矙绠变腑锛屼笌绯荤粺鐨勫叾浠栭儴鍒嗛殧绂汇€傚湪娌欑鍐咃紝搴旂敤鍙互鏄竴涓綉缁滄墿灞曪紝浠ュ疄鐜?VPN 鎴栬€呯被 VPN 鐨勫姛鑳姐€傜綉缁滄墿灞曞疄鐜扮殑鍔熻兘瀵瑰簲鐢ㄥ晢搴椾箣澶栫殑搴旂敤鏄棤娉曠敓鏁堢殑銆?/p>

浠?macOS 浠?10.15 寮€濮嬫柊澧炰簡绯荤粺鎵╁睍锛岃鐧戒簡灏辨槸杩愯鍦ㄧ敤鎴锋€佺殑鍐呮牳鎵╁睍锛屽畠鐩告瘮浜庝紶缁熺殑缃戠粶鎵╁睍澧炲己浜嗗緢澶氬姛鑳斤紝姣斿鍐呭杩囨护銆侀€忔槑浠g悊銆丏NS 浠g悊绛夈€俆ailscale 鐙珛浜庡簲鐢ㄥ晢搴楃殑瀹夎鍖呬娇鐢ㄧ殑灏辨槸绯荤粺鎵╁睍锛岄€氳繃 DMG 鎴栬€?zip 鍘嬬缉鍖呰繘琛屽垎鍙戙€?/p>

{{< alert >}}
涓嶈鍚屾椂瀹夎搴旂敤鍟嗗簵鐗堟湰鍜岀嫭绔嬪垎鍙戠増鏈紝鍚屾椂鍙兘瑁呬竴涓€?br> {{< /alert >}}

鑰屽懡浠よ宸ュ叿鏃㈡病鏈変娇鐢ㄧ綉缁滄墿灞曚篃娌℃湁浣跨敤绯荤粺鎵╁睍锛岃€屾槸浣跨敤鐨?utun 鎺ュ彛锛岀浉姣斾簬 GUI 鐗堟湰缂哄皯浜嗛儴鍒嗗姛鑳斤紝姣斿 MagicDNS 鍜?Taildrop銆?/p>

鎬昏锛?/p>

搴旂敤鍟嗗簵锛堢綉缁滄墿灞曪級 鐙珛搴旂敤锛堢郴缁熸墿灞曪級 鍛戒护琛岀増鏈?/th>
鏄惁鍙敤 yes yes, beta yes
鍥惧舰鐣岄潰 yes yes no; CLI
macOS 鏈€浣庣増鏈?/td> macOS 10.13 macOS 10.15 macOS 10.13
鍚庡彴杩愯 no; sandboxed 鐞嗚涓婃敮鎸? 灏氭湭瀹炵幇 yes
浣跨敤鐨勯挜鍖欎覆馃攽 鐢ㄦ埛绾?/td> 绯荤粺绾?/td> 鐩存帴瀛樻斁鍦ㄦ枃浠朵腑
娌欑洅闅旂 yes no no
鑷姩鏇存柊 yes; 搴旂敤鍟嗗簵鐩存帴鏇存柊 yes; Sparkle no
鏄惁寮€婧?/td> no no yes
MagicDNS yes yes yes
Taildrop yes yes 鏈疄鐜?/td>

瀹夎瀹?GUI 鐗堝簲鐢ㄥ悗杩橀渶瑕佸仛涓€浜涢獨鎿嶄綔锛屾墠鑳借 Tailscale 浣跨敤 Headscale 浣滀负鎺у埗鏈嶅姟鍣ㄣ€傚綋鐒讹紝Headscale 宸茬粡缁欐垜浠彁渚涗簡璇︾粏鐨勬搷浣滄楠わ紝浣犲彧闇€瑕佸湪娴忚鍣ㄤ腑鎵撳紑 URL锛?code>https://<HEADSCALE_PUB_ENDPOINT>/apple锛屼究浼氬嚭鐜板涓嬬殑鐣岄潰锛?/p>

Tailscale 基础教程:Headscale 的部署方法和使用教程,第11张

瀵逛簬 1.34.0 鍙婁互涓婄殑 Tailscale 鐗堟湰锛屽彲浠ユ寜鐓т笅闈㈢殑鏂规硶鏉ユ搷浣滐細

  1. 闀挎寜銆孉LT銆嶉敭锛岀劧鍚庣偣鍑婚《閮ㄨ彍鍗曟爮鐨?Tailscale 鍥炬爣锛岀劧鍚庡皢榧犳爣鎸囬拡鎮仠鍦ㄣ€孌ebug銆嶈彍鍗曚笂銆?/p>

    Tailscale 基础教程:Headscale 的部署方法和使用教程,第12张
  2. 鍦ㄣ€孋ustom Login Server銆嶄笅鏂归€夋嫨銆孉dd Account...銆嶃€?/p>

  3. 鍦ㄦ墦寮€鐨勫脊绐椾腑濉叆 Headscale 鐨勫叕缃戝煙鍚嶏紝鐒跺悗鐐瑰嚮銆孉dd Account銆嶃€?/p>

    Tailscale 基础教程:Headscale 的部署方法和使用教程,第13张
  4. 鐒跺悗绔嬮┈灏变細璺宠浆鍒版祻瑙堝櫒骞舵墦寮€涓€涓〉闈€?/p>

    Tailscale 基础教程:Headscale 的部署方法和使用教程,第14张
  5. 鎺ヤ笅鏉ヤ笌涔嬪墠 Linux 瀹㈡埛绔浉鍚岋紝鍥炲埌 Headscale 鎵€鍦ㄧ殑鏈哄櫒鎵ц娴忚鍣ㄤ腑鐨勫懡浠ゅ嵆鍙紝娉ㄥ唽鎴愬姛锛?/p>

    Tailscale 基础教程:Headscale 的部署方法和使用教程,第15张

鍥炲埌 Headscale 鎵€鍦ㄤ富鏈猴紝鏌ョ湅娉ㄥ唽鐨勮妭鐐癸細

$ headscale nodes list

ID | Name | NodeKey | Namespace | IP addresses | Ephemeral | Last seen | Onlin

e | Expired

1 | coredns | [Ew3RB] | default | 100.64.0.1 | false | 2022-03-20 09:08:58 | onlin

e | no
2 | carsondemacbook-pro | [k7bzX] | default   | 100.64.0.2     | false     | 2022-03-20 09:48:30 | online  | no

鍥炲埌 macOS锛屾祴璇曟槸鍚﹁兘 ping 閫氬绔妭鐐癸細

$ ping -c 2 100.64.0.1
PING 100.64.0.1 (100.64.0.1): 56 data bytes
64 bytes from 100.64.0.1: icmp_seq=0 ttl=64 time=37.025 ms
64 bytes from 100.64.0.1: icmp_seq=1 ttl=64 time=38.181 ms

--- 100.64.0.1 ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 37.025/37.603/38.181/0.578 ms

涔熷彲浠ヤ娇鐢?Tailscale CLI 鏉ユ祴璇曪細

$ /Applications/Tailscale.app/Contents/MacOS/Tailscale ping 100.64.0.1
pong from coredns (100.64.0.1) via xxxx:41641 in 36ms

瀵逛簬鐗堟湰鍙蜂綆浜?1.32.0 鐨?Tailscale 瀹㈡埛绔紝浣犲彧闇€瑕佹寜鐓у浘涓墍杩扮殑姝ラ鎿嶄綔鍗冲彲锛屾湰鏂囧氨涓嶅啀璧樿堪浜嗐€?/p>

Android

Android 瀹㈡埛绔粠 1.30.0 鐗堟湰寮€濮嬫敮鎸佽嚜瀹氫箟鎺у埗鏈嶅姟鍣紙鍗?coordination server锛夛紝浣犲彲浠ラ€氳繃 Google Play 鎴栬€?F-Droid 涓嬭浇鏈€鏂扮増鏈殑瀹㈡埛绔€?/p>

瀹夎瀹屾垚鍚庢墦寮€ Tailscale App锛屼細鍑虹幇濡備笅鐨勭晫闈細

<img src="https://cdn.jsdelivr.us/gh/yangchuansheng/imghosting4@main/uPic/2022-11-22-18-12-m2IYpv.jpeg">

鐐瑰紑鍙充笂瑙掔殑鈥滀笁涓偣鈥濓紝浣犱細鐪嬪埌鍙湁涓€涓?About 閫夐」锛?/p>

<img src="https://cdn.jsdelivr.us/gh/yangchuansheng/imghosting4@main/uPic/2022-11-22-18-14-ghdl4A.jpeg">

鎺ヤ笅鏉ュ氨闇€瑕佷竴浜涢獨鎿嶄綔浜嗭紝浣犻渶瑕佸弽澶嶄笉鍋滃湴鐐瑰紑鍐嶅叧闂?/strong>鍙充笂瑙掔殑鈥滀笁涓偣鈥濓紝閲嶅涓夊洓娆′箣鍚庯紝渚夸細鍑虹幇涓€涓?Change server 閫夐」锛?/p>

<img src="https://cdn.jsdelivr.us/gh/yangchuansheng/imghosting4@main/uPic/2022-11-22-18-23-mcAexh.jpeg">

鐐瑰嚮 Change server锛屽皢 headscale 鎺у埗鏈嶅姟鍣ㄧ殑鍦板潃濉繘鍘伙細

<img src="https://cdn.jsdelivr.us/gh/yangchuansheng/imghosting4@main/uPic/2022-11-22-18-37-fkRIxW.jpeg">

鐒跺悗鐐瑰嚮 Save and restart 閲嶅惎锛岀偣鍑?Sign in with other锛屽氨浼氳烦鍑鸿繖涓〉闈細

<img src="https://cdn.jsdelivr.us/gh/yangchuansheng/imghosting6@main/uPic/2024-01-07-19-39-fKOCTT.jpg">

灏嗗叾涓殑鍛戒护绮樿创鍒?Headscale 鎵€鍦ㄤ富鏈虹殑缁堢锛屽皢 USER 鏇挎崲涓轰箣鍓嶅垱寤虹殑 user锛岀劧鍚庢墽琛屽懡浠ゅ嵆鍙€傛敞鍐屾垚鍔熷悗鍙皢璇ラ〉闈㈠叧闂紝鍥炲埌 App 涓婚〉锛屾晥鏋滃鍥撅細

<img src="https://cdn.jsdelivr.us/gh/yangchuansheng/imghosting6@main/uPic/2024-01-07-20-21-2e8CKX.jpg">

Windows

Windows Tailscale 瀹㈡埛绔兂瑕佷娇鐢?Headscale 浣滀负鎺у埗鏈嶅姟鍣紝鍙渶鍦ㄦ祻瑙堝櫒涓墦寮€ URL锛?code>https://<HEADSCALE_PUB_ENDPOINT>/windows锛屼究浼氬嚭鐜板涓嬬殑鐣岄潰锛?/p>

Tailscale 基础教程:Headscale 的部署方法和使用教程,第16张

鎸夌収鍏朵腑鐨勬楠ゆ搷浣滃嵆鍙€?/p>

鍏朵粬 Linux 鍙戣鐗?/h3>

闄や簡甯歌鐨?Linux 鍙戣鐗堜箣澶栵紝杩樻湁涓€浜涚壒娈婂満鏅殑 Linux 鍙戣鐗堬紝姣斿 OpenWrt銆佸▉鑱旈€氾紙QNAP锛夈€佺兢鏅栫瓑锛岃繖浜涘彂琛岀増鐨勫畨瑁呮柟娉曞凡缁忔湁浜哄啓濂戒簡锛岃繖閲屽氨涓嶈缁嗘弿杩颁簡锛屾垜鍙粰鍑虹浉鍏崇殑 GitHub 浠撳簱锛屽ぇ瀹跺鏋滆嚜宸辨湁闇€姹傦紝鐩存帴鍘荤湅鐩稿叧浠撳簱鐨勬枃妗e嵆鍙€?/p>

  • OpenWrt锛歨ttps://github.com/adyanth/openwrt-tailscale-enabler
  • 缇ゆ櫀锛歨ttps://github.com/tailscale/tailscale-synology
  • 濞佽仈閫氾細https://github.com/tailscale/tailscale-qpkg

iOS

iOS 绯荤粺鐩存帴浠庡簲鐢ㄥ晢搴楀畨瑁呭嵆鍙紝褰撶劧鍓嶆彁鏄綘闇€瑕佹湁涓€涓編鍖?ID銆?/p>

  1. 瀹夎瀹屾垚鍚庢墦寮€ Tailscale 纭浣犳病鏈夌櫥褰曚换浣曡处鍙枫€傜劧鍚庢墦寮€銆岃缃€嶏紝鍚戜笅婊戝姩锛屽湪銆孏ame Center銆嶆垨鑰呫€岀數瑙嗘彁渚涘晢銆嶄笅鏂规壘鍒般€孴ailscale銆嶏紝鐒跺悗鐐瑰嚮杩涘幓銆?/p>

    Tailscale 基础教程:Headscale 的部署方法和使用教程,第17张

    濡傛灉浣犵殑璁惧涔嬪墠鐧诲綍杩?Tailscale 鏈嶅姟绔紝闇€瑕佸皢銆孯eset Keychain銆嶉€夐」鎵撳紑銆?/p>

  2. 鍦ㄣ€孉lternate Coordination Server URL銆嶄笅鏂硅緭鍏ヤ綘鐨?Headscale 鍏綉鍩熷悕銆?/p>

  3. 浠?iOS 搴旂敤绋嬪簭鍒囨崲鍣ㄤ腑鍏抽棴 Tailscale 鍐嶉噸鏂版墦寮€锛岀劧鍚庨€夋嫨銆孡og in銆嶏紝灏变細寮瑰嚭涓€涓?Headscale 韬唤璁よ瘉椤甸潰銆?/p>

    Tailscale 基础教程:Headscale 的部署方法和使用教程,第18张
  4. 灏?Headscale 韬唤璁よ瘉椤甸潰涓殑鍛戒护澶嶅埗绮樿创鍒?headscale 鎵€鍦ㄥ鍣ㄧ殑缁堢涓紝骞跺皢 USERNAME 鏇挎崲涓哄墠闈㈡墍鍒涘缓鐨?user銆?/p>

    $ headscale nodes register --user default --key mkey:1fbd9696ebb03b9394033949514345bc5dba0e570bc0d778f15f92a02d2dcb66
    2023-12-29T09:55:38Z TRC DNS configuration loaded dns_config={"Nameservers":["1.1.1.1"],"Proxied":true,"Resolvers":[{"Addr":"1.1.1.1"}]}
    Node localhost registered
    
  5. 娉ㄥ唽鎴愬姛銆?/p>

    Tailscale 基础教程:Headscale 的部署方法和使用教程,第19张

閫氳繃 Pre-Authkeys 鎺ュ叆

鍓嶉潰鐨勬帴鍏ユ柟娉曢兘闇€瑕佹湇鍔$鍚屾剰锛屾楠ゆ瘮杈冪儲鐞愶紝鍏跺疄杩樻湁鏇寸畝鍗曠殑鏂规硶锛屽彲浠ョ洿鎺ユ帴鍏ワ紝涓嶉渶瑕佹湇鍔$鍚屾剰銆?/p>

棣栧厛鍦ㄦ湇鍔$鐢熸垚 pre-authkey 鐨?token锛屾湁鏁堟湡鍙互璁剧疆涓?24 灏忔椂锛?/p>

$ headscale preauthkeys create -e 24h --user default

鏌ョ湅宸茬粡鐢熸垚鐨?key锛?/p>

$ headscale --user default preauthkeys list
ID | Key                                              | Reusable | Ephemeral | Used  | Expiration          | Created            
1  | 57e419c40e30b0dxxxxxxxf15562c18a8c6xxxx28ae76f57 | false    | false     | false | 2022-05-30 07:14:17 | 2022-05-29 07:14:17

褰撶劧浣犱篃鍙互鍦?Headscale-Admin 涓敓鎴愩€傜偣鍑诲鎴风鎯冲姞鍏ョ殑 User锛?/p>

Tailscale 基础教程:Headscale 的部署方法和使用教程,第20张

鍦ㄥ脊鍑虹殑鐣岄潰涓偣鍑汇€孭reAuth Keys銆嶅彸渚х殑 Create锛岃缃竴涓繃鏈熸椂闂达紙姣斿 100 骞磣锛夛紝濡傛灉鎯抽噸澶嶅埄鐢ㄨ繖涓?Key锛屽彲浠ュ嬀閫?Reusable锛屾渶鍚庣偣鍑?鉁咃細

Tailscale 基础教程:Headscale 的部署方法和使用教程,第21张

鍒涘缓鎴愬姛鍚庯紝鐐瑰嚮绾㈡鍖哄煙渚垮彲澶嶅埗璇?PreAuth Key锛?/p>

Tailscale 基础教程:Headscale 的部署方法和使用教程,第22张

鐜板湪鏂拌妭鐐瑰氨鍙互鏃犻渶鏈嶅姟绔悓鎰忕洿鎺ユ帴鍏ヤ簡锛?/p>

$ tailscale up --login-server=http://<HEADSCALE_PUB_ENDPOINT>:8080 --accept-routes=true --accept-dns=false --authkey $KEY

鎵撻€氬眬鍩熺綉

鍒扮洰鍓嶄负姝㈡垜浠彧鏄墦閫犱簡涓€涓偣瀵圭偣鐨?Mesh 缃戠粶锛屽悇涓妭鐐逛箣闂撮兘鍙互閫氳繃 WireGuard 鐨勭鏈夌綉缁?IP 杩涜鐩磋繛銆備絾鎴戜滑鍙互鏇村ぇ鑳嗕竴鐐癸紝杩樿寰楁垜鍦ㄦ枃绔犲紑澶存彁鍒扮殑璁块棶瀹跺涵鍐呯綉鐨勮祫婧愬悧锛熸垜浠彲浠ラ€氳繃閫傚綋鐨勯厤缃姣忎釜鑺傜偣閮借兘璁块棶鍏朵粬鑺傜偣鐨勫眬鍩熺綉 IP銆傝繖涓娇鐢ㄥ満鏅氨姣旇緝澶氫簡锛屼綘鍙互鐩存帴璁块棶瀹跺涵鍐呯綉鐨?NAS锛屾垨鑰呭唴缃戠殑浠讳綍涓€涓湇鍔★紝鏇撮珮绾х殑鐜╁鍙互浣跨敤杩欎釜鏂规硶鏉ヨ闂簯涓?Kubernetes 闆嗙兢鐨?Pod IP 鍜?Service IP銆?/strong>

鍋囪浣犵殑瀹跺涵鍐呯綉鏈変竴鍙?Linux 涓绘満锛堟瘮濡?OpenWrt锛夊畨瑁呬簡 Tailscale 瀹㈡埛绔紝鎴戜滑甯屾湜鍏朵粬 Tailscale 瀹㈡埛绔彲浠ョ洿鎺ラ€氳繃瀹朵腑鐨勫眬鍩熺綉 IP锛堜緥濡?192.168.100.0/24锛?璁块棶瀹跺涵鍐呯綉鐨勪换浣曚竴鍙拌澶囥€?/p>

閰嶇疆鏂规硶寰堢畝鍗曪紝棣栧厛闇€瑕佽缃?IPv4 涓?IPv6 璺敱杞彂锛?/p>

$ echo 'net.ipv4.ip_forward = 1' | tee /etc/sysctl.d/ipforwarding.conf
$ echo 'net.ipv6.conf.all.forwarding = 1' | tee -a /etc/sysctl.d/ipforwarding.conf
$ sysctl -p /etc/sysctl.d/ipforwarding.conf

瀹㈡埛绔慨鏀规敞鍐岃妭鐐圭殑鍛戒护锛屽湪鍘熸潵鍛戒护鐨勫熀纭€涓婂姞涓婂弬鏁?--advertise-routes=192.168.100.0/24锛屽憡璇?Headscale 鏈嶅姟鍣ㄢ€滄垜杩欎釜鑺傜偣鍙互杞彂杩欎簺鍦板潃鐨勮矾鐢扁€濄€?/p>

$ tailscale up --login-server=http://<HEADSCALE_PUB_ENDPOINT>:8080 --accept-routes=true --accept-dns=false --advertise-routes=192.168.100.0/24 --reset

鍦?Headscale 绔煡鐪嬭矾鐢憋紝鍙互鐪嬪埌鐩稿叧璺敱鏄叧闂殑銆?/p>

$ headscale nodes list|grep openwrt

6 | openwrt | [7LdVc] | default | 100.64.0.6 | false | 2022-03-20 15:50:46 | onlin

e | no

$ headscale routes list -i 6

Route | Enabled

192.168.100.0/24 | false

寮€鍚矾鐢憋細

$ headscale routes enable -i 6 -r "192.168.100.0/24"

Route | Enabled

192.168.100.0/24 | true

濡傛灉鏈夊鏉¤矾鐢遍渶瑕佺敤 , 闅斿紑锛?/p>

$ headscale routes enable -i 6 -r "192.168.100.0/24,xxxx"

涔熷彲浠ラ€氳繃鍙傛暟 -a 寮€鍚墍鏈夎矾鐢憋細

$ headscale routes enable -i 6 -a

鍏朵粬鑺傜偣鏌ョ湅璺敱缁撴灉锛?/p>

$ ip route show table 52|grep "192.168.100.0/24"
192.168.100.0/24 dev tailscale0

鍏朵粬鑺傜偣鍚姩鏃堕渶瑕佸鍔?--accept-routes=true 閫夐」鏉ュ0鏄?鈥滄垜鎺ュ彈澶栭儴鍏朵粬鑺傜偣鍙戝竷鐨勮矾鐢扁€濄€?/p>

鐜板湪浣犲湪浠讳綍涓€涓?Tailscale 瀹㈡埛绔墍鍦ㄧ殑鑺傜偣閮藉彲浠?ping 閫氬搴唴缃戠殑鏈哄櫒浜嗭紝浣犲湪鍏徃鎴栬€呮槦宸村厠涔熷彲浠ュ儚鍦ㄥ閲屼竴鏍风敤鍚屾牱鐨?IP 闅忔剰璁块棶瀹朵腑鐨勪换浣曚竴涓澶囷紝灏遍棶浣犻涓嶉锛?/p>

鎬荤粨

鐩墠浠庣ǔ瀹氭€ф潵鐪嬶紝Tailscale 姣斿叾浠栨満閬?WireGuard 鐨勭粍缃戝伐鍏风暐鑳滀竴绛癸紝鍩烘湰涓婁笉浼氭椂涓嶆椂鍑虹幇 ping 涓嶉€氱殑鎯呭喌锛岃繖鍙栧喅浜?Tailscale 鍦ㄧ敤鎴锋€佸 NAT 绌块€忔墍鍋氱殑绉嶇浼樺寲锛屼粬浠繕涓撻棬鍐欎簡涓€绡囨枃绔犱粙缁?NAT 绌块€忕殑鍘熺悊锛屼腑鏂囩増缈昏瘧鑷浗鍐呯殑 eBPF 澶т浆璧典簹妤狅紝澧欒鎺ㄨ崘澶у闃呰銆傛斁涓€寮犲浘缁欏ぇ瀹舵劅鍙椾竴涓嬶細

Tailscale 基础教程:Headscale 的部署方法和使用教程,第23张

https://www.xamrdz.com/backend/3fu1935163.html

相关文章: