Setting the Linux Host Name

Setting the Linux Host Name

   

This post was last updated on May 26th, 2020 at 10:28 pm

Checking your Linux host name

First, see if your host name is set correclty using the following commands:

uname -n
hostname -a
hostname -s
hostname -d
hostname -f
hostname

If the above commands return correctly with no errors then all may be well;
however, you may want to read on to verify that all settings are correct.


Configuring /etc/hosts

If your IP address is assigned to you by a DHCP server, then /etc/hosts is configured as follows:

127.0.0.1	mybox.mydomain.com	localhost.localdomain localhost mybox

If you have a static IP address, then /etc/hosts is configured as follows:

127.0.0.1	localhost.localdomain localhost
192.168.0.10	mybox.mydomain.com	mybox


Setting the Host Name using “hostname”

After updating the /etc/hosts file correctly, the “hostname” command should be run as follows to set your hostname:

hostname mybox.mydomain.com


Checking /etc/HOSTNAME (if present)

You may or may not have the file /etc/HOSTNAME:

mybox.mydomain.com


Checking /etc/sysconfig/network

If you have a static IP address, then /etc/sysconfig/network is configured as follows:

NETWORKING=yes
HOSTNAME="mybox.mydomain.com"
...

If your IP address is assigned to you by a DHCP server, and you wish to update the local DNS server through Dynamic DNS, then /etc/sysconfig/network is configured as follows:

NETWORKING=yes
HOSTNAME="mybox.mydomain.com"
DHCP_HOSTNAME="mybox.mydomain.com"
...


Checking /proc/sys/kernel/hostname

This is checked with the following command:

cat /proc/sys/kernel/hostname

If you need to set this file, you can either reboot or set it now with the following command:

echo mybox.mydomain.com > /proc/sys/kernel/hostname


Dynamic DNS – Updating the local DNS server with your host name and DHCP IP

If you receive your IP address from a DHCP server, you may update the local DNS server by adding the following line to /etc/sysconfig/network for Red Hat:

DHCP_HOSTNAME="mybox.mydomain.com"

or if running Debian, edit /etc/network/interfaces as follows (adding the hostname line):

iface eth0 inet dhcp
    hostname mybox.mydomain.com

For more info in Debian, see “man interfaces” and scroll down to”The dhcp Method”.


WINS – Updating the local WINS server with your host name and IP

If you wish to update the local WINS server, then use SAMBA, and configure it to point to the local WINS server. samba.html
i.e. update the /etc/samba/smb.conf “wins server = ” entry with the WINS server addresses for your network – be sure not to enable “wins support = yes” as that will make Linux a WINS server.


prev next index


Previous Here we will walk through setting up a new server and explain what is going on along the way
Next How to Capture Boot Time Error Messages

About author

Sibananda Sahu
Sibananda Sahu 154 posts

A Linux Kernel Developer and a Firmware Developer by profession. Have worked with few big companies: BROADCOM Corporation, Cypress Semiconductor, LSI Corporation, TOSHIBA Corporation, Western Digital; on various cutting edge technologies and product lines, such as: RAID storage Driver, SSD Firmware, WLAN Firmware etc. Having more than 9 years of experience in Software Engineering domain. Now, took a pledge to educate all aspirant students to teach about Linux Kernel Development.

View all posts by this author →

You might also like

FreeBSD Topics 0 Comments

How To Add Or Remove A User In FreeBSD?

This post was last updated on August 1st, 2020 at 12:13 pmFreeBSD is a free and open-source Unix-like operating system descended from the Berkeley Software Distribution. It is used to

How To 0 Comments

Kickstarter

This post was last updated on July 9th, 2020 at 01:54 pmks.cfg stuff: http://www.cpqlinux.com/ks-getting-started.html ks-merged-ks.cfg.html – A kickstart that works for 7.2, AS2.1, 7.3, 8.0, and 9 ks-create-merged-ks.cfg.sh.html – This

How To 0 Comments

Setting the Date and Time in Linux

This post was last updated on June 1st, 2020 at 01:46 amYou have at least 2 methods for setting the date and time in Linux: You can set the time

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply