在Oracle Linux7中怎麼配置hostname?

來源:互聯網
上載者:User

在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: hsotnamectl2. use NetworkManager command line tool: nmcli3. 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:

[[email protected] ~]# 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:

[[email protected] ~]# hostnamectl set-hostname oraclelinux.oracle.com[[email protected] ~]#


Re-login terminal session:

[[email protected] ~]# 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:

[[email protected] ~]# nmcli general hostnamelocalhost.localdomain

 

Modify hostname and restart ystemd-hostnamed service:

[[email protected] ~]# nmcli general hostname oraclelinux.oracle.com[[email protected] ~]# systemctl restart systemd-hostnamed


Re-login terminal session:

[[email protected] ~]# hostnameoraclelinux.oracle.com

 

3. Edit /etc/hostname

View current content:

[[email protected] ~]# cat /etc/hostnamelocalhost.localdomain


Replace file content with new hostname:

[[email protected] ~]# echo "oraclelinux.oracle.com" > /etc/hostname[[email protected] ~]# cat /etc/hostnameoraclelinux.oracle.com


Restart system and verify:

[[email protected] ~]# hostnameoraclelinux.oracle.com

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.