Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Maximum hostname length

News Networking Recommended Books Recommended Links hostname nslookup dig - DNS lookup utility
DNS Tools Troubleshooting Perl Tools History Tips Humor Etc

This is mainly a Unix kernel related issue related to the length of particular string in one of kernel structures. But applications might also have problem if they reserve only eight character string (applications usually use DNS, not hostname, but Unix scripts often use hostname command and $HOSTNAME variable without full understanding that it can be a long, up to 64 bytes string).

It is very similar to Year 2000 problem: most modern Unixes work OK with long hostnames but risks remains.

Generally it is prudent to limit hostnames to 8 characters if possible and to use DNS aliases with longer names. One exception is Oracle which for some reason prefers fully qualified names as hostname. RHEL supports such behavior by default.

This is mainly a Unix kernel related issue related to the length of particular string in one of kernel structures. But applications might also have problem if they reserve only eight character string.

Same considerations:

This is like year 2000 problem. It might well be exaggerated but that does not mean that it does not exist. Unix is a legacy system and if you exceed legacy limits you might be punished, no matter what new standard say (POSIX standard specifies 255 characters, but only Solaris currently supports it).

No amount of Internet search will give us correct estimate of the risk. The danger is that such errors are very subtle. Like complex routing problems they can demonstrate itself in a way we will not even understand that this is hostname length related problem.

Unless absolutely necessary you should generally avoid using hostnames longer then eighth characters as a matter of policy. Here is one good advice from the Net

For compatibility sake with other systems, no matter how long the OS states the hostname can be you do not want to exceed 8 characters.

Even some of the newer systems coming out have hard limits built in to help the windows people conform to the standards, instead of defining their own. again........

if you need long names, setup DNS and make good domain/sub-domain names. This way legacy systems and systems that support only 8 characters can still function

Here are a few systems not supporting more than 8 characters.


Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

Linux Maximum Length Of A Host Name

Jeff Schroeder

This is one that you are actually wrong on.

The Single Unix Specification version 2 (SuSv2) guarantees 'Host names are limited to 255 bytes'.

POSIX 1003.1-2001 guarantees 'Host names (not including the terminating NULL) are limited to HOST_NAME_MAX bytes'.

$ grep HOST_NAME_MAX /usr/include/bits/local_lim.h
#define HOST_NAME_MAX 64

$ getconf HOST_NAME_MAX
64

This is part of the c library you use and libc defaults to 64. Changing your kernel and recompiling would still give you a max hostname size of 64 characters including the null termination byte at the end.

maximum hostname length in linux - Ars Technica OpenForum

Short answer: 64 bytes.

Long answer: in Linux, the hostname is stored in the nodename field of the utsname structure for the current namespace. For all versions of Linux that I am aware of (say, since 1994 or so) the length of that field is 65 bytes (meaning, 64 chars terminated by a 0). In order to increase it, you will need to, at the very least:
1. change __NEW_UTS_LEN in include/linux/utsname.h to whatever number you need;
2. change the sizes of the fields in the old_utsname and new_utsname structs to __NEW_UTS_LEN + 1
3. recompile the kernel
4. replace /usr/include/linux/utsname.h with the new version
5. recompile glibc to use the modified linux/utsname.h
6. make sure that /usr/include/bits/utsname.h has _UTSNAME_LENGTH set to the right value (recompiling glibc should take care of this, probably)
7. recompile all programs and libraries that include /usr/include/sys/utsname.h, /usr/include/bits/utsname.h, or /usr/include/linux/utsname.h, or that use functions or constants or structs defined in those header files.
8. and if you run closed-source software, you are kinda stuck.

quote:

http://refspecs.freestandards.org/LSB_2.0.1/LSB-Core/LSB-Core.html

Maximum length of a host name (not including the terminating null) as returned from the gethostname function shall be at least 255 bytes.

tetromino

Ars Centurion

quote:

Originally posted by Linux_Biz:
then steps no; 3 to 8 , i am saying sorry, i dont know how to follow.

To be perfectly honest, I don't know what's the best way to follow them either. For one thing, it would probably be dangerous to run a glibc that uses one definition of utsname on a kernel that uses a different definition. The safest approach would be to compile a new livecd that uses the large utsname, using something like Gentoo's catalyst tool, and use that to reinstall your entire operating system. Essentially, you will need to maintain your own fork of some existing distro.

It's not a trivial undertaking. If you aren't comfortable with Linux innards, in particular if you don't know how to compile your own kernel, you really should go for a workaround -- maybe DNS aliases, like kperrier suggested.

And those people that think Linux supports 255 byte hostnames, try the following as root:

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

char oldname[65];
char name[256];

int main() {
memset(name, 'x', 256);
if(!gethostname(oldname, 65))
printf("Saving your current hostname (%s)...\n",oldname);
if(!sethostname(name, 64))
printf("64 bytes works :)\n");
if(sethostname(name, 65))
perror("65 bytes is too long");
if(sethostname(name, 255))
perror("255 bytes is too long");
if(!gethostname(name, 255))
printf("Hostname successfully set to %s (%d bytes)\n", name, strlen(name));
if(!sethostname(oldname, strlen(oldname)))
printf("Restored your hostname to %s\n", oldname);
return 0;
}

linux_biz
what is the default length in redhat liunx? 65 or 256?

tetromino

@Linux_Biz:
copy the code in my post above, compile with gcc, and run the resulting executable as root. If it says that 64 bytes works but 65 bytes is too long, well, you'll know what length redhat supports.

BajanDude

64. Run tetromino's code, it's fairly safe.

Ta btw tetromino, that's a nice empirical test. I was merely quoting POSIX, but did see mentions that it's only 64 when I was googling.

Length of hostname

‎12-10-2002 | HP Enterprise Business Community

This is one area where Linux is ahead of HP-UX.

My web server for my web hosting biz at home runs Linux. The main server host name is jerusalem, my favorite city. That's nine characters btw

I tried that with an HP-UX box and had issues with swinstall and Ignite. That server is now called Moriah (the Temple Mount).

8 character limit is the way to go with HP-UX and thats 11.11 btw.

Steve
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com

===

Re: Length of hostnamePost options


‎12-10-2002 09:28 AM

For compatability sake with other systems, no matter how long the OS states the hostname can be you do not want to exceed 8 characters.

Even some of the newer systems coming out have hard limite built in to help the windows people conform to the standards, instead of defining their own. again........

if you need long names, setup DNS and make good domain/sub-domain names. This way legacy systems and systems that support only 8 characters can still function.
Here are a few systems not supporting more than 8 characters.

OS/400, MVS, WinNT3.5, Windows 3.1, DOS, MacOS less than 9, SCO Unix, Most Unices older than 4 years.

Regards,
Shannon
Microsoft. When do you want a virus today?

Unix server hostname length - HP Enterprise Business Community

Re: Unix server hostname lengthPost options

‎04-26-2005 03:04 PM

HP-UX is a standards-based system and uname must remain consistent with the standards. uname is defined as an 8-character (max) name as stated in the man page for hostname. Once a standard is changed, all sorts of problems with compatibility start showing up. Each man page documents the applicable standard(s) at the bottom.

NOTE: hostname is limited to 64 characters but nodename (the value reported by uname) is limited to 8 characters. BOTH can be set by editing the /etc/rc.conig.d/netconf file and entering separate values for HOSTNAME and NODENAME. If you must use a long hostname, then set NODENAME *and* HOSTNAME in the netconf file:

NODENAME="shorty"
HOSTNAME="shortstuffismyname"

Now you have both...but read this document:

http://www1.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=200000063236997


and then remember that all the sysadmins will have to handle any issues.

Re: Unix server hostname lengthPost options

HP is very much aware of the desire/need to support longer hostnames. However, as noted in some of the previous responses, it's a lot harder than it sounds to make such changes and still keep compatibility with older software (especially since software stacks come from many different vendors, many of which have no relationship with HP).

You might find it informative to look at the patch description text for PHCO_31598.

IBM AIX - How long can hostname be

Blizard
3 Nov 06 10:09

I am trying to find what the maximum length is for an AIX hostname - just the machine name without domain info. We currently use 8 characters, but I am building a new data center and the way we are configuring the machines, an extra character or two would be very helpful.

We chose 8 characters several years ago, but I can't remember why. It might have had something to do with the HP systems we have.

Any info gratefully accepted.

Robert Blizard
National Grid USA Service Co.
An expert is a man who has made all the mistakes which can be made, in a narrow field.
Neils Bohr (1885-1962)

p5wizard (IS/IT--Management)

3 Nov 06 10:14 Help screen in smit (F1 when in "smit mkhostname") talks about 32 chars or less for compatibility with older hosts, so you shouldn't get in any trouble...

HTH,

p5wizard


Recommended Links

Top Visited

Bulletin Latest Past week Past month
Google Search



...



Etc

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Haterís Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to to buy a cup of coffee for authors of this site

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: March, 12, 2019