How to configure the hostname in Oracle Linux7?
How to configure the hostname in Oracle Linux7?
Source:
How to Configure hostname in Oracle Linux 7 (Document ID 2049221.1)
Applicable:
Linux OS-Version Oracle Linux 7.0 and later
Linux x86
Linux x86-64
Objectives:
This document describes how to modify the hostname in Oracle Linux7.
Note: manually APPEND "HOSTNAME = xxxxx" to/etc/sysconfig/network and restart OS. This method does not take effect in Oracle Linux7.
Solution:
Use either of the following three methods to modify the host name in 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 Use EMD-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