茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1669055 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00042.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

小企鵝開談 : [轉貼]Linux (Redhat / Fedora / CentOS) 更改 hostname 的方式

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Linux (Redhat / Fedora / CentOS) 更改 hostname 的方式

Linux (Redhat / Fedora / CentOS) 更改 hostname 的方式

發現更改主機的 hostname 的方式都改不太完整. 以下是試出來比較完整的方式:

Step 00:

  • 假設原本 hostname 為 tryboxap2, 現在想要更改為 tryboxap03
  • 使用 root 才可以更改 hostname
su - root

Step 01:

  • 將 /etc/hosts 內出現的 tryboxap2 都改成 tryboxap03
127.0.0.1 tryboxap03 localhost.localdomain localhost

Step 02:

  • 將 /etc/sysconfig/network 內的 HOSTNAME 改成 tryboxap03

NETWORKING=yes
HOSTNAME=tryboxap03
GATEWAY=61.67.71.126

Step 03:

  • 再使用 hostname 命令指定一次
hostname tryboxap03
  • 這時就已經設定完成. 可以使用 hostname 命令去確認一次

[email protected] etc]# hostname
tryboxap03
[[email protected] etc]#

只要重新登入, 命令提示字串就會改成 [ [email protected] etc]#

  • 如果有系統有設定自動寄出信件, 必須要重新啟動 sendmail 否則會出現 relay deny 的狀況
  • 如果要當郵件主機, hostname 就要符合 FQDN Exp. tryboxap03.ichiayi.com 所以 /etc/hosts 內要改成
    127.0.0.1 tryboxap03.ichiayi.com tryboxap03 localhost.localdomain localhost
  • CentOS7 如果以上三步驟還無法改成功, 就需要在 /etc/hostname 這檔案內加入 hostname Exp. tryboxap03 或 tryboxap03.ichiayi.com
    tryboxap03.ichiayi.com

原文出處:Linux (Redhat / Fedora / CentOS) 更改 hostname 的方式 [蔡宗融個人網站]
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Redhat / CentOS 7 更改 hostname
Redhat / CentOS 7 更改 hostname

以前的 Redhat 要更改 hostname 可以修改 /etc/sysconfig/network, 並用 hostname 指令設定等。現在 Redhat/Centos 7 用了新的方法, 只要 hostnamectl 指令便可以。

檢查主機 hostname:
# hostnamectl

會列出目前使用的 hostname, 要修改則要這樣:
# hostnamectl set-hostname new_hostname

上面的 new_hostname 是新 hostname, 設定好後可以再用 hostnamectl 檢一是否生效。

原文出處:Redhat / CentOS 7 更改 hostname
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]How to Set or Change System Hostname in Linux

How to Set or Change System Hostname in Linux

by | Published: April 14, 2016 | Last Updated: April 14, 2016

Device or system hostnames are used to easily recognize a machine within a network in a human readable format. It is not much of a surprise, but on Linux system, the hostname can be easily changed by using simple command as “hostname“.

Running hostname on its own, without any parameters, will return the current hostname of your Linux system like this:


$ hostname
TecMint

If you want to change or set hostname of your Linux system, simply run:


$ hostname NEW_HOSTNAME

Of course, you will need to replace “NEW_HOSTNAME” with the actual hostname that you wish to set. This will change the hostname of your system immediately, but there is one problem – the original hostname will be restored upon next reboot.

There is another way to change the hostname of your system – permanently. You might have already figured it out that this will require change in some configuration files and you will be correct.

Set System Hostname Permanently in Linux

Newer version of different Linux distributions such as latest Ubuntu, Debian, CentOS, Fedora, RedHat, etc. comes with systemd, a system and service manager that provides a hostnamectl command to manage hostnames in Linux.

To set system hostname on SystemD based distributions, we will use hostnamectl command as shown:


$ sudo hostnamectl set-hostname NEW_HOSTNAME

For Older Linux distributions, which uses SysVinit in short init, can have their hostnames changed by simply editing the hostname file located in:


# vi /etc/hostname

You then have to add another record for the hostname in:


# vi /etc/hosts

For example:


127.0.0.1 TecMint

You then need to run:


# /etc/init.d/hostname restart

On RHEL/CentOS based systems that use init, the hostname is changed by modifying:


# vi /etc/sysconfig/network

Here is a sample of that file:


/etc/sysconfig/network
NETWORKING=yes
HOSTNAME="tecmint.com"
GATEWAY="192.168.0.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"

To keep a permanent hostname change the value next to "HOSTNAME" to the one of your hostname.

Conclusion

This simple article meant to show you a simple Linux trick and I hope that you learned something new.


原文出處: How to Set or Change System Hostname in Linux
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|