Setting the Hostname on Linux

105

I’ve had to do this many times, and have never really found a good, definitive tutorial on this until now. Because of this, I decided to just copy and paste it into my blog in case they take it down at some point.

The following came from: http://www.cpqlinux.com/hostname.html

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"
...


It makes more sense to move this “DHCP_HOSTNAME” variable into /etc/sysconfig/network-scripts/ifcfg-eth0 (or appropriate NIC cfg file). So the above section has been moved, see below. If you have only 1 NIC, then the above struck section works fine, but with more than 1 NIC it makes no sense. Maybe this is true for the “‘HOSTNAME” line too, maybe that line should be moved into /etc/sysconfig/network-scripts/ifcfg-eth0 as well. I will investigate further. By default RHL places HOSTNAME=localhost.localdomain in /etc/sysconfig/network.


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

For Red Hat Linux if you receive your IP address from a DHCP server, you may update the local DNS server by adding the following line to the correct ifcfg file in /etc/sysconfig/network-scripts, such as ifcfg-eth0 or ifcfg-eth1:

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

Filed under Reference by  #

Pings on Setting the Hostname on Linux

1/17/2012
2/3/2012
2/4/2012
2/5/2012
2/6/2012
4/8/2012
5/15/2012
7/11/2012

Comments on Setting the Hostname on Linux Leave a Comment

10/24/2010

leon2k @ 6:14 am #

----

6/15/2011

Ron @ 1:42 am #

----

1/18/2012

Alegro @ 12:26 am #

----

1/21/2012

----

1/22/2012

----

1/23/2012

Desiree Milius @ 6:38 am #

----

1/24/2012

----

1/25/2012

Yon Hosfeld @ 3:43 am #

----

1/26/2012

Leanna Earles @ 1:44 am #

----

1/27/2012

Mildred Sanes @ 4:50 am #

----

1/28/2012

Vanita Oen @ 6:18 am #

----

Chantel Kio @ 5:51 pm #

----

1/30/2012

Elenora Baskin @ 1:55 am #

----

cumberbuns @ 2:10 pm #

----

1/31/2012

Star Clevinger @ 12:49 am #

----

2/1/2012

efterskoleliv @ 3:35 pm #

----

2/2/2012

Efterskole @ 10:35 am #

----

Elisha Hsueh @ 12:57 pm #

----

Peggie Salaza @ 4:39 pm #

----

----

2/3/2012

Rachel Gudis @ 1:41 am #

----

Arla Whan @ 12:34 pm #

----

----

a505392 @ 1:14 pm #

----

----

----

small weddings @ 8:31 pm #

----

----

Szybkozłącza @ 11:11 pm #

----

2/4/2012

----

----

----

zwrot podatku @ 7:06 am #

----

marin bikes @ 9:34 am #

----

----

----

Elias Nieratko @ 1:34 pm #

----

----

zwrot podatku @ 11:31 pm #

----

2/5/2012

Heidy Scaturro @ 12:45 am #

----

----

Shante Uhrich @ 1:44 am #

----

----

Lettie Snowdy @ 12:48 pm #

----

----

----

balustrady @ 4:32 pm #

----

----

sexfotka @ 5:52 pm #

----

----

Marie Kimple @ 5:55 pm #

----

Cherly Selig @ 6:14 pm #

----

----

----

----

Aleen Swanke @ 9:56 pm #

----

Bonita Catino @ 10:53 pm #

----

Son Gately @ 11:02 pm #

----

----

----

----

2/6/2012

zweedse sex @ 12:10 am #

----

----

----

Wava Confrey @ 3:39 am #

----

Seo Las Vegas @ 4:50 am #

----

bayan escort @ 5:18 am #

----

John @ 5:27 am #

----

----

----

----

----

----

----

cliquez ici @ 10:33 am #

----

sex in zwolle @ 11:37 am #

----

Nigel Andreu @ 11:39 am #

----

Shannon Godby @ 11:43 am #

----

----

Online dating @ 12:02 pm #

----

----

Leave a Comment

Fields marked by an asterisk (*) are required.


5 × = ten

Register Login

Switch to our mobile site