Changing Hostname in Linux

The hostname in Linux is what appears at the left of the cursor in terminal. Using hostnames over ip addresses when creating shortcuts, network printers and mapped network drives is generally preferable because the path is abstracted from the assigned ip address. If the ip ever changes, you will not need to reset up your links.

        Here is how to change it on Mac, Linux – Debian Based, Linux – RedHat Based, and BSD

Identify your current hostname

On Linux systems you can find out what your hostname is by typing in the command

<code>

hostname

</code>

wpid-terminal2-2012-01-10-14-244.png

Temporarily Change Name

You could temporarily change the hostname by typing in:

hostname some-new-name

This works on linux and mac systems.

The change will not persist across reboots.

Scroll down for the persistent solution.

<code>

hostname spencers-new-name

</code

wpid-terminal1-2012-01-10-14-244.png

Permanently Change Host Name

Linux – Redhat / Fedora and Derivatives

        wpid-red-hat-2012-01-10-14-244.jpg

wpid-fedora-core-2012-01-10-14-244.jpg

Changing the hostname on a Red Hat or derivative machine requires editing the ‘network’ file located in /etc/sysconfig.

The name should already be populated from the initial install.

<code>

sudo nano /etc/sysconfig/network

</code>

wpid-vmwarefusion2-2012-01-10-14-244.png

wpid-vmwarefusion1-2012-01-10-14-244.png

( I am aware of the typo in fedora, This post was a result of needing to fix it)

Linux – Ubuntu and Debian Derivatives

        wpid-debian-2012-01-10-14-244.png

        wpid-ubuntu-2012-01-10-14-244.png

Linux Distros based on Debian such as ubuntu and CentOS have a slightly different way of changing the hostname.

For them, you must edit the /etc/hostname file

<code>

sudo nano /etc/hostname

</code>

wpid-1____vmwarefusion1-2012-01-10-14-244.png

You will then need to reboot, or if you are in a hurry, you can type in this command

<code>

/etc/init.d/hostname.sh start

</code>

The file should already have the name of your system listed. By default it is just ubuntu

wpid-vmwarefusion-2012-01-10-14-244.png

After changing it, you should restart the computer. Logging out isn’t sufficient.

Mac – OSx

wpid-apple-2012-01-10-14-244.png

While there may be a way to edit a file on mac, it is simpler and quicker to run the scutil command. Enter the word HostName followed by the new name you want to assign it. Note that there are 2 dashes ’ ‘ with no spaces in-between them

<code>

scutil — set HostName Spencers-New-Name

</code>

wpid-1____terminal1-2012-01-10-14-244.png

As always, you should restart the computer to update all references of the old name stored in memory.

FreeBSD

        wpid-freebsd_300x300-2012-01-10-14-244.png

You must exit and log back in as root

<code>

vi /etc/rc.conf

</code>

wpid-1____vmwarefusion-2012-01-10-14-244.png

Add this line to the end of the config file. Including quotes

<code>

hostname = “some-new-name”

</code>

wpid-2____vmwarefusion1-2012-01-10-14-244.png

You should restart to make the changes stick.

Credits

http://www.ducea.com/2006/08/07/how-to-change-the-hostname-of-a-linux-system/

http://osxdaily.com/2010/09/06/change-your-mac-hostname-via-terminal/

http://lists.freebsd.org/pipermail/freebsd-questions/2006-April/119355.html

Advertisements

About spuder
spuder is a "super computer" support engineer by day, and tinkerer / hobbyist by night.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: