温馨提示×

centos怎样删除域名

小樊
42
2026-10-08 16:37:44
栏目: 云计算

在 CentOS 中“删除域名”通常有以下几种常见场景,你可以按需选择:


一、删除本地 hosts 文件中的域名解析

如果你在 /etc/hosts 里手动绑定过域名:

vi /etc/hosts

找到类似:

192.168.1.100 example.com

删除该行,保存退出即可。


二、删除 NetworkManager / 系统主机名中的域名

1. 查看当前主机名和域名

hostname
hostname -f

2. 修改主机名(去掉域名部分)

hostnamectl set-hostname your-hostname

例如:

hostnamectl set-hostname centos

三、删除 DNS 配置的搜索域(search domain)

如果是通过网卡配置设置的域名(如 search example.com):

方法 1:修改网卡配置

vi /etc/sysconfig/network-scripts/ifcfg-eth0

删除或注释:

DOMAIN=example.com

然后重启网络:

systemctl restart network

(CentOS 8 可用 nmcli 或 NetworkManager)

方法 2:修改 /etc/resolv.conf

vi /etc/resolv.conf

删除:

search example.com

⚠️ 注意:若由 NetworkManager 管理,resolv.conf 可能被自动覆盖。


四、删除 Nginx / Apache 中的域名站点

Nginx

rm -f /etc/nginx/conf.d/example.com.conf
systemctl restart nginx

Apache

rm -f /etc/httpd/conf.d/example.com.conf
systemctl restart httpd

五、删除防火墙中放行的域名(如用了 firewalld + dns)

一般防火墙不直接“绑定域名”,若你是指端口或富规则:

firewall-cmd --list-all
firewall-cmd --remove-service=http --permanent
firewall-cmd --reload

如果你能具体说明:

  • 是 系统域名 / hosts / DNS / Web 服务 / 邮件服务
  • CentOS 版本(7 / 8 / Stream)

我可以给你更精确的命令。

0 踩