Skip to content

Commit bd5dc17

Browse files
joshtripletttorvalds
authored andcommitted
uts: make default hostname configurable, rather than always using "(none)"
The "hostname" tool falls back to setting the hostname to "localhost" if /etc/hostname does not exist. Distribution init scripts have the same fallback. However, if userspace never calls sethostname, such as when booting with init=/bin/sh, or otherwise booting a minimal system without the usual init scripts, the default hostname of "(none)" remains, unhelpfully appearing in various places such as prompts ("root@(none):~#") and logs. Furthermore, "(none)" doesn't typically resolve to anything useful. Make the default hostname configurable. This removes the need for the standard fallback, provides a useful default for systems that never call sethostname, and makes minimal systems that much more useful with less configuration. Distributions could choose to use "localhost" here to avoid the fallback, while embedded systems may wish to use a specific target hostname. Signed-off-by: Josh Triplett <josh@joshtriplett.org> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Acked-by: David Miller <davem@davemloft.net> Cc: Serge Hallyn <serue@us.ibm.com> Cc: Kel Modderman <kel@otaku42.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ca39599 commit bd5dc17

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎include/linux/uts.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#endif
1010

1111
#ifndef UTS_NODENAME
12-
#define UTS_NODENAME "(none)" /* set by sethostname() */
12+
#define UTS_NODENAME CONFIG_DEFAULT_HOSTNAME /* set by sethostname() */
1313
#endif
1414

1515
#ifndef UTS_DOMAINNAME

‎init/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ config KERNEL_LZO
204204

205205
endchoice
206206

207+
config DEFAULT_HOSTNAME
208+
string "Default hostname"
209+
default "(none)"
210+
help
211+
This option determines the default system hostname before userspace
212+
calls sethostname(2). The kernel traditionally uses "(none)" here,
213+
but you may wish to use a different default here to make a minimal
214+
system more usable with less configuration.
215+
207216
config SWAP
208217
bool "Support for paging of anonymous memory (swap)"
209218
depends on MMU && BLOCK

0 commit comments

Comments
 (0)