在 Debian 里替换 hosts 文件(通常是 /etc/hosts)有几种常见方式,下面按安全、常用的顺序说明。
sudo cp /etc/hosts /etc/hosts.bak
sudo nano /etc/hosts
或
sudo vim /etc/hosts
Ctrl + O 保存,Ctrl + X 退出:wq 保存退出如果你已经有一个写好的 hosts 文件,比如 new_hosts:
sudo cp new_hosts /etc/hosts
⚠️ 注意:这会完全覆盖原文件。
只添加一条解析:
echo "127.0.0.1 example.com" | sudo tee -a /etc/hosts
Debian 若使用 systemd-resolved:
sudo systemctl restart systemd-resolved
127.0.0.1 localhost
127.0.1.1 debian
192.168.1.10 nas.local
/etc/hosts 属于 rootsudo如果你是想:
可以告诉我具体场景,我给你更合适的方案。