---
title: "linux 修改 hostname"
author: "xxtianxiaxing"
date: "2010-01-07T08:38:44Z"
tags: []
categories: ["操作系统"]
slug: "linux-hostname"
draft: false
lastmod: "2010-01-08T11:53:05Z"
id: 564407
url: "https://xylonwang.iteye.com/blog/564407"
---

1\. 变更当前主机名  
两种方法： echo new-hostname &gt; /proc/sys/kernel/hostname  
或者： hostname myhost

2\. 修改配置文件，使得下次重启的时候，使用新的主机名  
编辑文件： /etc/sysconfig/network  
修改： HOSTNAME=myhost.com

3\. 配置本机的域名解析文件，使得本机的应用程序能够解析新的主机名  
编辑文件： /etc/hosts

127.0.0.1     localhost.localdomain localhost

192.168.1.100 myhost.com myhost

 

 

修改hostname 可能带来无法预知的错误，（如：mysql-master-slave）

谨慎修改

详细参见：[http://www.linuxsir.org/main/node/222](http://www.linuxsir.org/main/node/222)