如何修改hostname

修改/etc/sysconfig/network中的:

HOSTNAME

比如改成机器的IP:

NETWORKING=yes
HOSTNAME=10.20.150.92

GATEWAY=10.20.150.254 

改完后运行/etc/rc.d/rc.sysinit 

#/etc/rc.d/rc.sysinit

系统运行如下: 

mount: proc already mounted
Setting default font (lat0-sun16):                         [  OK  ]
                Welcome to Red Hat Enterprise Linux AS
                Press 'I' to enter interactive startup.
Cannot access the Hardware Clock via any known method.
Use the --debug option to see the details of our search for an access method.
Setting clock  (localtime): Fri Apr 22 16:21:09 CST 2011   [  OK  ]
Starting udev:                                             [  OK  ]
Initializing hardware...  storage network audio done       [  OK  ]
mount: none already mounted or /dev/pts busy
mount: according to mtab, none is already mounted on /dev/pts
Configuring kernel parameters:                             [  OK  ]
Loading default keymap (us):                               [  OK  ]
Setting hostname 10.20.150.92:                             [  OK  ]
Your system appears to have shut down uncleanly
Press Y within 1 seconds to force file system integrity check...
Checking root filesystem
/dev/xvda1 is mounted.  e2fsck: Cannot continue, aborting.

最后输入密码退出,不会重启,这个时候hostname 就修改完毕了 

当然运行reboot也可以 

Temporarily changing your hostname

You can temporarily change your hostname by issuing a single command. You have to issue this command either using sudo or as the root user. To make this change you will use the same command you used to find out your hostname, only you will include the new hostname to the command. Say you want to change your hostname to “willow”. To make this change temporarily issue the command:

hostname willow

Now issue the command hostname which should report back:

willow

This change will last until you reboot your machine.

Permanently changing your hostname

How you permanently change your hostname will depending upon which distribution you use. We’ll examine making this change on both a Ubuntu system and a Fedora system. First Ubuntu.

On a Ubuntu system there is a file called /etc/hostname. The contents of this file will have a single line containing the hostname of your machine. Open up this file in your favorite editor, delete the default hostname, add your desired hostname, and save the file. To make this chang take effect issue the command:

/etc/init.d/hostname.sh start

This hostname will remain intact upon reboot.

Now to change your hostname in Fedora. This is taken care of in the /etc/sysconfig/networkfile. The default contents of this file will look like:

NETWORKING=yes
HOSTNAME=localhost.localdomain

Erase the “localhost.localdomain” portion and change that to reflect the hostname you want. Once you have made this change save the file. Once you have made this change issue the following command (as the root user):

/etc/rc.d/rc.sysinit

For the change to take effect. 

原文地址:https://www.cnblogs.com/welkinwalker/p/2025048.html