Linux Maximum Length Of A Host Name

by Vivek Gite on April 30, 2008 · 3 comments

While browsing Linux kernel source code I came across POSIX (Portable Operating System Interface) variable called _POSIX_HOST_NAME_MAX . It defines the maximum length of a host name (not including the terminating null) as returned from the gethostname function.

This variable sets the limit to the number of characters in a hostname under Linux.
$ grep '_POSIX_HOST_NAME_MAX' /usr/include/bits/posix1_lim.h
Output:

#define _POSIX_HOST_NAME_MAX    255

You can change limit and recompile the kernel to get bigger hostname.

See comment below for correct information.

Updated for accuracy.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 3 comments… read them below or add one }

1 Jeff May 1, 2008

This is a VERY bad idea. The length of hostnames is a standard defined by the RFC’s.

If anyone adjusts this to excess of the standards and has problems, they are just a idiot to be laughed at.

Reply

2 Jeff Schroeder May 1, 2008

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.

Can you switch your blog over to recaptcha for better captchas and do the world some good?
http://recaptcha.net/plugins/wordpress/

http://www.digitalprognosis.com/blog

Reply

3 vivek May 1, 2008

Thanks for correct information, The post has been updated.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 2 + 7 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: