hostname

/etc/hostname

显示 /etc/hostname 中配置的 hostname
# hostname
localhost.localdomain

hostnamectl

配置 hostname
# hostnamectl set-hostname master.example.com
# hostnamectl status
   Static hostname: master.example.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: d8bed309f4294655bb32a6fae3d9b8e9
           Boot ID: f6013904460948db93109440302364f8
    Virtualization: kvm
  Operating System: Red Hat Enterprise Linux Server 7.3 (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.3:GA:server
            Kernel: Linux 3.10.0-514.el7.x86_64
      Architecture: x86-64
# cat /etc/hostname
master.example.com

/etc/hosts

/etc/hosts 文件中定义着 IP 地址和域名的映射关系

# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

10.66.192.101 master.example.com

/etc/resolv.conf

当通过 /etc/hosts 不能够完成域名解析时 /etc/resolv.conf 用来完成域名解析。这个文件中定义了一系列域名服务器和search:

# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 8.8.8.8
host HOSTNAME 用来测试 DNS 服务器的连接性
# host master.example.com

案例: 配置 OpenShift master 和 node 节点 hostname

配置 OpenShift master 和 两个 node 节点 hostname 分别为 master.example.com, node1.example.com, node2.example.com,并在 /etc/hosts 中添加映射。

配置 master

hostnamectl set-hostname master.example.com

编辑 /etc/hosts, 添加

10.66.192.101 master.example.com

配置 node1

hostnamectl set-hostname node1.example.com

编辑 /etc/hosts, 添加

10.66.192.102 node1.example.com

配置 node2

hostnamectl set-hostname node2.example.com

编辑 /etc/hosts, 添加

10.66.192.103 node2.example.com

测试配置

master ping 域名
# ping -c3 master.example.com
PING master.example.com (10.66.192.101) 56(84) bytes of data.
64 bytes from master.example.com (10.66.192.101): icmp_seq=1 ttl=64 time=0.049 ms
64 bytes from master.example.com (10.66.192.101): icmp_seq=2 ttl=64 time=0.043 ms
64 bytes from master.example.com (10.66.192.101): icmp_seq=3 ttl=64 time=0.046 ms

--- master.example.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.043/0.046/0.049/0.002 ms
node1 ping 域名
# ping -c3 node1.example.com
PING node1.example.com (10.66.192.102) 56(84) bytes of data.
64 bytes from node1.example.com (10.66.192.102): icmp_seq=1 ttl=64 time=0.042 ms
64 bytes from node1.example.com (10.66.192.102): icmp_seq=2 ttl=64 time=0.052 ms
64 bytes from node1.example.com (10.66.192.102): icmp_seq=3 ttl=64 time=0.050 ms

--- node1.example.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.042/0.048/0.052/0.004 ms
node2 ping 域名
# ping -c3 node2.example.com
PING node2.example.com (10.66.192.103) 56(84) bytes of data.
64 bytes from node2.example.com (10.66.192.103): icmp_seq=1 ttl=64 time=0.055 ms
64 bytes from node2.example.com (10.66.192.103): icmp_seq=2 ttl=64 time=0.055 ms
64 bytes from node2.example.com (10.66.192.103): icmp_seq=3 ttl=64 time=0.056 ms

--- node2.example.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.055/0.055/0.056/0.006 ms

results matching ""

    No results matching ""