• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / Changing the hostname on CentOS

Changing the hostname on CentOS

If the hostname setting is incorrect on your CentOS/RedHat/Fedora machine, it’s really easy to change the hostname from the command line. There are also GUI tools for doing this but we’ll just look at the CLI tools for doing this.

The file /etc/sysconfig/network contains the hostname and will look something like this:

NETWORKING="yes"
GATEWAY="10.1.1.1"
HOSTNAME="www.example.com"

Simply open up the file in your favourite text editor, either as root or using sudo, and change the HOSTNAME value to what you want it to. For example, if we wanted to change www.example.com from the above example to ftp.example.com then you’d end up with the following:

NETWORKING="yes"
GATEWAY="10.1.1.1"
HOSTNAME="ftp.example.com"

This change won’t take affect until the next reboot, but you can make the change happen immediately using the hostname command like so:

$ hostname ftp.example.com

Simply issuing the command on its own will return the current hostname, eg

$ hostname
ftp.example.com

You may also need to add/change the hostname in the /etc/hosts file. By default this would look something like this, using our www.example.com example again:

127.0.0.1  www.example.com localhost localhost.localdomain

You would then change it to be like so:

127.0.0.1  ftp.example.com localhost localhost.localdomain

Check Out These Related posts:

  1. Styling select, optgroup and options with CSS
  2. Create a file in Linux
  3. Sendmail Connection Refused on localhost
  4. Reinstall TCP/IP on Windows XP

Filed Under: Linux/Unix/BSD

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap