For example.
[root@ip-10-0-7-225 ~]#
I edited /etc/hosts but it didn't work.
As noted, the problem is the hostname. CentOS (unlike Debian) may get that information from
/etc/sysconfig/network
e.g., a line like
HOSTNAME=myhostname.mydomainname
Further reading: 28.1.21. /etc/sysconfig/network
The part that comes after @ in PS1 by default is your hostname.
My default PS1 in Armbian (Debian) is
PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
Where \h is shorthand for the hostname.
To change the name, either you:
To change it immediately to a new name (lost at logout time):
PS1='\u@new_name'
Where \u is shorthand for the logged in user.
PS1 is fine to change it on the go, I do not recommend changing the default PS1 permanently as the proper method.
As such, to change it in runtime via hostname you have to do:
sudo hostname new_name.new_domain
And then logout and login.
You also have to edit /etc/hostname
to change the default name server when rebooting.
sudo vi /etc/hostname
Keep however in mind that disconnecting and connecting the network interface, and then logout and login, will revert to the old name if you have not configured your dhcp client to ignore the name you receive via DHCP.
For more info, please peruse this stack exchange question:
I do not recommend changing the default PS1 permanently as the proper method.
why ?
$PS1
give someone problems with scripts?
Commented
Feb 15, 2016 at 16:01