Terry : Hostname

How to change Linux hostname

Debian based distributions (Debian GNU/Linux, Ubuntu)

Edit /etc/hostname

Arch Linux

Change hostname temporarily until next reboot

sudo hostname newhostname

Edit /etc/rc.conf which is the core system configuration file for Arch Linux, for example:

# -----------------------------------------------------------------------
# NETWORKING
# -----------------------------------------------------------------------
#
# HOSTNAME: Hostname of machine. Should also be put in /etc/hosts
#
HOSTNAME="myhost"

# Use 'ifconfig -a' or 'ls /sys/class/net/' to see all available interfaces.
#
# Interfaces to start at boot-up (in this order)
# Declare each interface then list in INTERFACES
#   - prefix an entry in INTERFACES with a ! to disable it
#   - no hyphens in your interface names - Bash doesn't like it
#
# DHCP:     Set your interface to "dhcp" (eth0="dhcp")
# Wireless: See network profiles below
#
eth0="eth0 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255"
INTERFACES=(eth0)

# Routes to start at boot-up (in this order)
# Declare each route then list in ROUTES
#   - prefix an entry in ROUTES with a ! to disable it
#
gateway="default gw 192.168.1.1"
ROUTES=(!gateway)

# Enable these network profiles at boot-up.  These are only useful
# if you happen to need multiple network configurations (ie, laptop users)
#   - set to 'menu' to present a menu during boot-up (dialog package required)
#   - prefix an entry with a ! to disable it
#
# Network profiles are found in /etc/network.d
#
# This now requires the netcfg package
#
#NET_PROFILES=(main)

After systemd came into picture, configuration has changed.

Set hostname in /etc/hostname

Enable Networking (DHCP)

sudo systemctl enable dhcpcd.service

Red Hat Enterprise Linux, Oracle Linux, CentOS

Edit /etc/sysconfig/network or change through Network configuration UI

NETWORKING=yes
HOSTNAME=linux.au.oracle.com

Change hostname on the fly (Kernel 2.6+)

Changed made directly to the kernel's pseudo file system, no network restart required.

sudo echo "newhostname" > /proc/sys/kernel/hostname