Linux之如何配置主机名
一、查看当前服务器主机名称
[root@ORCL ~]# hostname
ORCL
二、修改主机名称
2.1 方式1:修改/etc/hostname文件,需要重启。
[root@ORCL ~]# vi /etc/hostname
2.2 方式2:hostnamectl命令修改,不需要重启
[root@ORCL ~]# cat /etc/hostname
ORCL
[root@ORCL ~]# hostnamectl set-hostname ORCL1
[root@ORCL ~]# hostname
orcl1
[root@ORCL ~]# cat /etc/hostname
orcl1
三、修改linux的主机映射文件
由于虚拟机比较多,配置时通常会采用主机名的方式配置,比较简单方便,不用刻意记ip地址。
//编辑 /etc/hosts
[root@ORCL ~]# vi /etc/hosts
这样我们就可以通过 ORCL 来访问 192.168.198.142 这台机器了,比如 ping ORCL 效果如下,自动根据名称在 /etc/hosts 文件中找到对应的ip.
[root@ORCL ~]# ping ORCL
PING ORCL (192.168.198.142) 56(84) bytes of data.
64 bytes from ORCL (192.168.198.142): icmp_seq=1 ttl=64 time=0.032 ms
64 bytes from ORCL (192.168.198.142): icmp_seq=2 ttl=64 time=0.045 ms
64 bytes from ORCL (192.168.198.142): icmp_seq=3 ttl=64 time=0.040 ms
window上也也有这种文件,对应的位置如下:
路径为:C:\Windows\System32\drivers\etc\hosts