Debian LAMP网络问题排查与修复指南
一、快速定位问题类型
ss -tulpen | grep -E ':(80|443)' 查看监听与进程。systemctl status apache2、systemctl status mysql、systemctl status php*-fpm,并查看对应错误日志(Apache:/var/log/apache2/error.log;MySQL:/var/log/mysql/error.log;PHP-FPM:常见为 /var/log/php*-fpm.log)。top/htop、free -m、df -h、iotop 排查 CPU/内存/磁盘IO 是否耗尽。二、从链路到DNS的分层排查
ip a 看接口是否 UP;必要时用 ethtool eth0 检查 链路状态(Link detected: yes/no)。ip route 确认是否存在 default via 网关IP dev 接口;若缺失,临时添加:sudo ip route add default via 192.168.1.1 dev eth0。ping 网关IP,再 ping 8.8.8.8(纯IP测试);若IP通而域名不通,转向DNS。/etc/resolv.conf 是否有 nameserver;用 nslookup example.com、dig example.com 验证;若被覆盖,需做持久化DNS配置。traceroute 8.8.8.8 或 mtr 8.8.8.8 定位丢包/高延迟节点。ss -tulpen 校验监听。三、Debian网络与服务恢复操作
sudo systemctl status NetworkManager;sudo systemctl status networking;sudo systemctl status systemd-networkd。sudo systemctl restart NetworkManager 或 nmcli connection reload;sudo systemctl restart networking 或 sudo /etc/init.d/networking restart;sudo systemctl restart systemd-networkd;sudo ip link set eth0 down && sudo ip link set eth0 up(接口名以 ip a 为准)。sudo ufw status、sudo ufw allow 80,443/tcp、sudo ufw reload;sudo firewall-cmd --list-all、sudo firewall-cmd --permanent --add-service=http --add-service=https && sudo firewall-cmd --reload;sudo systemctl restart apache2sudo systemctl restart mysqlsudo systemctl restart php*-fpm(按实际版本,如 php8.2-fpm)四、LAMP场景的典型问题与处理
ss -tulpen | grep -E ':(80|443|3306)' 检查;若端口冲突,调整服务端口或停用占用进程;确认云安全组与防火墙放行。mysql -u root -p;远程连接需授权并开放 3306(仅在可信网络)。五、配置与验证的实用建议
.network 文件;sudo netplan apply。/etc/resolv.conf,在相应网络管理方式中配置 DNS 或在 /etc/resolvconf/resolv.conf.d/base 写入 nameserver 8.8.8.8 后执行 sudo resolvconf -u。ping -c 4 网关IP、ping -c 4 8.8.8.8、nslookup example.com;ss -tulpen | grep -E ':(80|443|3306)';systemctl is-active apache2 mysql php*-fpm;curl -I https://你的域名。