Hostname, Change Your

From PCLinuxOSHelp Knowledge Base
Revision as of 20:33, 13 December 2021 by Dwmoar (talk | contribs) (Added nmcli for editing ones hostname)
Jump to: navigation, search

How To Change your hostname

There are several different ways to change the hostname on your Linux Machine.

Here are just two examples


From your desktop press the "Alt" key and "F2" key. This will open a window at the top of you screen.


Run-command.png]


In the line enter

kdesu kwrite


Enter-command.png


or use your favorite text editor. When you are finished press enter. After a few moments, you should than be greeted with a password dialog box.


Dialogbox.png


In this box enter your root users password, when you are done press OK.


Enter-password.png


Your text editor should now open. In our example "kwrite" will open.


Kwrite-opens.png


Click on the "OPEN" button and open the following file.

/etc/sysconfig/network


Select-file.png


We are only interested in on line in this file. This is the first line starting with

HOSTNAME=localhost.localdomain

Now we want to change it to reflect our new hostname. In this example we want to change it to read.

HOSTNAME=workbox.localhost.localdomain


Edit-file.png


Named-changed.png


When you have finished click on "SAVE" Once saved you can than close your editor. Your changes will now take effect the next time you reboot your computer.


Also Note: I've found that I need to add DHCP_HOSTNAME=<myhostname> to /etc/sysconfig/network for my router to "see" the hostname.


Changing Your Hostname yet another way

Open synaptic and install the package edit_hostname


Synaptic edit hostname.png

Once installed you can run the file from your menu -> Configuration -> Change Hostname


Run edit hostname.png


when ran a dialog box will ope as below. Simply put your desired host name in the box labeled Enter Hostname. When finished click on save. The dialog box will close.

Fill in the hostname.png

Another way to run the program is from a terminal window. Open a terminal window as root and typed edit_hostname.sh at the prompt followed by pressing enter. A dialog box will open. Enter your chosen hostname in the box labeled Enter Hostname and then click Save. The dialog box will close. You can simple close the console window.

Dit hostname from console window.png

As with both options, your new host name will appear after you restart your machine.


Chnaging the hostname using NMCLI

Another way to change your hostname is by using the Network Manager Command Line Interface (NMCLI)

Tou use the nmcli open a console window as the root user.

at the prompt enter nmcli general hostname <my-server>

replacing the <my server> with your chosen 'hostname' then press return.

Your new hostname should appear after restarting your machine

To query the static hostname, issue the following at the command prompt

 nmcli general hostname

example:

[dwmoar@chimpbox ~]$ nmcli general hostname chimpbox