[root@cl-uat-nginx-02 ~]# hostnamectl
Static hostname: cl-uat-nginx-02
Icon name: computer-vm
Chassis: vm
Machine ID: 61e3e73bb37d428ba1e84cd69d27c82e
Boot ID: 99fafe42de7f425a850379232d202fb1
Virtualization: kvm
Operating System: Red Hat Enterprise Linux Server 7.4 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.4:GA:server
Kernel: Linux 3.10.0-693.el7.x86_64
Architecture: x86-64
[root@cl-uat-nginx-02 ~]# cat /etc/sysconfig/network
# Created by anaconda
[root@sit-ntp-service-01 ~]# cat /etc/hostname
sit-ntp-service-01
[root@cl-uat-nginx-02 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=”eth0”
NAME=”eth0”
BOOTPROTO=”dhcp”
ONBOOT=”yes”
STARTMODE=”onboot”
PERSISTENT_DHCLIENT=”yes”
PEERDNS=”no”
[root@cl-uat-nginx-02 ~]#
#!/bin/bash
hostnamectl set-hostname cl-uat-nginx-02
HostName=$HOSTNAME
HostIP=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo "$HostIP" " " "$HostName" >> /etc/hosts
[root@cl-uat-nginx-02 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.182.220.87 cl-uat-nginx-02
[root@cl-uat-nginx-02 ~]#