centos7.6主机名变成bogon的解决办法

今天打开 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 0

lo: 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 0

virbr0: 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 0

virbr0-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.2
Address:	192.168.60.2#53

Non-authoritative answer:
130.60.168.192.in-addr.arpa	name = 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 了!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值