13

And when I tried the following commands /etc/hostnames and /etc/hosts, it says:

bash: permission denied.
1
  • 5
    /etc/hostnames and /etc/hosts are not commands.
    – Pilot6
    Aug 11, 2016 at 17:15

3 Answers 3

40

To to resolve a host, just add it to /etc/hosts, like the example below.

Animated example

Use ctrl+o to save the edits and ctrl+x to exit from Nano. Here you are and screenshot example.

In this example is assumed that the hostname (SZS in this case) is correct, but it is not bound to the server's IP address via server's hosts file.


To resolve this issue you must find (or set) your hostname and insert next line into /etc/host:

127.0.1.1    your-hostname

The commands used in the example are:

cat /etc/hostname      # the command 'cat' will print the content of '/etc/hostname' file
hostname               # without arguments, this command will do the same as above command
cat /etc/hosts         # will print the content of '/etc/hosts' file
sudo nano /etc/hosts   # 'nano' text editor will open '/etc/hosts' as root

Here you are, few more approaches and explanations:

0
5

I'm assuming you're on Ubuntu Server.

/etc/hosts and /etc/hostname are files. You can use nano or pico to edit them if you're new to the OS. These files are owned by root, thus you need to use sudo to edit them.

Thus, the full command would be sudo nano /etc/hosts or sudo nano /etc/hostname

If you're on Ubuntu Server it's more advisable to use sudo hostname your.fqdn.com. This will automatically update the /etc/hostname file, however, if it doesn't you can always add the FQDN of your server into that file.

You will need to log out / log in to SSH to have these changes take effect for your session.

3

You can try sudo -i gedit /etc/hosts.

To edit the file in the terminal itself, use sudo vim /etc/hosts (advanced).

If you break something in this file, here's a fix.

1
  • It still says that tho,i tried to modify it with my current usernam because i mispelled it when i typed it the first time but it says sudo: unable to resolve host joli3-hp-g62-notebook-pc (gedit:9316): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files ** (gedit:9316): WARNING **: Set document metadata failed: Setting attribute metadata::gedit-spell-enabled not supported
    – Iulia Aset
    Aug 11, 2016 at 17:31

Not the answer you're looking for? Browse other questions tagged .