Linux 系统配置指南
Linux 系统配置指南
Section titled “Linux 系统配置指南”常用的 Linux 系统配置,包括网络、电源管理、主机名等。
禁用 IPv6
Section titled “禁用 IPv6”sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1编辑 /etc/sysctl.conf:
net.ipv6.conf.all.disable_ipv6=1net.ipv6.conf.default.disable_ipv6=1net.ipv6.conf.lo.disable_ipv6=1应用配置:
sudo sysctl -p /etc/sysctl.conf使用 systemd 的 hostnamectl:
sudo hostnamectl set-hostname NEW_HOSTNAME还需检查以下配置:
- 检查
/etc/hosts:确保没有旧主机名的映射 - 检查
/etc/sysconfig/network:确认HOSTNAME值正确(如果存在)
刷新 DNS 缓存
Section titled “刷新 DNS 缓存”# macOS 10.15+ (Catalina, Big Sur, Monterey, Ventura...)sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder# systemd-resolved(Ubuntu 18.04+)sudo systemd-resolve --flush-caches
# Dnsmasqsudo systemctl restart dnsmasq.service
# NSCD(RedHat 系)sudo systemctl restart nscdWindows
Section titled “Windows”ipconfig /flushdns添加公共 DNS
Section titled “添加公共 DNS”编辑 /etc/resolv.conf:
nameserver 8.8.8.8nameserver 8.8.4.4::: tip Google DNS 延迟较高,建议仅在需要时临时添加。 :::
合盖不休眠(笔记本服务器)
Section titled “合盖不休眠(笔记本服务器)”编辑 /etc/systemd/logind.conf:
HandleLidSwitch=ignore重启服务:
sudo service systemd-logind restart| Ubuntu 版本 | 测试状态 |
|---|---|
| 20.04 | ✅ |
| 18.04 | ✅ |