安装 OpenClash
确保你已经安装了 OpenClash 和相关的依赖项:
sudo apt-get install openclash-dep openclash libpcap-dev
配置 OpenClash
OpenClash 的配置文件通常位于 /etc/openclash/openclash.lua 或者 $HOME/.config/openclash/openclash.lua。
1 设置默认接口
默认接口通常是 eth,但你需要根据你的网络环境设置正确的接口:
-- 设置默认接口为 eth DEFAULT_INTERFACE = "eth"
2 设置收集器 IP 和端口
OpenClash 会作为 NetFlow 数据的收集器,通常使用默认的 ...:20001:
-- 收集器 IP 和端口 collector_ip = "..." collector_port = 20001
3 设置队列大小和其他参数
根据你的网络流量情况调整队列大小和其他参数:
-- 队列大小 queue_size = 100 -- 握手超时 handshake_timeout = 100 -- 最大并发连接数 max_connections = 200
保存并重启 OpenClash
保存配置文件后,重启 OpenClash 服务:
sudo systemctl restart openclash
测试配置
- 运行 OpenClash 并查看日志:
sudo journalctl -u openclash -b
- 确保 OpenClash 正确监听在接口
eth:sudo tcpdump -n "tcp port 20001"
检查防火墙设置
确保防火墙允许 OpenClash 服务运行:
sudo ufw allow out 20001
启用和停止 OpenClash
- 启用 OpenClash:
sudo systemctl enable openclash
- 停止 OpenClash:
sudo systemctl stop openclash
配置示例
以下是一个示例配置文件:
DEFAULT_INTERFACE = "eth" collector_ip = "..." collector_port = 20001 queue_size = 100 handshake_timeout = 100 max_connections = 200 -- 启用 IPv6 支持(如果需要) use_ipv6 = true -- 自定义其他参数 pcap_queue = 1 -- 同时使用多个 pcap 队列 pcap_filter = "tcp port 80 or port 443" -- 可选的过滤规则
其他注意事项
- OpenClash 会使用
libpcap,请确保它已正确安装。 - 如果你在一个高负载的网络环境中,可能需要调整
max_connections和queue_size。 - 如果你需要收集来自多个接口的流量,可以在配置文件中添加额外的接口。
通过以上步骤,你应该能够成功配置 OpenClash 的路由设置,并开始收集和分析网络流量数据。









