Polls

Topics

Linux Maximum Length Of A Host Name

Posted by Vivek on Wednesday April 30, 08 (2 weeks ago) @7:09 pm

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.

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in...

Discussion on This Article:

  1. Jeff Says:

    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.

  2. Jeff Schroeder Says:

    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

  3. vivek Says:

    Thanks for correct information, The post has been updated.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , ~ Last updated on: May 1, 2008

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.