linux下如何更改主机名_如何在不重新启动的情况下更改Linux主机名

linux下如何更改主机名

linux下如何更改主机名

If you’ve worked in the admin world for any length of time, you’ve probably run into an instance where you needed to change the hostnames on your server to match some corporate naming standard, but you can’t have downtime either. So how do you change the hostname without rebooting?

如果您已经在管理领域工作了一段时间,则可能遇到了一个实例,您需要更改服务器上的主机名以符合某些公司命名标准,但是也不能停机。 那么,如何在不重启主机的情况下更改主机名?

更改主机名 (Changing the Hostname)

First, you must change the config file that controls this. The actual file and its location will vary across distributions. In the Redhat derivatives, the file to modify is /etc/sysconfig/network so vi this file and change the line that reads HOSTNAME=

首先,您必须更改控制它的配置文件。 实际文件及其位置在不同发行版中会有所不同。 在Redhat派生版本中,要修改的文件是/ etc / sysconfig / network,所以vi该文件并更改读取HOSTNAME =的行。

From this:

由此:

To this:

对此:

For SuSE distributions you would similarly change the /etc/HOSTNAME file while Debian admins would modify the /etc/hostname file to set the new name.

对于SuSE发行版,您将类似地更改/ etc / HOSTNAME文件,而Debian管理员将修改/ etc / hostname文件以设置新名称。

Next, the /etc/hosts file needs to be changed. This is identical across all flavors and consists of using your favorite text editor and modifying the old hostname within. Such as from this:

接下来,需要更改/ etc / hosts文件。 这在所有类型中都是相同的,包括使用您喜欢的文本编辑器并修改其中的旧主机名。 如从此:

To this:

对此:

“But”, you mutter under your breath, “I just typed in `hostname` and got ‘Snoopy’ as a result. It doesn’t work!”.

“但是”,你低声喃喃道,“我刚输入`hostname`,结果得到了'Snoopy'。 它不起作用!”。

What you need to know is that the previous steps are to permanently set the new name. You are much too quick to judge, obviously. So, continue on by entering (at the command line as root or a sudoer):

您需要知道的是,先前的步骤是永久设置新名称。 显然,您判断得太快了。 因此,继续输入(在命令行以root或sudoer身份):

# hostname mdmvr14s9db

#主机名mdmvr14s9db

This will set the hostname for now but the change is not saved (that is what the above steps are for, remember?). Go ahead – test it. Type in `hostname` (without the tickmarks ) and the command should return ‘mdmvr14s9db’ (without the single quotes).

这将立即设置主机名,但更改不会保存(以上步骤是做什么的,还记得吗?)。 继续进行测试。 输入“主机名”(不带勾号),命令应返回“ mdmvr14s9db”(不带单引号)。

Now let’s set it in stone. If you are using chkconfig and service commands (RedHat family folk, usually), you can simply type

现在让我们把它放在石头上。 如果您使用的是chkconfig和service命令(通常是RedHat家庭成员),则只需键入

#service network restart

#service网络重启

which will restart the network with the new host name. The rest of you should be able to type

这将使用新的主机名重新启动网络。 其余的人应该可以输入

#/etc/init.d/network restart

#/ etc / init.d /网络重启

to obtain the same results.

获得相同的结果。

Then test again with the hostname command – you should get the new name returned.

然后使用hostname命令再次测试-您应该返回新名称。

This has been the easy part. Hopefully, prior to starting this, you checked all application conf files for any hard coded reference to the new name and changed that as well. And you need to then change your DNS ‘A’ record to also reflect the new name. And once you have restarted named with the new name on the DNS you will have succeeded in temporarily irritating around half of those 18,000 users previously mentioned who now can’t get to the server since the name has not propagated around the network yet. But this too shall pass as long as you hide long enough.

这是容易的部分。 希望在开始之前,您检查了所有应用程序的conf文件是否有对新名称的硬编码引用,并进行了更改。 然后,您需要更改DNS“ A”记录以也反映新名称。 并且,一旦您在DNS上重新启动了以新名称命名的名称,您将成功地暂时激怒了之前提到的18,000个用户中的大约一半,这些用户由于该名称尚未在网络中传播而现在无法访问服务器。 但是,只要您隐藏足够长的时间,这也将过去。

And at least you can keep the small stuffed plush Snoopy sitting at your desk to remind you of that gentler, simpler time.

而且至少您可以让毛绒小巧的史努比坐在您的办公桌前,以提醒您那段更温和,更简单的时间。

翻译自: https://www.howtogeek.com/50631/how-to-change-your-linux-hostname-without-rebooting/

linux下如何更改主机名

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值