diff --git a/Makefile b/Makefile
index ae4b0464c483ea5e025d46368bf8f44375428442..aa7de5aa732d89ea06e84190ec8a5d3c2a6f2b56 100644
--- a/Makefile
+++ b/Makefile
@@ -545,7 +545,7 @@ samples: adsi
 		echo ";[options]" ; \
 		echo ";internal_timing = yes" ; \
 		echo ";systemname = my_system_name ; prefix uniqueid with a system name for global uniqueness issues" ; \
-		echo ";autosystemname = yes ; automatically set systemname to hostname - uses 'localhost' on failure" ; \
+		echo ";autosystemname = yes ; automatically set systemname to hostname - uses 'localhost' on failure, or systemname if set" ; \
 		echo "; Changing the following lines may compromise your security." ; \
 		echo ";[files]" ; \
 		echo ";astctlpermissions = 0660" ; \
diff --git a/main/asterisk.c b/main/asterisk.c
index c44e2cbd677d15d05dfa1228bbb4e2e8676d754c..a8dd93d75b27cb51fa776a61da5b395afa8324ed 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2529,8 +2529,10 @@ static void ast_readconfig(void)
 				if (!gethostname(hostname, sizeof(hostname) - 1))
 					ast_copy_string(ast_config_AST_SYSTEM_NAME, hostname, sizeof(ast_config_AST_SYSTEM_NAME));
 				else {
-					ast_log(LOG_ERROR, "Cannot obtain hostname for this system.  Using 'localhost' instead.\n");
-					ast_copy_string(ast_config_AST_SYSTEM_NAME, "localhost", sizeof(ast_config_AST_SYSTEM_NAME));
+					if (!ast_strlen_zero(ast_config_AST_SYSTEM_NAME)){
+						ast_copy_string(ast_config_AST_SYSTEM_NAME, "localhost", sizeof(ast_config_AST_SYSTEM_NAME));
+					}
+					ast_log(LOG_ERROR, "Cannot obtain hostname for this system.  Using '%s' instead.\n", ast_config_AST_SYSTEM_NAME);
 				}
 			}
 		} else if (!strcasecmp(v->name, "languageprefix")) {