在 CentOS 中,hosts 文件的位置是固定的,就是:
/etc/hosts
sudo cp /etc/hosts /etc/hosts.bak
sudo vi /etc/hosts
或
sudo nano /etc/hosts
127.0.0.1 localhost
192.168.1.10 test.example.com
sudo systemctl restart network
(CentOS 7/8)
/etc/resolv.conf(那是 DNS 配置)/etc/nsswitch.conf(那是解析顺序)如果你是想用脚本/配置管理替换 hosts(如 Ansible、cloud-init),也可以告诉我场景。