Setting the Hostname on Linux

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

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

105 comments on this post.
  1. leon2k:

    ----

  2. Ron:

    ----

  3. Ip Address Definition? | Free Hide My IP Address:

    ----

  4. Alegro:

    ----

  5. Gwendolyn Krumme:

    ----

  6. Perla Bilderback:

    ----

  7. Desiree Milius:

    ----

  8. Kanesha Stimmell:

    ----

  9. Yon Hosfeld:

    ----

  10. Leanna Earles:

    ----

  11. Mildred Sanes:

    ----

  12. Vanita Oen:

    ----

  13. Chantel Kio:

    ----

  14. Elenora Baskin:

    ----

  15. cumberbuns:

    ----

  16. Star Clevinger:

    ----

  17. efterskoleliv:

    ----

  18. beyin tümörü belirtileri:

    ----

  19. Efterskole:

    ----

  20. Elisha Hsueh:

    ----

  21. Peggie Salaza:

    ----

  22. Teknoloji Haberleri:

    ----

  23. kolon kanseri belirtileri:

    ----

  24. Rachel Gudis:

    ----

  25. Arla Whan:

    ----

  26. Przewody hydrauliczne:

    ----

  27. a505392:

    ----

  28. I've said that least 505392 times:

    ----

  29. Gaming Fun:

    ----

  30. oil painting reproductions:

    ----

  31. Further Games:

    ----

  32. baccarat online:

    ----

  33. araç Kiralama:

    ----

  34. Personal Injury Lawyers in Philadelphia:

    ----

  35. small weddings:

    ----

  36. kız oyunları:

    ----

  37. Szybkozłącza:

    ----

  38. Real Estate Seminole County:

    ----

  39. Jackeline Willson:

    ----

  40. modern-rug.co.uk:

    ----

  41. neues handy kaufen:

    ----

  42. Internet Games:

    ----

  43. zwrot podatku:

    ----

  44. Cheap Bicycling Jerseys:

    ----

  45. Net Game:

    ----

  46. marin bikes:

    ----

  47. Marlene Janousek:

    ----

  48. LittleBlueKangaroo:

    ----

  49. Play Game:

    ----

  50. Elias Nieratko:

    ----

  51. zwrot podatku holandia:

    ----

  52. zwrot podatku:

    ----

  53. Heidy Scaturro:

    ----

  54. zwrot podatku holandia:

    ----

  55. Shante Uhrich:

    ----

  56. AIR DOCTOR INC. AIR CONDITIONING and HEATING REPAIR:

    ----

  57. Nikon D5100 vs Canon T3i:

    ----

  58. Triglyceride Levels:

    ----

  59. Lettie Snowdy:

    ----

  60. Wasserbetten Test:

    ----

  61. Cartoni animati musicali:

    ----

  62. blouson swimsuits:

    ----

  63. balustrady:

    ----

  64. odchudzanie tabletki:

    ----

  65. Good Games:

    ----

  66. sexfotka:

    ----

  67. seo company naples:

    ----

  68. Marie Kimple:

    ----

  69. Cherly Selig:

    ----

  70. Cortney Strausner:

    ----

  71. website directory:

    ----

  72. car insurance washington:

    ----

  73. Vitamins for Wellness:

    ----

  74. Aleen Swanke:

    ----

  75. Bonita Catino:

    ----

  76. Son Gately:

    ----

  77. ereksiyon hapı:

    ----

  78. barriere de securite:

    ----

  79. DIY Renewable Energy:

    ----

  80. zweedse sex:

    ----

  81. Micro Memory card:

    ----

  82. Terence Monteverde:

    ----

  83. Wava Confrey:

    ----

  84. fernseher kaufen online:

    ----

  85. Seo Las Vegas:

    ----

  86. bayan escort:

    ----

  87. John:

    ----

  88. odchudzanie tabletki:

    ----

  89. gibson les paul dc:

    ----

  90. clip on chandelier:

    ----

  91. Willodean Cristofaro:

    ----

  92. Financial Adviser:

    ----

  93. tabletki na odchudzanie:

    ----

  94. Electronic cigarette:

    ----

  95. cliquez ici:

    ----

  96. sex in zwolle:

    ----

  97. Nigel Andreu:

    ----

  98. Shannon Godby:

    ----

  99. dover electrician:

    ----

  100. rest assured mattresses:

    ----

  101. Online dating:

    ----

  102. Orlando Short Sale:

    ----

  103. Massagetekniker:

    ----

  104. Immobilien Glarus:

    ----

  105. Linux hostname | Algebratesting:

    ----

Leave a comment






− 1 = two