Change Hostname

From INIwiki
Jump to: navigation, search

Checking your Linux host name First, see if your host name is set correctly 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.

Contents

[edit] Configuring /etc/hosts

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

vi /etc/hosts
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

[edit] Using Hostname

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

[edit] Resolve.conf

Checking /etc/resolv.conf (if needed - not dhcp)

vi /etc/resolv.conf
search mydomain.com

[edit] Sysconfig Settings

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

vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME="mybox.mydomain.com"
vi /etc/sysconfig/network-scripts/ifcfg-eth*
HOSTNAME="mybox.mydomain.com"

[edit] 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

Updated information about ddns:

Kill the dhclient process ("killall dhclient") - make sure it is gone
Then restart networking - "service network restart"

Updated information for ddns on Gentoo:

killall dhclient

Edit /etc/conf.d/net uncomment and modify the line as follows:

dhcpcd_eth0="-h yourhostname"

reboot or restart your network subsystem

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

[edit] Changing the hostname while in X-Windows

Changing the hostname while in X-Windows can be problematic. Most often, new windows cannot be opened. Either 1. change the hostname while the X-Windows is not running or 2. in X-Windows change the hostname, then restart X-Windows.


[edit] Source:

http://www.cpqlinux.com/hostname.html
Personal tools