3

I've read through several articles on how to do this, but it seems every time I edit "/etc/hosts" then restart my server it reverts back to the previous host names. I'm running 16.04.2 LTS

I would just like it to point to my server IP, as when I'm trying to install wordpress + lamp it installs it to the http://freeddns.noip.com I had setup.

hope this is enough information. thanks.

closed as unclear what you're asking by David Foerster, Pilot6, waltinator, Zanna, Eric Carvalho Jul 28 '17 at 17:00

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    Host name on the server is NOT the same as registering a domain name. To set the host name on the server use sudo hostnamectl set-hostname $new_hostname – Panther Jul 22 '17 at 19:51
  • Could you please add a little more detail? What exactly did you do, what did you want to achieve and what happened instead? Did you encounter any warning or error messages? Please reproduce them in their entirety in your question. You can select, copy and paste terminal content and most dialogue messages in Ubuntu. (see How do I ask a good question?) – David Foerster Jul 23 '17 at 23:32
  • To permanently change hostname edit the hostname manually from sudo gedit /etc/hostname /etc/hosts and restart. – Tahlil Sep 7 '18 at 11:41
7

You need to edit the /etc/hosts and the /etc/hostname file as well. The /etc/hosts file maps IP addresses to hostnames and the /etc/hostname file contains only the hostname. After editing the /etc/hosts file, edit the /etc/hostname file and write your new hostname in it. To apply changes:

systemctl restart systemd-logind.service

You can also use the following command to change the hostname:

hostnamectl set-hostname new_host_name
  • Ok, I got the /etc/hostname working now. But what can I change the /etc/hosts to so that it points to my server IP and apache installs and shows up there. right now this is the error I'm getting. root@myhostname:~# sudo systemctl start apache2 sudo: unable to resolve host myhostname – aRog121 Jul 22 '17 at 20:02
  • See the following links: unix.stackexchange.com/questions/36009/… – Noisy_Botnet Jul 22 '17 at 20:11
  • 2
    Noisy_Botnet It's probable that @aRog121 wants to change his domain name, not the host name... He'll have to do DNS changes instead... – Fabby Jul 22 '17 at 20:40
  • I'm basing my problem off of this: tecmint.com/install-wordpress-on-ubuntu-16-04-with-lamp it doesn't install anything to the server ip, it only shows this: i.imgur.com/5asMWvv.png – aRog121 Jul 22 '17 at 20:47
  • 1
    This works temporarily, but not permanently, at least on EC2. Even though I ran these commands, after I did a apt-get update; apt-get upgrade; apt-get dist-upgrade; reboot, I found my EC2 Ubuntu instance had reset it's hostname to the default "ip-xxx-xxx-xxx-xxx". – Cerin Aug 23 '18 at 0:42

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