How to set FQDN in Ubuntu

June 1, 2013 35.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 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: localhost do.rtcamp.com do

I changed it to localhost do.rtcamp.com do is IP of my new droplet.

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

$ cat /etc/hostname

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 localhost do.rtcamp.com do

# cat /etc/hostname

# hostname -F /etc/hostname

# hostname

#hostname --fqdn

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