Editing /etc/hosts file with domain name?


I was trying to figure out why I couldn’t get some command line curl requests to work. Turns out /etc/hosts has: admin.mydomain.com

I thought maybe my scripts were installing that , but it seems to be coming from hst-install-ubuntu.sh:

if [[ -z $(grep -i "$servername" /etc/hosts) ]]; then
    echo " $servername" >> /etc/hosts

Is there a reason for that? If I comment it out, it works fine:

curl -4 http://admin.mydomain.com:8338/fail2ban

But with that line in the /etc/hosts, I get:

curl -4 http://admin.mydomain.com:8338/fail2ban
curl: (7) Failed to connect to admin.mydomain.com port 8338: Connection refused

I’ve commented it out for now so that it works, but I just want to try and understand why its in there, and if its important I leave it?