Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had set my hostname while installing linux as "ankit". i want to change it to "ankit.centos". I tried changing hostname in /etc/hosts, /etc/sysconfig/network and sysctl kernel.hostname=ankit.centos.

Though the hostname is set correctly which I verified by typing hostname on terminal, but even after restarting the system the name on terminal is not changed it still is showing root@ankit$.

Any clues how do change that?

share|improve this question
What is the result of the following commands: hostname & hostname -s – sparticvs Dec 16 '13 at 18:40
@sparticvs hostname results in "ankit.centos" while hostname -s gives "ankit" – ay89 Dec 16 '13 at 18:45
Your hostname is correct. Your prompt is only showing the shortname. Each '.' is a domain delimiter. The system is assuming that "centos" is your TLD. If you want to make sure you see it, change your hostname to ankit-centos. – sparticvs Dec 16 '13 at 19:04
You'd try to set your PS1 to \u@\H\$. Using \H instead of \h shows you the full hostname instead of just the short form of it. – Risto Salminen Dec 16 '13 at 19:05
@ay89 it should be "ankit.centos" anyway, so leave it. It should be the same as the values you set before. I just checked my install and its the FQDN (fully-qualified domain name). – sparticvs Dec 16 '13 at 19:29
up vote 4 down vote accepted

The default PS1 prompt behavior is to display the hostname up to the first '.' as noted in this excerpt from the bash man page:

PROMPTING When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:


\h the hostname up to the first ‘.’

\H the hostname

You can correct this by changing how your PS1 prompt is displayed in /etc/bashrc

This CentOS website details methods for customizing your bash prompt, including this:

System-wide Configuration

System-wide configuration is done in /etc/bashrc. Comment out the default settings and add your customization below:

# [ "$PS1" = "\s-\v\\$ " ] && PS1="[\u@\h \w]\$ "

PS1='\u@\H:\w\$ '

share|improve this answer
my bad, just realized a few seconds back. – ay89 Dec 16 '13 at 19:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.