温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

命令行界面如何调试网络

发布时间:2026-11-03 13:34:35 来源:亿速云 阅读:96 作者:小樊 栏目:系统运维

在命令行界面(CLI)下调试网络,通常依赖一组系统自带或常见的网络诊断命令。下面按常见场景 + 对应命令 + 示例来梳理,适用于 Linux / macOS / Windows(CMD/PowerShell 大多通用)。


一、基础连通性测试

1. ping —— 测试是否能到达目标

ping example.com
ping 8.8.8.8

✅ 通:网络层基本正常
❌ 不通:可能是 DNS、路由、防火墙问题

Windows 默认发 4 个包,Linux 用 Ctrl+C 停止


2. telnet / nc —— 测试端口是否开放

telnet example.com 80
nc -vz example.com 443

用于判断:

  • 服务是否监听
  • 防火墙是否拦截端口

Windows 10+ 可能需先启用 telnet


二、DNS 调试

3. nslookup

nslookup example.com

查看域名解析结果和 DNS 服务器

4. dig(Linux / macOS)

dig example.com
dig @8.8.8.8 example.com

5. host

host example.com

三、路由与路径分析

6. traceroute / tracert

traceroute example.com     # Linux/macOS
tracert example.com        # Windows

查看数据包经过的跳数和卡在哪一层


7. route / ip route

route -n
ip route

查看本机路由表,确认默认网关是否正确


四、网络接口与配置

8. ifconfig / ip

ifconfig
ip addr

查看 IP、子网掩码、MAC

9. ip link

ip link

查看网卡状态(up/down)


五、连接与进程排查

10. netstat

netstat -antp

查看:

  • 已建立连接
  • 监听端口
  • 对应进程(Linux)

11. ss(更现代)

ss -antp

12. lsof

lsof -i :80

查看谁占用了某个端口


六、抓包分析(高级)

13. tcpdump(Linux)

tcpdump -i eth0 port 80

14. Wireshark(CLI 版)

tshark -i eth0

七、常见排查思路(实战流程)

  1. 本机 IP 是否正常
    ip addr
    
  2. 网关是否通
    ping 网关IP
    
  3. 外网是否通
    ping 8.8.8.8
    
  4. DNS 是否解析
    nslookup example.com
    
  5. 端口是否开放
    nc -vz example.com 80
    
  6. 路由是否异常
    traceroute example.com
    

八、Windows 专用小技巧

ipconfig /all
ipconfig /flushdns
netsh interface show interface

如果你有具体场景(如:

  • 服务器连不上
  • Docker 网络问题
  • 内网不通
  • HTTPS 无法访问)

可以告诉我,我可以给你针对性的命令组合。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI
助
手