Hostname not set properly

Hello all,

So I'm trying to set up a couple basic servers and I'm typically a GUI slob and use cpanel. I'm following along with the guides

I went with Ubuntu 16.04 as per recommendation.

I set the hostname, when I enter the 'hostname' command it returns the name that I set.

however when I try to disable logins with root as per here

Or try to install UFW here

I get a return that "sudo: unable to resolve host My_Hostname"

some things seem to complete properly but others don't seem to.

I'm sure It's something simple I'm missing and would appreciate any help offered up.



15 Replies

Your hostname needs an entry in the /etc/hosts file. The easiest way is probably just to add it with your Linode's public IP as this guide suggests.

/etc/hosts is used for stuff that needs to be internally resolvable on your machine, without any interaction with an external DNS server. Basically right now it's looking up your hostname but it doesn't map to anything.

This information used to reside in the Getting Started guide, but for some reason it has since been removed. It should probably go back there because right now it's giving you a kind of incomplete picture of what you need for a working system. I'll open an issue on there.

Thank you.

I opened the hosts file and changed the top line from localhost

to localhost.localdomain localhost

For public IP If I understand correctly I can change it from username

to hostnamesetpreviously

and I can remove the line ubuntu


thanks again

Yes, that looks ok. You don't need to specify a domain for localhost, though. Basically your hostname just needs to resolve to somewhere. As the Debian documentation notes:

For a system with a permanent IP address, that permanent IP address should be used here instead of

Since your Linode has a static IP, you should be fine just using that, and removing the entry for

You will want to make sure you are logged in as the root user. If you are using a terminal window (Terminal, iTerm, PuTTY) you can do this by following the command below.


From there it will ask for your password and you will be in as the root user. You can also use the Lish console.

You are going to want to update your /etc/hosts file as outlined here.

From there you should be good to go. You are absolutely on the right track and doing better than I did my first time trying this! If you need anything else let us know.


OK. Made some progress lol but stuck again for the moment.

Have the server up and responding to ping commands.

I have hosts file configured as above, and I added in

I followed along here for a LEMP setup

Everything went as expected. COnnected to server with SFTP via IP. all looks good.

I have the domain DNS pointed to cloudflare (currently lives on another LAMP server)

I changed the a record for the domain in CF pointing to the linode 50.xx IP address. When I try to access I get error 521.

I double checked in UFW that port 80 and 443 are allowed. disabled and enabled UFW.

Restarted nginx.

Now I'm officially stuck.

Thanks again for any help.

You should probably just provide the IP address for the Linode - it'd make it easier for others to troubleshoot this for you, and it's on the public internet anyway.

lol true, I just try not to give out any more info than required.

site is IP


Nevermind that, I found it..which wasn't very hard to do (if you're interested in keep it a secret with cloudflare) but I won't post it since you've not provided it yourself. Anyway, a quick check to see if it's listening shows that it's not:

PORT STATE SERVICE 80/tcp closed http 443/tcp closed https

You can confirm this by running nmap -p80,443 <your_ip_address>


  • Disable your firewall. I know you said you did it earlier, but I'd suggest just having it off for however long you're troubleshooting.
  • Run systemctl status nginx and provide the output here.
  • Run tail -n 40 /var/log/nginx/error.log and add the output here.
  • Run nginx -T to check for config errors, add the output here.

ok disabled the firewall and still seeing 521

ran nginx status

nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en Active: active (running) since Wed 2018-03-28 00:50:26 +06; 19h ago Process: 29920 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 Process: 29925 ExecStart=/usr/sbin/nginx -g daemon on; masterprocess on; (cod Process: 29923 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; masterprocess Main PID: 29929 (nginx) CGroup: /system.slice/nginx.service ├─29929 nginx: master process /usr/sbin/nginx -g daemon on; master_pr └─29931 nginx: worker process

I ran

tail -n 40 /var/log/nginx/error.log

and there was no output.

Nginx config

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

configuration file /etc/nginx/nginx.conf:

user www-data; worker_processes auto; pid /run/;

events { workerconnections 768; # multiaccept on; }

http {

    # Basic Settings

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # SSL Settings

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    # Logging Settings

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Gzip Settings

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    # Virtual Host Configs

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;


mail {

# See sample authentication script at:



# auth_http localhost/auth.php;

# pop3_capabilities "TOP" "USER";

# imap_capabilities "IMAP4rev1" "UIDPLUS";


server {

listen localhost:110;

protocol pop3;

proxy on;



server {

listen localhost:143;

protocol imap;

proxy on;



configuration file /etc/nginx/mime.types:

types { text/html html htm shtml; text/css css; text/xml xml; image/gif gif; image/jpeg jpeg jpg; application/javascript js; application/atom+xml atom; application/rss+xml rss;

text/mathml                           mml;
text/plain                            txt;
text/      jad;
text/vnd.wap.wml                      wml;
text/x-component                      htc;

image/png                             png;
image/tiff                            tif tiff;
image/vnd.wap.wbmp                    wbmp;
image/x-icon                          ico;
image/x-jng                           jng;
image/x-ms-bmp                        bmp;
image/svg+xml                         svg svgz;
image/webp                            webp;

application/font-woff                 woff;
application/java-archive              jar war ear;
application/json                      json;
application/mac-binhex40              hqx;
application/msword                    doc;
application/pdf                       pdf;
application/postscript                ps eps ai;
application/rtf                       rtf;
application/         m3u8;
application/              xls;
application/         eot;
application/         ppt;
application/vnd.wap.wmlc              wmlc;
application/  kml;
application/      kmz;
application/x-7z-compressed           7z;
application/x-cocoa                   cco;
application/x-java-archive-diff       jardiff;
application/x-java-jnlp-file          jnlp;
application/x-makeself                run;
application/x-perl                    pl pm;
application/x-pilot                   prc pdb;
application/x-rar-compressed          rar;
application/x-redhat-package-manager  rpm;
application/x-sea                     sea;
application/x-shockwave-flash         swf;
application/x-stuffit                 sit;
application/x-tcl                     tcl tk;
application/x-x509-ca-cert            der pem crt;
application/x-xpinstall               xpi;
application/xhtml+xml                 xhtml;
application/xspf+xml                  xspf;
application/zip                       zip;

application/octet-stream              bin exe dll;
application/octet-stream              deb;
application/octet-stream              dmg;
application/octet-stream              iso img;
application/octet-stream              msi msp msm;

application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;

audio/midi                            mid midi kar;
audio/mpeg                            mp3;
audio/ogg                             ogg;
audio/x-m4a                           m4a;
audio/x-realaudio                     ra;

video/3gpp                            3gpp 3gp;
video/mp2t                            ts;
video/mp4                             mp4;
video/mpeg                            mpeg mpg;
video/quicktime                       mov;
video/webm                            webm;
video/x-flv                           flv;
video/x-m4v                           m4v;
video/x-mng                           mng;
video/x-ms-asf                        asx asf;
video/x-ms-wmv                        wmv;
video/x-msvideo                       avi;


Can I see the actual config in /etc/nginx/sites-enabled? Try to use markdown for your code blocks so they're formatted correctly.


I when I navigate to the directory etc/nginx/sites-enabled and enter

ls it shows that is there

When I open it it shows as a new file So then I enter the following in the file

server {
        listen 80;
        listen [::]:80;


        root /var/www/html/;
        index index.php index.html;

        location / {
                try_files $uri $uri/ =404;
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                include fastcgi_params;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_param SCRIPT_FILENAME /var/www/html/woodbuffalodesign.c$

Then when I attempt to exit and save i get an error "too many levels of symbolic links"

Thank again for all your help

That LEMP guide has you create a config under /etc/nginx/sites-available and then symlink it.

You should probably just remove the file (rm /etc/nginx/sites-enabled/ and then create a new one with your config info in the sites-enabled directory. Then reboot nginx.

Ok deleted and then re-created the file with exactly what's been pasted above. file saved no issue.

I then tried to restart nginx, and got an error.

there was an unexpected } on line 18.

triple check everything, only one set of braces for server, and two different sets for location.

I removed the brace on line 18, and it returned "unexpected }" this time on 19. Removed it too and got the error you would expect - "unexpected end of file".

I compared my file against other examples online and the default example and I don't see what I am missing.

Thank you.

Your problems are on this line:

fastcgi_param SCRIPT_FILENAME /var/www/html/woodbuffalodesign.c$

This needs a semicolon at the end of it. Also, woodbuffalodesign.c$ as a script name is going to cause separate errors as well. I'm assuming this is a typo.

If you fix both of those things your nginx config should work.

OK, I did as you said and added a semicolon,

When I changed .c$ to a .com I got "Access denied" when I try to view the domain.

When I removed it entirely I get "File not found"

I have all of my files installed to the public_html directory and confirmed that my index.php file is there.

Thanks again for all the help.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct