Crab-Hole 项目启动与配置教程
1. 项目目录结构及介绍
Crab-Hole 是一个用 Rust 编写的跨平台 Pi-Hole 克隆项目。以下是项目的目录结构及各部分的简要介绍:
crab-hole/
├── .github/ # GitHub 工作流和配置文件
├── src/ # 源代码目录
├── .dockerignore # Docker 忽略文件
├── .gitattributes # Git 属性文件
├── .gitignore # Git 忽略文件
├── Cargo.lock # Rust 依赖锁文件
├── Cargo.toml # Rust 项目配置文件
├── LICENSE # 项目许可证文件
├── README.md # 项目说明文件
├── build.rs # Rust 构建脚本
├── config.toml # 默认配置文件
├── dockerfile # Dockerfile 文件
├── example-config.toml # 配置文件示例
└── rustfmt.toml # Rust 格式化配置文件
.github/
: 包含 GitHub Actions 工作流,用于自动化项目的某些任务。src/
: 包含项目的所有 Rust 源代码。.dockerignore
: 指定在创建 Docker 镜像时应忽略的文件和目录。.gitattributes
: 配置 Git 如何处理特定的文件和目录。.gitignore
: 指定在版本控制中应忽略的文件和目录。Cargo.lock
: 记录项目的依赖关系和版本,确保构建的一致性。Cargo.toml
: Rust 项目的配置文件,包括项目元数据和依赖项。LICENSE
: 项目使用的 AGPL-3.0 许可证。README.md
: 提供项目的详细说明和基本信息。build.rs
: 自定义的 Rust 构建脚本,可以在编译前执行一些任务。config.toml
: 默认的配置文件,用于设置项目的运行参数。dockerfile
: 用于构建 Docker 容器的 Dockerfile 文件。example-config.toml
: 提供一个配置文件的示例,帮助用户了解如何配置项目。
2. 项目的启动文件介绍
项目的启动非常直接,只需执行编译后的二进制文件即可。以下是启动项目的步骤:
- 确保已经安装了 Rust 和 Cargo。
- 使用以下命令安装 Crab-Hole:
cargo install crab-hole --locked
- 确保
~/.cargo/bin
路径已经添加到系统的PATH
环境变量中。 - 运行以下命令启动服务:
crab-hole
3. 项目的配置文件介绍
项目的配置文件是 config.toml
,它包含了项目运行时所需的所有配置信息。以下是一些重要的配置选项:
blocklist
: 定义要阻止的域名列表。allow_list
: 定义要允许的域名列表。api
: 配置 API 服务,如端口和监听地址。downstream
: 定义下游服务的配置,包括协议、监听地址、端口等。upstream
: 定义上游 DNS 服务器,包括地址、协议等。
以下是一个配置文件示例:
[blocklist]
include_subdomains = true
lists = [
"https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn/hosts",
"https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt",
"file:///blocked.txt"
]
[allow_list]
lists = [
"file:///allowed.txt"
]
[api]
port = 8080
listen = "127.0.0.1"
show_doc = true
admin_key = "1234"
[[downstream]]
protocol = "udp"
listen = "localhost"
port = 8080
[[downstream]]
protocol = "udp"
listen = "[::]"
port = 8053
[[downstream]]
protocol = "tls"
listen = "[::]"
port = 8054
certificate = "dns.example.com.crt"
key = "dns.example.com.key"
[[downstream]]
protocol = "https"
listen = "[::]"
port = 8055
certificate = "dns.example.com.crt"
key = "dns.example.com.key"
dns_hostname = "dns.example.com"
[[downstream]]
protocol = "quic"
listen = "127.0.0.1"
port = 8055
certificate = "dns.example.com.crt"
key = "dns.example.com.key"
dns_hostname = "dns.example.com"
[upstream]
validate = true
[[upstream.name_servers]]
socket_addr = "[2606:4700:4700::1111]:853"
protocol = "tls"
tls_dns_name = "example-dns-service.com"
trust_nx_responses = false
[[upstream.name_servers]]
socket_addr = "1.1.1.1:853"
protocol = "tls"
tls_dns_name = "example-dns-service.com"
trust_nx_responses = false
确保根据您的网络环境和需求调整配置文件。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考