首页 > 编程知识 正文

centos76安装详细解,主机名是什么

时间:2023-05-06 04:15:20 阅读:222632 作者:2399

今天打开 centos 发现主机名变成了 bogon,解决方法如下:

1、查看主机 IP 地址 ifconfig -a

结果:

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.60.130 netmask 255.255.255.0 broadcast 192.168.60.255 inet6 fe80::dca3:beae:898a:77d4 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:15:ed:6c txqueuelen 1000 (Ethernet) RX packets 642 bytes 234562 (229.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 642 bytes 77386 (75.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 66 bytes 5668 (5.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 66 bytes 5668 (5.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:42:73:68 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether 52:54:00:42:73:68 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 2、 对主机 IP 地址进行解析 nslookup 192.168.60.130

结果:

Server:192.168.60.2Address:192.168.60.2#53Non-authoritative answer:130.60.168.192.in-addr.arpaname = bogon.Authoritative answers can be found from:

结果显示:本机的 IP 地址被解析成了 bogon

3、解决方法

解析时不经过 DNS,使用 hosts 文件,直接将本机的 IP 地址解析为本地主机。

执行以下命令:

sudo vi /etc/hosts

显示为:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

编辑 hosts 文件,在最后一行添加如下信息:

192.168.60.130 localhost

保存并退出。

4、重启centos

重启后打开终端,会发现,主机名又变回 localhost 了!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。