客户端使用指南
本指南将详细介绍如何使用 Anima 客户端进行内网穿透。
📋 目录
🚀 快速开始
初始化配置
# 首次使用,配置服务器和认证信息
anima config init
按提示输入:
- 服务器地址:
frp.anima4.cn(官方服务器)或your-domain.com(私有化部署) - API Token:从管理后台复制的 Token
配置文件位置
配置文件自动保存在:~/.anima/config.toml
[server]
# 支持官方服务器和私有化部署
addr = "frp.anima4.cn" # 官方服务器
# addr = "your-domain.com" # 私有化部署
token = "anima_xxxxxxxxxxxx"
[client]
name = "my-macbook"
⚙️ 配置管理
查看当前配置
anima config show
更新配置
anima config update
重置配置
anima config reset
🔗 隧道管理
创建隧道
HTTP 隧道
# 创建 HTTP 隧道
anima tunnel create \
--name my-webapp \
--type http \
--local-port 3000 \
--subdomain myapp
# 启动隧道
anima tunnel start my-webapp
访问地址:http://myapp.anima4.cn
TCP 隧道
# 创建 TCP 隧道
anima tunnel create \
--name my-ssh \
--type tcp \
--local-port 22 \
--remote-port 2222
# 启动隧道
anima tunnel start my-ssh
访问地址:frp.anima4.cn:2222
UDP 隧道
# 创建 UDP 隧道
anima tunnel create \
--name my-game \
--type udp \
--local-port 7777 \
--remote-port 7777
# 启动隧道
anima tunnel start my-game
隧道操作
查看隧道列表
anima tunnel list
输出示例:
NAME TYPE STATUS LOCAL_PORT REMOTE_URL
my-webapp http active 3000 http://myapp.anima4.cn
my-ssh tcp inactive 22 frp.anima4.cn:2222
查看隧道状态
anima tunnel status my-webapp
输出示例:
📊 隧道状态: my-webapp
状态: 活跃
类型: HTTP
本地端口: 3000
远程地址: http://myapp.anima4.cn
运行时间: 2小时30分钟
流量: 128 MB
请求数: 1,234
停止隧道
# 停止特定隧道
anima tunnel stop my-webapp
# 停止所有隧道
anima tunnel stop --all
删除隧道
anima tunnel delete my-webapp
查看日志
实时日志
# 查看特定隧道日志
anima tunnel logs my-webapp
# 查看所有隧道日志
anima tunnel logs --all
日志文件
日志文件位置:~/.anima/logs/
🔧 高级功能
批量操作
# 启动所有隧道
anima tunnel start --all
# 停止所有隧道
anima tunnel stop --all
# 重启所有隧道
anima tunnel restart --all
配置文件模式
创建 ~/.anima/tunnels.toml:
[tunnels.webapp]
type = "http"
local_port = 3000
subdomain = "myapp"
[tunnels.ssh]
type = "tcp"
local_port = 22
remote_port = 2222
[tunnels.api]
type = "http"
local_port = 8080
subdomain = "api"
启动配置文件中的隧道:
anima tunnel start --config ~/.anima/tunnels.toml
环境变量
# 设置环境变量
export ANIMA_TOKEN="your_token_here"
export ANIMA_SERVER="frp.anima4.cn"
# 使用环境变量
anima tunnel create --name my-app --type http --local-port 3000
系统服务
macOS (LaunchAgent)
创建 ~/Library/LaunchAgents/com.anima.client.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.anima.client</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/anima</string>
<string>tunnel</string>
<string>start</string>
<string>--all</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
加载服务:
launchctl load ~/Library/LaunchAgents/com.anima.client.plist
Linux (systemd)
创建 /etc/systemd/system/anima.service:
[Unit]
Description=Anima Client
After=network.target
[Service]
Type=simple
User=anima
ExecStart=/usr/local/bin/anima tunnel start --all
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
启动服务:
sudo systemctl enable anima
sudo systemctl start anima
💡 最佳实践
安全建议
- 使用强密码:为管理后台设置强密码
- 定期更新 Token:定期更换 API Token
- 限制访问:只暴露必要的端口
- 监控日志:定期查看访问日志
性能优化
-
选择合适的隧道类型:
- HTTP:Web 应用
- TCP:数据库、SSH
- UDP:游戏、实时应用
-
合理配置端口:
- 避免使用常用端口
- 使用随机端口减少扫描
-
监控资源使用:
- 定期检查流量使用
- 监控连接数