Files
wlnote/nebula/操作概述.md
2025-06-13 17:33:44 +08:00

136 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 操作概述
---
## Nebula 网络的架构
1. 灯塔节点 (lighthouse)
2. 证书授权 (certificate authority)
3. 终端节点 (host)
### 灯塔节点
灯塔节点即中心节点,用于追踪所有其他节点,帮助其他节点建立连接。
### 证书授权 (CA)
CA 由 2 个文件组成 :一个 CA 证书,以及关联的私匙 (private key)。
CA 证书对整个网络公开,并被网络中所有终端信任 CA 私匙 则不公开,在不使用 Nebula 网络是可保持离线。
### 终端节点
终端节点即 Nubula 网络的单个普通节点CA 用于验证加入网络中的每一个终端。
一个终端证书包含名称、IP、组成员、其他终端细节等终端不能修改自己的证书修改即失去有效性这可以杜绝假冒发生。
每个终端都有自己的私匙,用于在创建隧道时使自身的标识符生效。
---
## 软件下载
Nebula 软件包包含 2 部分nebula-cert 和 nebula binary, 支持各种平台Linux, Windows, macOS, FreeBSD, iOS, Android, Docker
自 1.7.0 版本Nebula 内置 CA 私匙加密功能,在生成 CA 时传递 -encrypt 参数即可达到加密目的。
## CA
创建 Nebula 网络的第一步是 生成组织的 CA
```shell
./nebula-cert ca -name "Myorganization, Inc"
```
该指令生成 ca.key 和 ca.cert 两个文件ca.key 用来签署其他终端的证书,需要妥善保管,建议强加密。
默认创建的 CA 有一年有效期,传递 --duration XXhXXmXXs 参数可指定有效期限,如 -duration 17531h 有效期限为 2 年。
---
## 快速构建 Nebula 网络
1. 创建灯塔节点
灯塔节点是整个 Nebula 网络中唯一需要固定 IP 地址的终端,灯塔节点对终端配置要求不高。
灯塔节点需要对互联网开放 UDP/4242 端口,保证不被内部防火墙阻塞。
2. 生成各终端的证书和密钥
命令需要指定终端名称和 IP 地址,还可以指定组(用于隧道的通行规则)
```shell
./nebula-cert sign -name "lighthouse1" -ip "192.168.100.1/24"
./nebula-cert sign -name "laptop" -ip "192.168.100.5/24" -groups "laptop,ssh"
./nebula-cert sign -name "server" -ip "192.168.100.9/24" -groups "servers"
```
3. 配置 Nebula
下载示例配置文件,相应修改后作为各终端的配置文件。
**灯塔节点**
```yaml
static_host_map:
lighthouse:
am_lighthouse: true
```
灯塔节点配置文件中的 static_host_map 应当为空,即网络中的灯塔节点是唯一的。
**终端节点**
```yaml
static_host_map:
'192.168.100.1': ['198.51.100.1:4242']
lighthouse:
am_lighthouse: false
interval: 60
hosts:
- '192.168.100.1'
```
终端节点配置文件中中必须在 static_host_map 节和 lighthouse 节 的 hosts 中定义灯塔节点的公网 IP以及隧道 IP 。
4. 防火墙配置
在配置文件中设定防火墙的数据流向规则。
```yaml
firewall:
outbound:
# Allow all outbound traffic from this node
- port: any
proto: any
host: any
inbound:
# Allow icmp between any nebula hosts
- port: any
proto: icmp
host: any
```
5. 将生成的 4 个文件放入各终端,启动网络
将 CA、终端证书、密钥、配置文件放入一个目录自定义比如
```shell
mv config-lighthouse.yaml /etc/nebula/config.yaml
mv ca.crt /etc/nebula/ca.crt
mv lighthouse.crt /etc/nebula/host.crt
mv lighthouse.key /etc/nebula/host.key
```
启动 Nebula ,在参数中指定配置文件位置
```shell
./nebula -config /etc/nebula/config.yaml
```
6. 验证连通性
---
## Windows 注册服务
1. 使用系统自带 sc 命令
2. 使用 nssm 注册工具