I used Linux command of the hostname - show or set the hostname

2010-11-06  来源:本站原创  分类:OS  人气:145 

I used Linux command of the hostname - show or set the hostname

This link: http://codingstandards.javaeye.com/blog/804648 (reprint, please indicate the source)

Use Description

hostname command can be used to display or set the host name (show or set the system's host name). Save the environment variable HOSTNAME is also the current host name. Using the hostname command to set the host name, the system does not permanently save the new host name, restart the machine after the host name or the original. If you need to permanently change the host name, you need to also modify / etc / hosts and / etc / sysconfig / network related content. Some rely on the host name of the software system, after modifying the host name may be problems, such as mysql replication is configured, modify the host name of a good idea to stop the run (the voice of experience, I have to so toss a long time) .

Common parameters

Without parameters to display the host name.

Format: hostname

Take-i parameter to display ip address.

Format: hostname-i

Displayed when the-f parameter to bring the whole domain name (FQDN, Fully Qualified Domain Name).

Format: hostname-f

Change the host name, followed by the new host name. (Note that this method is effective immediately, but will not permanently stored, see the back of the sample).

Format: hostname newhostname

Use the sample

Example I shows the host name

[Root @ jfht ~] # hostname
jfht
[Root @ jfht ~] # echo $ HOSTNAME
jfht
[Root @ jfht ~] # grep jfht / etc / hosts
127.0.0.1 jfht localhost.localdomain localhost

Note: This machine hosts to set some problems, and should also open a line to set ip fqdn hostname, such as 192.168.1.191 jfht.xyz.com jfht.

[Root @ jfht ~] # hostname-i
127.0.0.1 <== the / etc / hosts file settings is not reasonable, it shows the loopback address (loopback 127.0.0.1).

[Root @ jfht ~] # hostname-f
jfht <== the / etc / hosts file is not set FQDN, so I can not display fqdn.
[Root @ jfht ~] # grep jfht / etc / sysconfig / network
HOSTNAME = jfht

[Root @ jfht ~] # cat / proc / sys / kernel / hostname
jfht
[Root @ jfht ~] #

Modify the host name two examples

Now show you how to change the original host name rhel55 new55, and increase the FQDN settings.

[Root @ rhel55 ~] # hostname
rhel55
[Root @ rhel55 ~] # hostname-i
127.0.0.1
[Root @ rhel55 ~] # hostname-f
rhel55
[Root @ rhel55 ~] # hostname new55
[Root @ rhel55 ~] # echo $ HOSTNAME
rhel55
[Root @ rhel55 ~] # hostname
new55
[Root @ rhel55 ~] # vi / etc / hosts

Open the / etc / hosts, will be

127.0.0.1 rhel55 localhost.localdomain localhost

To

127.0.0.1 localhost.localdomain localhost

And to increase the line

192.168.6.55 new55.somedomain.com new55

[Root @ rhel55 ~] # vi / etc / sysconfig / network

Will

HOSTNAME = rhel55

Change

HOSTNAME = new55

Now exit the current shell to log look.

[Root @ rhel55 ~] # exit
logout

Last login: Sat Nov 6 17:00:08 2010 from 192.168.6.106
[Root @ new55 ~] # echo $ HOSTNAME
new55
[Root @ new55 ~] # hostname
new55
[Root @ new55 ~] # hostname-i
192.168.6.55
[Root @ new55 ~] # hostname-f
new55.somedomain.com
[Root @ new55 ~] #

Restart about Linux, then log in, you can see the host name changes to take effect.
[Root @ new55 ~] # reboot

Last login: Sat Nov 6 17:10:08 2010 from 192.168.6.106
[Root @ new55 ~] # echo $ HOSTNAME
new55
[Root @ new55 ~] # hostname
new55
[Root @ new55 ~] # hostname-i
192.168.6.55
[Root @ new55 ~] # hostname-f
new55.somedomain.com
[Root @ new55 ~] #

At this point, to sum up the method to modify the host name:

1. Stop the host name associated with the software running, such as mysql.

2. First, set the hostname using the hostname newname.

3. In the / etc / hosts to modify or add ip fqdn newname line, and check the setting of the original 127.0.0.1 line.

4. In the / etc / sysconfig / network to modify the HOSTNAME = newname.

5. Restart the machine and verify that the change successful.

Reflections

Related information

【1】 cnblogs [Linux.Bash] of several configuration files on the host name and the command

【2】 Interactive Encyclopedia FQDN

【3】 Baidu space linux how to modify the hostname (zz)

【4】 LinuxSir.Org Linux operating system host name (hostname) Jane said (v0.1b)

【5】 ChinaUnix how to modify the hostname Linux

【6】 robinwu log Redhat Linux change the host name (HOSTNAME)

Back to Linux I used the command line List

相关文章
  • I used Linux command of the hostname - show or set the hostname 2010-11-06

    I used Linux command of the hostname - show or set the hostname This link: http://codingstandards.javaeye.com/blog/804648 (reprint, please indicate the source) Use Description hostname command can be used to display or set the host name (show or set

  • Linux command line tips 2010-06-02

    Xiaoming Motorcycle and Chen Huajiang have kindly TRANSLATED this page. This is a list of linux common commands. • mark those entries, you can copy directly to the terminal without any modification, so you'd better open a terminal Bian Dubian cut & c

  • linux command Daquan 2010-07-07

    http://www.pixelbeat.org/cmdline.html This is a linux command line reference for common operations. Examples marked with • are valid / safe to paste without modification into a terminal, so you may want to keep a Terminal window Open while reading th

  • Linux command line, modify the IP. Gateway. DNS method 2010-07-14

    Linux command line, modify the IP, gateway, DNS method Way: ifconfig eth0 192.168.1.18 netmask 255.255.255.0 Description: The ways you can make changes take effect immediately, restart will revert to the original IP The second way: vi / etc/sysconfig

  • Linux command line Daquan 2010-09-27

    The following is reproduced: Linux command line operation simple and efficient, the number is a bit more. linuxguide.it compiled more than 350 Linux command line command, and the corresponding instructions for you to use Quick Check. Linux novice or

  • linux command collection (1) 2010-09-28

    This is a list of linux common commands. • mark those entries, you can copy directly to the terminal without any modification, so you'd better open a terminal while being read cut & copy . All commands in Fedora and Ubuntu have done a test under Comm

  • I used the Linux command uname - print system information 2010-11-11

    I used the Linux command uname - print system information This link: http://codingstandards.javaeye.com/blog/809182 (please specify reproduced everywhere) Use Description uname command to print the system information (print system information), inclu

  • I used the Linux command telnet - telnet-based tools TELNET protocol 2010-12-07

    I used the Linux command telnet - telnet-based tools TELNET protocol This link: http://codingstandards.javaeye.com/blog/835485 (reprint, please indicate the source) Use Description remote login telnet command is often used. telnet program is based on

  • I used the Linux command line List (update 4.17, 94) 2010-10-17

    I used the Linux command line List This link: http://codingstandards.iteye.com/blog/786653 (reproduced please indicate the source) Outline Type of command The table lists the I exhausted all my memory sorting out the Linux command, which on the exter

  • I used Linux command of telnet - telnet TELNET protocol-based tools 2010-12-07

    I used Linux command of telnet - telnet TELNET protocol-based tools This link: http://codingstandards.iteye.com/blog/835485 (reproduced please indicate the source) Use Description The telnet command is usually used to log in remotely. telnet program

  • I used Linux command of the mysql - MySQL client command-line tool 2011-03-25

    I used Linux command of the mysql - MySQL client command-line tool This link: http://codingstandards.iteye.com/blog/975686 (reproduced please indicate the source) Use Description mysql command is used to connect to MySQL server and run the command-li

  • I used Linux command of the env - display the current user's environment variables 2011-04-09

    I used Linux command of the env - display the current user's environment variables This link: http://codingstandards.iteye.com/blog/994906 (reproduced please indicate the source) Use Description env command to display the current user's environment v

  • I used the Linux command line List (7.2 update 98) 2011-07-02

    I used the Linux command line List (7.2 update 98) This link: http://codingstandards.iteye.com/blog/786653 (reproduced please indicate the source) Outline Type of command The table lists the I exhausted all my memory sorting out the Linux command, wh

  • Linux command ip Detailed View 2011-07-15

    Turn: ifconfig Linux command to view IP address - ifconfig ifconfig command is used to view and change the address and network interface parameters $ Ifconfig-a lo0: flags = 849 mtu 8232 inet 127.0.0.1 netmask ff000000 hme0: flags = 863 mtu 1500 inet

  • I used Linux command of the ping - test connectivity with the target host 2011-07-16

    I used Linux command of the ping - test connectivity with the target host This link: http://codingstandards.iteye.com/blog/1125766 (reproduced please indicate the source) Use Description The ping command is commonly used network commands, it is usual

  • I used Linux command of the export - set or display environment variables 2011-08-02

    I used Linux command of the export - set or display environment variables This link: http://codingstandards.iteye.com/blog/1138524 (reproduced please indicate the source) Use Description export command can be used to set or display environment variab

  • linux command find find files 2010-03-13

    Each of the operating system by thousands of different types of documents composed. Which comes with the file system itself, the user's own documents, as well as share files and so on. Sometimes we often forget that a document on the hard drive which

  • The most common Linux command basic operations 2010-03-25

    Linux command basic operations http://www.chinaitpower.com/A/2003-02-18/50468.html First introduced the term "console (console)", it is the use of characters we usually see the interface of man-machine interface, such as dos. We say that the con

  • Xiang Jie common Linux command line svn command 2010-03-31

    This article describes common Linux command line use svn command, in the hope of help to you. 1, Linux command line checkout files to a local directory svn checkout path (path is the directory on the server) For example: svn checkout svn: / / 192.168

  • tar linux command description 2010-04-19

    tar linux command description Introduction Parameters: -C: create a compressed file parameter commands (create meaning); -X: solve the parameters of a compressed file instructions! -T: view files inside tarfile! Particular attention to issue of the p