Looking Glass 网络测试工具教程

Looking Glass(LG)是一种网络诊断平台,通常由 ISP、IDC 和 VPS 提供商部署,允许用户通过 Web 界面远程执行 ping、traceroute、MTR 和 BGP 路由查询等网络测试操作。搬瓦工等 VPS 提供商也提供 Looking Glass 服务。本文将介绍 Looking Glass 的使用方法,以及如何在自己的搬瓦工 VPS 上搭建一个 Looking Glass 平台。

一、什么是 Looking Glass

Looking Glass 的核心功能包括:

  • Ping 测试:从服务器向指定目标发送 ICMP 包,测试延迟和丢包。
  • Traceroute:追踪数据包从服务器到目标的路由路径。
  • MTR:结合 ping 和 traceroute 的功能,持续监测每一跳的延迟和丢包。
  • BGP 路由查询:查看 BGP 路由表中到特定前缀的路由信息。
  • 测速文件:提供不同大小的测试文件供用户下载测速。

二、使用现有的 Looking Glass

在搭建自己的 Looking Glass 之前,可以先使用公开的 LG 平台来测试网络质量。很多主机商和网络运营商都提供 Looking Glass 服务,通过浏览器即可访问,输入目标 IP 或域名就能从对方的网络节点发起测试。

三、搭建 Telephone Looking Glass

Telephone 是一个轻量级的 PHP Looking Glass 项目,适合在搬瓦工 VPS 上快速部署。

3.1 安装依赖

apt update
apt install nginx php-fpm php-cli git mtr-tiny traceroute -y

3.2 下载项目

cd /var/www
git clone https://github.com/telephone/LookingGlass.git
cd LookingGlass

3.3 运行配置脚本

# 运行配置向导
bash configure.sh

配置向导会询问以下信息:站点标题、服务器位置、测速文件大小、速率限制等。根据需要填写即可。

3.4 配置 Nginx

cat > /etc/nginx/sites-available/looking-glass <<'EOF'
server {
    listen 80;
    server_name lg.example.com;
    root /var/www/LookingGlass;
    index index.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }
}
EOF

ln -s /etc/nginx/sites-available/looking-glass /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx

四、搭建 Hybula Looking Glass

Hybula 是一个现代化的 Looking Glass 项目,界面美观,功能完善。

4.1 安装依赖

apt install nginx php8.1-fpm php8.1-cli php8.1-xml composer mtr-tiny traceroute -y

4.2 安装 Hybula LG

cd /var/www
git clone https://github.com/hybula/lookingglass.git
cd lookingglass
composer install --no-dev

4.3 配置

# 复制配置模板
cp config.dist.php config.php

# 编辑配置文件
nano config.php

主要配置项包括:

<?php
return [
    'site_name' => 'My Looking Glass',
    'site_url'  => 'https://lg.example.com',
    'location'  => 'Los Angeles, US',
    'ipv4'      => '1.2.3.4',
    'ipv6'      => '2001:db8::1',
    'test_files' => [100, 1000],
    'rate_limit' => 10,
];

4.4 生成测速文件

# 生成 100MB 和 1000MB 的测试文件
dd if=/dev/zero of=/var/www/lookingglass/public/test/100MB.test bs=1M count=100
dd if=/dev/zero of=/var/www/lookingglass/public/test/1000MB.test bs=1M count=1000

五、搭建 Bird-lg 路由查询平台

如果你运行了 BGP 路由服务(如 BIRD),可以搭建 Bird-lg 提供 BGP 路由查询功能。

5.1 安装 Bird-lgproxy

# 安装 Go 环境
apt install golang -y

# 安装 bird-lgproxy
go install github.com/xddxdd/bird-lgproxy-go@latest

# 运行代理
bird-lgproxy-go --listen 127.0.0.1:8000 --bird /run/bird/bird.ctl

5.2 安装 Bird-lg 前端

go install github.com/xddxdd/bird-lg-go@latest

# 运行前端
bird-lg-go --listen 0.0.0.0:5000 --servers "node1,node2" --domain "lg.example.com"

六、配置 MTR 测试

# 确保 mtr 已安装
apt install mtr-tiny -y

# 允许非 root 用户使用 mtr
chmod u+s /usr/bin/mtr-packet

七、安全配置

Looking Glass 平台需要特别注意安全性,防止被滥用:

# 限制请求频率(Nginx 配置)
http {
    limit_req_zone $binary_remote_addr zone=lg:10m rate=5r/m;

    server {
        location /api/ {
            limit_req zone=lg burst=3 nodelay;
        }
    }
}
  • 设置速率限制,防止 DDoS 攻击。
  • 限制可查询的 IP 范围,禁止查询内网地址。
  • 使用 HTTPS 加密传输。
  • 记录所有查询日志以便审计。

八、常见问题

8.1 traceroute 无输出

# 确保 traceroute 工具已安装
apt install traceroute -y

# 检查权限
ls -la /usr/bin/traceroute

8.2 测速文件下载速度不准确

确保 Nginx 配置中没有开启 gzip 压缩,否则全零的测试文件会被高度压缩,导致测速结果不准确:

# 对测试文件禁用 gzip
location /test/ {
    gzip off;
}

总结

Looking Glass 是网络服务提供商展示网络质量的标准工具,也是运维人员进行网络诊断的利器。在搬瓦工 VPS 上搭建 Looking Glass 可以方便地对外展示你的网络质量。更多网络监控工具可以参考 SmokePing 延迟监控教程LibreNMS 网络监控教程。选购搬瓦工 VPS 请参考 全部方案,购买时使用优惠码 NODESEEK2026 可享受 6.77% 的优惠,通过 bwh81.net 进入官网购买。

关于本站

搬瓦工VPS中文网(bwgvps.com)是非官方中文信息站,整理搬瓦工的方案、优惠和教程。我们不销售主机,不提供技术服务。

新手必读
搬瓦工优惠码

NODESEEK2026(优惠 6.77%)

购买时填入即可抵扣。