0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Netbird(その2:サーバー構築)

0
Posted at

Self Host実現

Netbird Cloudを使わず、Cloudの代わりとなるサーバーを構築するものである。本家サイトにも構築方法の説明があるが、ここではChatGPTやGeminiに、ほぼ100%依存して作成した内容である。とは言え、彼らが答える内容は適切でないことも多く、100回以上(おそらく)のTry&Errorを繰り返し、最終解に辿り着くまで相当の時間を要した。

サーバー(Self Host)設定

ubuntu上に構築。

DNS関連:ドメイン設定

ドメイン名を利用する必要があるとのこと。ここでは、”netbird.local”という名称を利用し、”/etc/hosts”に登録する。

/etc/hosts
192.168.10.206 netbird.local

リーバースプロキシcaddy

結論的には、caddyを使うことであった。ここに至るまでが最も時間を要したところ。

インストール

$ sudo apt install -y debian-keyring debian-archive-keyring \
  apt-transport-https curl
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
  | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
  | sudo tee /etc/apt/sources.list.d/caddy-stable.list
$ sudo apt update
$ sudo apt install caddy

Caddyfile

設定ファイル、これはChatGPTから示された内容である。これを、”/etc/caddy/Caddyfile”として配置する。

/etc/caddy/Caddyfile
netbird.local {

    tls internal

    # gRPC (Signal / Management)
    @grpc path /signalexchange.SignalExchange/* /management.ManagementService/*
    reverse_proxy @grpc h2c://127.0.0.1:8081

    # Backend API
    @backend path /relay* /ws-proxy/* /api/* /oauth2/*
    reverse_proxy @backend 127.0.0.1:8081

    # Dashboard
    reverse_proxy /* 127.0.0.1:8080
}

再起動。

$ sudo systemctl restart caddy

CA

初期状態では、CAは未作成。下記コマンドにより、CA(root.crt)を作成する。”curl -k”により、自動的に作成されるらしい。

$ curl -k https://netbird.local
$ sudo ls /var/lib/caddy/.local/share/caddy/pki/authorities/local
intermediate.crt  intermediate.key  root.crt  root.key

CAを登録する。ここでは、”netbird-ca.crt”という名称に変更。

$ sudo cp -p /var/lib/caddy/.local/share/caddy/pki/authorities/local/root.crt \
  /usr/local/share/ca-certificates/netbird-ca.crt
$ sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
rehash: warning: skipping ca-certificates.crt,it does not contain exactly one certificate or CRL
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

Adding debian:netbird-ca.pem
done.
done.
$ sudo systemctl restart caddy

”netbird-ca.crt”はクライアントにscpなどでコピーする。

スクリプト実行

公式サイトから、Self Host構築用のスクリプトをダウンロード。

$ curl -fsSL https://github.com/netbirdio/netbird/raw/main/infrastructure_files/getting-started.sh \
  -o getting-started.sh
$ chmod +x getting-started.sh

実行する。下記「[4] External Caddy 」を選択することがポイント。

$ sudo ./getting-started.sh
The NETBIRD_DOMAIN variable cannot be empty.
Enter the domain you want to use for NetBird (e.g. netbird.my-domain.com): netbird.local

Which reverse proxy will you use?
  [0] Traefik (recommended - automatic TLS, included in Docker Compose)
  [1] Existing Traefik (labels for external Traefik instance)
  [2] Nginx (generates config template)
  [3] Nginx Proxy Manager (generates config + instructions)
  [4] External Caddy (generates Caddyfile snippet)
  [5] Other/Manual (displays setup documentation)

Enter choice [0-5] (default: 0): 4

Should container ports be bound to localhost only (127.0.0.1)?
Choose 'yes' if your reverse proxy runs on the same host (more secure).
Bind to localhost only? [Y/n]: Y

Is Caddy running in Docker?
If yes, enter the Docker network Caddy is on (NetBird will join it).
Docker network (leave empty if not in Docker): 
Rendering initial files...

==========================================
  EXTERNAL CADDY SETUP
==========================================

Generated: caddyfile-netbird.txt

Next steps:
  1. Add the contents of caddyfile-netbird.txt to your Caddyfile
  2. Reload Caddy: caddy reload --config /path/to/Caddyfile

Container ports (bound to 127.0.0.1):
  Dashboard:     8080
  NetBird Server: 8081 (all services)

Press Enter when your reverse proxy is configured (or Ctrl+C to exit)... 

Starting NetBird services

(略)

Script done on 2026-03-14 13:40:21+09:00 [COMMAND_EXIT_CODE="0"]

この結果として、次の4つのファイルが作成され、dockerイメージやコンテナが作成されるが、”caddyfile-netbird.txt”は使わない。

caddyfile-netbird.txt
config.yaml
dashboard.env
docker-compose.yml

すでに、サーバーコンテナ起動済み。

$ docker ps -a
CONTAINER ID   IMAGE                             COMMAND                   CREATED       STATUS       PORTS                                                                 NAMES
a5516b86fe00   netbirdio/netbird-server:latest   "/go/bin/netbird-ser…"   9 hours ago   Up 6 hours   0.0.0.0:3478->3478/udp, [::]:3478->3478/udp, 127.0.0.1:8081->80/tcp   netbird-server
6653dc25fcd9   netbirdio/dashboard:latest        "/usr/bin/supervisor…"   9 hours ago   Up 6 hours   443/tcp, 127.0.0.1:8080->80/tcp                                       netbird-dashboard

サーバー初期設定

https://netbird.local/」にアクセス、管理者初期設定実施。

201 1stAccess.png

再度、入り直す。

202 Login.png

”Skip to Dashboard”クリック。

103 1st Topのコピー.png

クライアントが接続するためのキーを作成する。

104 CreateSetupKeyのコピー.png

名称入力、キーの再利用ON、キーの有効期限を設定。

106 CreateSetupKey3のコピー.png
107 CreateSetupKey4.png

キーが作成される。

108 Created.png

キーは、後ほどクライアントからサーバーへ接続するときに利用する。このタイミングでしか表示されないようなので、要注意。忘れてしまった時などには、再度キーを作成する。

109 KeyList.png

クライアント

DNS関連:ドメイン設定

サーバー側と同様。

/etc/hosts
192.168.10.206 netbird.local

CA

サーバーからコピーしてきた”netbird-ca.crt”を利用。

$ sudo cp netbird-ca.crt /usr/local/share/ca-certificates/
$ sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
rehash: warning: skipping ca-certificates.crt,it does not contain exactly one certificate or CRL
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

Netbirdインストール

本家サイトのLinux Installationに従う。

$ curl -fsSL https://pkgs.netbird.io/install.sh | sh

...

NetBird service has been started
Installation has been finished. To connect, you need to run NetBird by executing the following command:

netbird up

念のため、再起動。

$ sudo systemctl restart netbird

Netbird起動

サーバーURLとサーバーで発行されたキーを指定して起動。

$ netbird up --management-url https://netbird.local --setup-key 31BC7FFE-D30C-4D75-B5A6-41C54C7102A5
Connected

検証

Peerリスト

サーバーでのクライアントの登録状況。

203 PeerList.png

クライアントステータス

他のクライアントも接続している状況でのNetbirdステータスである。

$ netbird status -d
Peers detail:
 raspberry.netbird.selfhosted:
  NetBird IP: 100.73.90.113
  Public key: 05RXHMY4+BjsgP6dIdBzx0SjlyMmItrWW86ZI8+l1zI=
  Status: Connected
  -- detail --
  Connection type: P2P
  ICE candidate (Local/Remote): host/prflx
  ICE candidate endpoints (Local/Remote): [fd7b:5983:8919:8974:c590:2302:92ff:40f8]:51820/[2408:211:7ee:9400:1078:cf73:3d7a:80d3]:44558
  Relay server address: rels://netbird.local:443
  Last connection update: 3 minutes, 15 seconds ago
  Last WireGuard handshake: 1 minute, 10 seconds ago
  Transfer status (received/sent) 216 B/584 B
  Quantum resistance: false
  Networks: -
  Latency: 6.708253ms

Events:
  [INFO] SYSTEM (f3d55da0-d257-4940-98d3-fc564784baff)
    Message: Network map updated
    Time: 3 minutes, 50 seconds ago
  [INFO] SYSTEM (2269606b-2364-486e-8903-b6027ce86bd1)
    Message: Network map updated
    Time: 3 minutes, 34 seconds ago
  [INFO] SYSTEM (270e5d43-1b73-41d3-84d4-ab941bf247e4)
    Message: Network map updated
    Time: 3 minutes, 32 seconds ago
OS: linux/amd64
Daemon version: 0.66.2
CLI version: 0.66.2
Profile: default
Management: Connected to https://netbird.local:443
Signal: Connected to https://netbird.local:443
Relays: 
  [stun:netbird.local:3478] is Available
  [rels://netbird.local:443] is Available
Nameservers: 
FQDN: aspero.netbird.selfhosted
NetBird IP: 100.73.152.243/16
Interface type: Kernel
Quantum resistance: false
Lazy connection: false
SSH Server: Disabled
Networks: -
Peers count: 1/1 Connected

Wireguardの状況。

$ ip a

...

4: wt0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1280 qdisc noqueue state UNKNOWN group default qlen 1000
    link/none 
    inet 100.73.152.243/16 brd 100.73.255.255 scope global wt0
       valid_lft forever preferred_lft forever
$
$ sudo wg show
interface: wt0
  public key: yq83laGwfxRtA95zIyrjog0RGCHHZq9IttDhEXjiwW0=
  private key: (hidden)
  listening port: 51820
  fwmark: 0x1bd00

peer: 05RXHMY4+BjsgP6dIdBzx0SjlyMmItrWW86ZI8+l1zI=
  endpoint: [2408:211:7ee:9400:1078:cf73:3d7a:80d3]:44558
  allowed ips: 100.73.90.113/32
  latest handshake: 1 minute, 50 seconds ago
  transfer: 308 B received, 988 B sent
  persistent keepalive: every 25 seconds

疎通

とりあえず、2拠点間のpingを実施。

$ ping 100.73.90.113 -c 3
PING 100.73.90.113 (100.73.90.113) 56(84) bytes of data.
64 bytes from 100.73.90.113: icmp_seq=1 ttl=64 time=54.3 ms
64 bytes from 100.73.90.113: icmp_seq=2 ttl=64 time=10.8 ms
64 bytes from 100.73.90.113: icmp_seq=3 ttl=64 time=7.05 ms

--- 100.73.90.113 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 7.053/24.028/54.273/21.439 ms

おまけ:SSHアクセス

DashboardからクライアントへSSHアクセスができる。クライアントリストから対象としたいクライアントのConnect-SSHをクリック。

SSH0のコピー.png

SSH1.png

Enableをクリックし、指示に従って、クライアントにてコマンド実行。

SSH2.png

$ netbird down
Disconnected
$ netbird up --management-url https://netbird.local --allow-server-ssh --enable-ssh-root
Connected

すると、SSHが選択できるようになる。

SSH3.png

ログインしてみる。

SSH4のコピー.png

管理ID情報を入力。

SSH5.png

SSH7のコピー.png

この時の該当クライアントのステータスは下記。

$ netbird status
OS: linux/amd64
Daemon version: 0.66.2
CLI version: 0.66.2
Profile: default
Management: Connected
Signal: Connected
Relays: 2/2 Available
Nameservers: 0/0 Available
FQDN: aspero.netbird.selfhosted
NetBird IP: 100.73.152.243/16
Interface type: Kernel
Quantum resistance: false
Lazy connection: false
SSH Server: Enabled (1 active session)
Networks: -
Peers count: 2/2 Connected

”SSH Server: Enabled (1 active session)”が見える。

EOF

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?