Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hostname -f returns localhost

I want to set the full hostname via hostname; Here is what i did below; unfortunately 'hostname -f' returns 'localhost'; why ? I was expecting the result of it to be 'bdvm1.us.mysite.com', that's what i need - thanks in advance

# more /etc/hosts
127.0.0.1   localhost bdvm1.us.mysite.com mysql mysql.bdvm1.us.mysite.com localhost.loca
ldomain localhost4 localhost4.localdomain4
192.168.1.106 bdvm1 bdvm1.us.impetus.com
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@bdvm1 ~]# hostname bdvm1.us.mysite.com
[root@bdvm1 ~]# hostname -f
localhost
[root@bdvm1 ~]# 
like image 459
matthieu lieber Avatar asked Sep 23 '26 22:09

matthieu lieber


1 Answers

The /etc/hosts file is used for mapping hostnames to IP addresses before the DNS. i.e. when you trying to connect to "example.com", the OS first looks in the /etc/hosts file, and if the hostname doesn't appear in this file, then the DNS server.

You have to change your hostname in another file. On my Lubuntu machine, the hostname is stored in the /etc/hostname file, when you find it, edit it and reboot the machine. Then try to type "hostname"

The 'localhost' is mapped as your local machine - 127.0.0.1

like image 90
Luka Klarić Avatar answered Sep 26 '26 13:09

Luka Klarić