服务器重启之后连不上网络
问题说明
- ping www.baidu.com :Name or service not know
- pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fb21e01b978>: Failed to establish a new connection: [Errno -2] Name or service not known’,)': /simple/matplotlib/
解决方法
1. 备份’resolved.conf’文件
sudo cp /etc/systemd/resolved.conf /etc/systemd/resolved.conf.backup
2. 编辑 ‘resolved.conf’ 文件:
sudo nano /etc/systemd/resolved.conf
确保’DNS’行没有注释,并且配置正确。例如:
[Resolve]
DNS=8.8.8.8 8.8.4.4
3. 重启 ‘systemd-resolved’ 服务:
sudo systemctl restart systemd-resolved
4. 更新 ‘/etc/resolv.conf’ 文件:
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
5. 重启网络服务:
sudo systemctl restart networking
6. 重启系统:
sudo reboot
=========================================================================================================
这些步骤旨在确保 systemd-resolved 的配置正确,并且 /etc/resolv.conf 符号链接指向正确的文件。如果问题仍然存在,可能需要更详细地查看系统日志,以获取有关 DNS 解析失败的更多信息。查看 /var/log/syslog 或 /var/log/journal/ 中的相关日志文件。