diff --git a/UPGRADE.txt b/UPGRADE.txt
index 67fa6a628ea882aecd314a1dc83e76e8b350d4a1..f603caab4274aa71feebedbc67cff590ddb60c0a 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -82,6 +82,9 @@ From 1.6.2 to 1.8:
   of a Mailbox or Password, will, if it exists, jump to the 'a' extension in
   the current dialplan context.
 
+* Environment variables that start with "AST_" are reserved to the system and
+  may no longer be set from the dialplan.
+
 From 1.6.1 to 1.6.2:
 
 * SIP no longer sends the 183 progress message for early media by
diff --git a/funcs/func_env.c b/funcs/func_env.c
index 70a87776bcfc6915fcc5b6376dab48facd0109d3..b770bbc9b2b6f8dfea9bee78294820bafb7af1d3 100644
--- a/funcs/func_env.c
+++ b/funcs/func_env.c
@@ -44,6 +44,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 			</parameter>
 		</syntax>
 		<description>
+			Variables starting with <literal>AST_</literal> are reserved to the system and may not be set.
 		</description>
 	</function>
 	<function name="STAT" language="en_US">
@@ -106,7 +107,7 @@ static int env_read(struct ast_channel *chan, const char *cmd, char *data,
 static int env_write(struct ast_channel *chan, const char *cmd, char *data,
 		     const char *value)
 {
-	if (!ast_strlen_zero(data)) {
+	if (!ast_strlen_zero(data) && strncmp(data, "AST_", 4)) {
 		if (!ast_strlen_zero(value)) {
 			setenv(data, value, 1);
 		} else {
diff --git a/main/asterisk.c b/main/asterisk.c
index 9ae67a9d80aa674f79372d71d8be584984f884ca..d11fc8dcec82ea902db1f83d85f1c77b30898b09 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -3128,6 +3128,18 @@ static void run_startup_commands(void)
 	ast_config_destroy(cfg);
 }
 
+static void env_init(void)
+{
+	setenv("AST_SYSTEMNAME", ast_config_AST_SYSTEM_NAME, 1);
+	setenv("AST_BUILD_HOST", ast_build_hostname, 1);
+	setenv("AST_BUILD_DATE", ast_build_date, 1);
+	setenv("AST_BUILD_KERNEL", ast_build_kernel, 1);
+	setenv("AST_BUILD_MACHINE", ast_build_machine, 1);
+	setenv("AST_BUILD_OS", ast_build_os, 1);
+	setenv("AST_BUILD_USER", ast_build_user, 1);
+	setenv("AST_VERSION", ast_get_version(), 1);
+}
+
 int main(int argc, char *argv[])
 {
 	int c;
@@ -3314,6 +3326,7 @@ int main(int argc, char *argv[])
 	}
 
 	ast_readconfig();
+	env_init();
 
 	if (ast_opt_remote && remotesock != NULL)
 		ast_copy_string((char *) cfg_paths.socket_path, remotesock, sizeof(cfg_paths.socket_path));