Set System Host Names and Locale on Oracle Linux
Introduction
Whether you run your Oracle Linux system headless or with a desktop environment, you will eventually need to configure the host name and locale for the system. The host name is simply a unique label or name assigned to a computer or device on a network, allowing it to be easily identified and distinguished from other devices. In comparison, the locale setting lets you specify the language for system settings and user interfaces.
Objectives
In this tutorial, you'll learn to:
- Set the system host name
- Set the system locale and system language
Prerequisites
Minimum of a single Oracle Linux system
Each system should have Oracle Linux installed and configured with:
- A non-root user account with sudo access
- Access to the Internet
Deploy Oracle Linux
Note: If running in your own tenancy, read the linux-virt-labs
GitHub project README.md and complete the prerequisites before deploying the lab environment.
Open a terminal on the Luna Desktop.
Clone the
linux-virt-labs
GitHub project.git clone https://github.com/oracle-devrel/linux-virt-labs.git
Change into the working directory.
cd linux-virt-labs/ol
Install the required collections.
ansible-galaxy collection install -r requirements.yml
Deploy the lab environment.
ansible-playbook create_instance.yml -e localhost_python_interpreter="/usr/bin/python3.6"
The free lab environment requires the extra variable
local_python_interpreter
, which setsansible_python_interpreter
for plays running on localhost. This variable is needed because the environment installs the RPM package for the Oracle Cloud Infrastructure SDK for Python, located under the python3.6 modules.The default deployment shape uses the AMD CPU and Oracle Linux 8. To use an Intel CPU or Oracle Linux 9, add
-e instance_shape="VM.Standard3.Flex"
or-e os_version="9"
to the deployment command.Important: Wait for the playbook to run successfully and reach the pause task. At this stage of the playbook, the installation of Oracle Linux is complete, and the instances are ready. Take note of the previous play, which prints the public and private IP addresses of the nodes it deploys and any other deployment information needed while running the lab.
Change the System Host Name
Configuring the system host name in other Linux distributions typically involves editing system files, such as /etc/hostname
and /etc/hosts
, running the hostname
command to set the host name, and finally rebooting the system for the changes to take effect. Oracle Linux simplifies the process through the hostnamectl
command.
Open a terminal and connect via SSH to the ol-node-01 instance.
ssh oracle@<ip_address_of_instance>
Review the system's static and transient host names.
hostnamectl
The static host name is the system's default, and Oracle Linux stores this setting's configuration in the
/etc/hostname
file. It typically contains only letters, numbers, and dashes. The transient host name represents the name that the network sets via services such as DHCP or mDNS after a system boot. The system ignores the transient hostname if the static hostname is set and valid, meaning you have set it to something other than localhost.Change the static and transient host name.
sudo hostnamectl set-hostname my-ol-vm
The transient and static host names are usually identical, but you can use the
--static
or--transient
options to set different values for each. You will notice that the host name does not change at the terminal prompt despite changes at the system level. This value will not change until you log out of the SSH session and reconnect.Set a pretty host name.
This name is optional and allows you to set a host name value that is longer and more descriptive. You can commonly find this name in user interface environments.
sudo hostnamectl set-hostname --pretty "My Oracle Linux Virtual Machine in OCI"
Verify these changes.
hostnamectl
The output now shows both the static and pretty names. For more information, see the
man hostnamectl
manual page.
Update the System Locale and Language
The localectl
command handles the generation of locale and language information. It sets the default system values for users when they log into the system, either through the command line or on a desktop environment. You can also use the command to set default keyboard mappings when physically connected to the system.
Get the current system locale.
localectl
List the available locales.
localectl list-locales
Press the
spacebar
to scroll through the list orq
to exit.Set the locale to British English and UTF-8 encoding.
sudo localectl set-locale en_GB.utf8
The system locale defines the language and character set encoding used to present information on a terminal and many GUI applications. Oracle Linux lists locale options in the format
LANGUAGE_COUNTRY.CODESET[@MODIFIERS]
. TheLANGUAGE
is an ISO 639 language code, for example,en
for English;COUNTRY
is an ISO 3166 country code, for example,GB
for Great Britain and the United Kingdom;CODESET
is the character set or encoding, for example,utf-8
. Thus, in this example, the locale isen_GB.utf8
.List the available keymaps.
localectl list-keymaps
Set the keymap to British English.
sudo localectl set-keymap gb
Verify the applied settings.
localectl status
If you are running locally on the system and using a US English qwerty keyboard, then the " and @ keys should have swapped places. You can also run the
date +%x
command and see the date shown in the DD/MM/YYYY format.However, if you are running from an SSH connection, as in the free lab environment, you will not see any behavioral changes. This behavior occurs because the local Luna Desktop system passes its locale settings through the SSH session to the remote host. The free lab environment uses
LANG=C.UTF-8
andLANGUAGE=en-US,en
as its defaults.Pass a different locale over the SSH session.
To see the local changes over an SSH session, leverage the
LC_ALL
environment variable. This variable will impact only the locale and not change the keymap. If you wish to change the keymap, you must make that change locally in your terminal application on your local host. Only then will SSH copy any local locale characters you type into the remote session, provided it understands the character set. If it does not understand the character set, you will get question marks or other unrecognized characters in the place of your expected character.Remove locale variables from remote users
.bashrc
file.sed -i '/^export\sLC_/d' ~/.bashrc
The free lab environment requires this step. Otherwise, the settings in the
.bashrc
file will override those passed into the session by SSH.Disconnect from the current SSH session.
exit
Reconnect with the new locale.
LC_ALL=en_GB.utf8 ssh oracle@<ip_address_of_instance>
Test the locale.
date +%x
The date output should now display using the DD/MM/YYYY format.
You can configure a locale for a specific session or user. For session-based configurations, set the
LANG
environment variable. Set theLANG
variable on the user's profile or shell configuration for user-based configurations. Thus, the session sets the environment variable each time a user logs into the system.
Next Steps
By completing this tutorial, you'll better understand the host name and locale settings on Oracle Linux. There are more features to explore, so continue your learning by checking out the links below and any of the tutorial's suggested man pages.