【翻译自mos文章】在Oracle Linux7中怎么配置hostname?

在Oracle Linux7中怎么配置hostname?
来源于:
How to Configure hostname in Oracle Linux 7 (文档 ID 2049221.1)

适用于:
Linux OS - Version Oracle Linux 7.0 and later
Linux x86
Linux x86-64

目标:
本文描述了在Oracle Linux7中修改hostname的方法
注意:手工在/etc/sysconfig/network中追加"HOSTNAME=xxxxx"并重启os,这个方法在Oracle Linux7中是不生效的。

解决方案:
请使用如下三种方法的任何一种来修改Oracle Linux7中的主机名

1. use hostname control utility: hsotnamectl
2. use NetworkManager command line tool: nmcli
3. edit /etc/hostname file directly (a reboot afterwards is required)

 

1. Use hsotnamectl which is a command-line client to systemd-hostnamed service

Get current hostname status:

[root@localhost ~]# hostnamectl status
   Static hostname: localhost.localdomain
         Icon name: computer
           Chassis: n/a
        Machine ID: ed264df49f3f42b7b64ca75f763ad117
           Boot ID: 3ec1705218b9499b9619e1bdca7be737
    Virtualization: oracle
  Operating System: Oracle Linux Server 7.1
       CPE OS Name: cpe:/o:oracle:linux:7:1
            Kernel: Linux 3.8.13-55.1.6.el7uek.x86_64
      Architecture: x86_64


Set hostname:

[root@localhost ~]# hostnamectl set-hostname oraclelinux.oracle.com
[root@localhost ~]#


Re-login terminal session:

[root@oraclelinux ~]# hostnamectl status
   Static hostname: oraclelinux.oracle.com
         Icon name: computer
           Chassis: n/a
        Machine ID: ed264df49f3f42b7b64ca75f763ad117
           Boot ID: 3ec1705218b9499b9619e1bdca7be737
    Virtualization: oracle
  Operating System: Oracle Linux Server 7.1
       CPE OS Name: cpe:/o:oracle:linux:7:1
            Kernel: Linux 3.8.13-55.1.6.el7uek.x86_64
      Architecture: x86_64

2. nmcli

Check current hostname:

<span style="color:#000000;TEXT-ALIGN: left; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(224,234,241); TEXT-INDENT: 0px; DISPLAY: inline !important; FONT: 11px 'Courier New', Courier, monospace; WHITE-SPACE: normal; FLOAT: none; LETTER-SPACING: normal; WORD-SPACING: 0px; -webkit-text-stroke-width: 0px">[root@localhost ~]# nmcli general hostname</span><br style="TEXT-ALIGN: left; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; FONT: 11px 'Courier New', Courier, monospace; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px" /><span style="color:#000000;TEXT-ALIGN: left; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(224,234,241); TEXT-INDENT: 0px; DISPLAY: inline !important; FONT: 11px 'Courier New', Courier, monospace; WHITE-SPACE: normal; FLOAT: none; LETTER-SPACING: normal; WORD-SPACING: 0px; -webkit-text-stroke-width: 0px">localhost.localdomain</span>

 

Modify hostname and restart ystemd-hostnamed service:

[root@localhost ~]# nmcli general hostname oraclelinux.oracle.com
[root@localhost ~]# systemctl restart systemd-hostnamed


Re-login terminal session:

[root@oraclelinux ~]# hostname
oraclelinux.oracle.com

 

3. Edit /etc/hostname

View current content:

[root@localhost ~]# cat /etc/hostname
localhost.localdomain


Replace file content with new hostname:

[root@localhost ~]# echo "oraclelinux.oracle.com" > /etc/hostname
[root@localhost ~]# cat /etc/hostname
oraclelinux.oracle.com


Restart system and verify:

[root@oraclelinux ~]# hostname
oraclelinux.oracle.com

你可能感兴趣的:(oracle,linux,hostname,change,modify,7,修改主机名)