2015年1月20日 星期二

How to Change Your Linux Hostname Without Rebooting


http://www.cyberciti.biz/faq/rhel-redhat-centos-7-change-hostname-command/

hostnamectl set-hostname "ABCDE"


RHEL / Centos Linux 7: Change and Set Hostname Command

I'm a new RHEL (Red Hat Linux) and/or CentOS Linux 7 server user. How can I change the hostname in CentOS 7 using a command line option?

On a CentOS Linux 7 server you can use any one of the following tool to manage hostnames:
  1. hostnamectl command : Control the system hostname. This is recommended method.
  2. nmtui command : Control the system hostname using text user interface (TUI).
  3. nmcli command : Control the system hostname using CLI part of NetworkManager.

Types of hostnames

The hostname can be configured as follows
  1. Static host name assigned by sysadmin. For example, "server1", "wwwbox2", or "server42.cyberciti.biz".
  2. Transient/dynamic host name assigned by DHCP or mDNS server at run time.
  3. Pretty host name assigned by sysadmin/end-users and it is a free-form UTF8 host name for presentation to the user. For example, "Vivek's netbook".

Method #1: hostnamectl command

Let us see how to use the hostnamectl command.

How do I see the host names?

$ hostnamectl
## OR ##
$ hostnamectl status

Sample outputs:
   Static hostname: centos-7-rc
         Icon name: computer
           Chassis: n/a
        Machine ID: b5470b10ccfd49ed8e4a3b0e953a53c3
           Boot ID: f79de79e2dac4670bddfe528e826b61f
    Virtualization: oracle
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-229.1.2.el7.x86_64
      Architecture: x86_64

How do I set the host name?

The syntax is:
# hostnamectl set-hostname Your-New-Host-Name-Here
# hostnamectl set-hostname "Your New Host Name Here" --pretty
# hostnamectl set-hostname Your-New-Host-Name-Here --static
# hostnamectl set-hostname Your-New-Host-Name-Here --transient

To set host name to "R2-D2", enter:
# hostnamectl set-hostname R2-D2
To set static host name to "server1.cyberciti.biz", enter:
# hostnamectl set-hostname server1.cyberciti.biz --static
To set pretty host name to "Senator Padmé Amidala's Laptop", enter:
# hostnamectl set-hostname "Senator Padmé Amidala's Laptop" --pretty
To verify new settings, enter:
# hostnamectl status
Sample outputs:
   Static hostname: server1.cyberciti.biz
   Pretty hostname: Senator Padmé Amidala's Laptop
Transient hostname: r2-d2
         Icon name: computer
           Chassis: n/a
        Machine ID: b5470b10ccfd49ed8e4a3b0e953a53c3
           Boot ID: f79de79e2dac4670bddfe528e826b61f
    Virtualization: oracle
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-229.1.2.el7.x86_64
      Architecture: x86_64

How do I delete a particular host name?

The syntax is:
# hostnamectl set-hostname ""
# hostnamectl set-hostname "" --static
# hostnamectl set-hostname "" --pretty

How do I change host name remotely?

Use any one of the following syntax:
# ssh root@server-ip-here hostnamectl set-hostname server1
OR set server1 as host name on a remote server called 192.168.1.42 using ssh:
# hostnamectl set-hostname server1 -H root@192.168.1.42





http://www.howtogeek.com/50631/how-to-change-your-linux-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=
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.
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:
To this:
“But”, you mutter under your breath, “I just typed in `hostname` and got ‘Snoopy’ as a result. It doesn’t work!”.
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):
# hostname 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).
Now let’s set it in stone. If you are using chkconfig and service commands (RedHat family folk, usually), you can simply type
#service network restart
which will restart the network with the new host name. The rest of you should be able to type
#/etc/init.d/network restart
to obtain the same results.
Then test again with the hostname command – you should get the new name returned.
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.
And at least you can keep the small stuffed plush Snoopy sitting at your desk to remind you of that gentler, simpler time.

沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...