jr5689
By:
jr5689

How to set FQDN in Ubuntu

June 1, 2013 51.1k views
Hi all, I want to set my FQDN in the format myhostname.mydomain.com I thought I only had to edit /etc/hosts: $ cat /etc/hosts 127.0.0.1 localhost apple # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters $ I added just this line: 12.345.6.78 apple.example.com apple and then $ reboot and in Domains added an A record for apple.example.com but it does not seem to have any effect - I still get: $ hostname --fqdn localhost $ Any ideas please what I am doing wrong? Thanks...
7 Answers
Got it. Providing details for others.

I set hostname in web-interface as `do.rtcamp.com` for new droplet.

It added line in `/etc/hosts` file as:

127.0.0.1 localhost do.rtcamp.com do

I changed it to
127.0.0.1 localhost
188.226.169.135 do.rtcamp.com do

188.226.169.135 is IP of my new droplet.

Now hostname -f work as expected.
What do you have in /etc/hostname?
@ Kamal Nasser

$ cat /etc/hostname
apple
$

Thanks...
Edit /etc/hostname and put apple.example.com in it. Run hostname -F /etc/hostname and try hostname --fqdn again.
@ Kamal Nasser - ok it works now, thank you :)
@Kamal I am facing same issue but given solution is not working for me.

# cat /etc/hosts
127.0.0.1 localhost do.rtcamp.com do

# cat /etc/hostname
do.rtcamp.com

# hostname -F /etc/hostname

# hostname
do.rtcamp.com

#hostname --fqdn
localhost

I am on Ubuntu 12.04 :|
Have another answer? Share your knowledge.