Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with localhost entry in hosts file 3

Status
Not open for further replies.

bazil2

Technical User
Feb 15, 2010
148
DE
I have inadvertently deleted an important line in /etc/hosts namely that for the local host.

Can anyone confirm the correct entry; do I also need a short name?

127.0.0.1 localhost

Best regads
 
That entry should be fine.

Our RHEL systems also have "loopback" on that line:

Code:
127.0.0.1       localhost loopback

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
(Elementary user)

Many thanks, my /etc/hosts entry now contains the line you mentioned:

[root@sgi ~]# more /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost loopback

However, when trying to execute curl for example, the local host can't be found:


[root@sgi ~]# /usr/bin/curl curl: (7) couldn't connect to host
[root@sgi ~]# /usr/bin/curl curl: (7) couldn't connect to host
[root@sgi ~]# /usr/bin/curl curl: (7) couldn't connect to host

I can however ping the local host successfully:

[root@sgi ~]# ping loopback
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.020 ms

[root@sgi ~]# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.023 ms

[root@sgi ~]# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.023 ms

Can you think of any reason why the curl programme can't connect to the host?

Best regards
 
Did you check if there is a webserver up and running on that host?
 
Yes, the machine can be accessed via the web; Apache is installed.

 
Is Apache configured to listen on localhost? How about if you curl the IP address of the host instead of the localhost (even though you're running it on the same host), does that work?

If you haven't restarted Apache since fixing your hosts file, try that, as it may have attempted to listen on that host name, not found it, and skipped on to any other valid addresses.

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Check the http port is listening with:

Code:
# telnet 0 80


-bash-3.00$ telnet 0 80
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
GET /
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>Test Page for Apache Installation</title>
</head>

more ...........


<div align="center"><img src="apache_pb.gif" alt="" /></div>
</body>
</html>

Connection to 0 closed by foreign host.
-bash-3.00$

Then be sure that curl is using files before dns to resolve the host

Check resolv.conf to be sure that you have:

hosts: files dns

And not the other way around.

Laurie.
 
Thank you both very much!

All of the following succeed when appended to: /usr/bin/curl http://

the external IP
the internal IP
the short name
the long name (web address)


Here is the output:

[root@sgi ~]# cat /etc/resolv.conf
search localdomain
nameserver xxx.xxx.xxx.xxx (IP hidden for security)

Does this help?

Best regards
 
My RHEL server contains the following in /etc/hosts:

# Do not remove the following line, or various programs
# that require network functionality will fail.
::1 localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost
 
Doh sorry I ment nsswitch.conf not resolv.conf .... (reading one thing while writing another mistake).

Have you rebooted since the changes you made ? ... probably not vital but something is not being read (excuse the pun .. resolved)

Laurie
 
Thank you both!

No problem, here is the (abridged) output:

#hosts: db files nisplus nis dns
hosts: files dns

Yes, after editing the /etc/hosts file I rebooted.

I think I will try and copy tonykent's two lines in to my hosts file?

Best regards
 
OK, I have edited the file as follows:

[root@sgi bin]# more /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
::1 localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost
#127.0.0.1 localhost loopback

Is there anyway of forcing the hosts file to reload or is a reboot necessary?

Curl didn't react any differently:

[root@sgi bin]# ./curl curl: (7) couldn't connect to host


Best regards
 
Here is the output of the telnet command:

[root@sgi bin]# telnet 0 80
Trying 0.0.0.0...
telnet: connect to address 0.0.0.0: Connection refused
telnet: Unable to connect to remote host: Connection refused
[root@sgi bin]#

I also checked the file: /etc/httpd/conf/httpd.conf

An found this entry:
...
Listen xxx.xxx.xxx.xxx:80 (IP removed for security)

Best regards
...
 
Thats strange although "telnet 0 80" nis not quite the same as "telnet localhost 80" as 0 (zero) goes to 0.0.0.0 where as localhost should go to 127.0.0.1

Try the latter and see if the output is the same or not ...

But you say that you can get to the "real" IP that your server is listening on is that correct? And you are sure its not just a cache of the index page you are seeing? ... Silly questions I know but something is not right here ....

It does sound strange, you are not running a firewall on your server that's blocking (dynamically reset after removing localhost) are you ?

And you are sure you have the httpd Apache daemons running when you check with `ps -ef | grep http`

Sorry its getting me beat ..... only a really remote other thing is netmasks ?? is the netmasks file looking ok ?

and what does ifconfig -a show do you see the loopback supporting 127.0.0.1 ?

Laurie.
 
Hello Laurie,

Here you are; I'm not sure where to look for netmasks?

[root@sgi bin]# telnet localhost 80
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
Trying ::1...
telnet: connect to address ::1: Connection refused
telnet: Unable to connect to remote host: Connection refused
[root@sgi bin]#

No firewall is in operation on the server.

[root@sgi bin]# ps -ef | grep http
apache 3863 5220 0 08:39 ? 00:00:01 /usr/sbin/httpd
root 5220 1 0 06:28 ? 00:00:00 /usr/sbin/httpd
apache 5238 5220 0 06:28 ? 00:00:01 /usr/sbin/httpd
apache 5239 5220 0 06:28 ? 00:00:01 /usr/sbin/httpd
apache 5240 5220 0 06:28 ? 00:00:01 /usr/sbin/httpd
apache 5241 5220 0 06:28 ? 00:00:01 /usr/sbin/httpd
apache 5242 5220 0 06:28 ? 00:00:01 /usr/sbin/httpd
apache 5243 5220 0 06:28 ? 00:00:01 /usr/sbin/httpd
apache 5244 5220 0 06:28 ? 00:00:01 /usr/sbin/httpd
apache 5245 5220 0 06:28 ? 00:00:01 /usr/sbin/httpd
apache 9719 5220 0 09:29 ? 00:00:01 /usr/sbin/httpd
root 10745 5624 0 15:29 pts/2 00:00:00 grep http
apache 22746 5220 0 10:21 ? 00:00:01 /usr/sbin/httpd
apache 31562 5220 0 09:17 ? 00:00:01 /usr/sbin/httpd
[root@sgi bin]#


[root@sgi bin]# ifconfig -a
bond0 Link encap:Ethernet HWaddr 00:30:48:7F:98:9E
inet addr:xxx.xxx.xxx.xxx Bcast:xxx.xxx.xxx.xxx Mask:255.255.255.0
inet6 addr: fe80::230:48ff:fe7f:989e/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:21881934 errors:0 dropped:0 overruns:0 frame:0
TX packets:28973856 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6458715991 (6.0 GiB) TX bytes:31100661166 (28.9 GiB)

eth0 Link encap:Ethernet HWaddr 00:30:48:7F:98:9E
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:13866750 errors:0 dropped:0 overruns:0 frame:0
TX packets:18703585 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4540878853 (4.2 GiB) TX bytes:20464930011 (19.0 GiB)
Memory:d8420000-d8440000

eth1 Link encap:Ethernet HWaddr 00:30:48:7F:98:9F
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:8015189 errors:0 dropped:0 overruns:0 frame:0
TX packets:10270282 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1917837468 (1.7 GiB) TX bytes:10635733465 (9.9 GiB)
Memory:d8460000-d8480000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12546 errors:0 dropped:0 overruns:0 frame:0
TX packets:12546 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:17500060 (16.6 MiB) TX bytes:17500060 (16.6 MiB)

sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

[root@sgi bin]#


 
Well that is very strange as all components look to be in place.....

AH! bond0 .... thats interface teaming (what I know on Solaris to be IPMP IP Multi pathing) ... Now we are heading into territory that I'm not familiar with on Linux but a quick google puts me a little in the picture and I wonder if your Apache httpd is only listening on the bond IP and not allowing access via the loopback

Some tests:

1) check whats listening and whats not with
Code:
# netstat -an | grep -i listen

We expect to see port :80 on the loopback

Code:
[admin@abcd1234 admin]$ netstat -an | grep -i list
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN
tcp        0      0 283.270.211.342:53        0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 283.270.211.342:443       0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:444             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:23              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:9022            0.0.0.0:*               LISTEN
unix  0      [ ACC ]     STREAM     LISTENING     378    /tmp/.s.PGSQL.5583
unix  0      [ ACC ]     STREAM     LISTENING     532    /tmp/mysql.sock
unix  0      [ ACC ]     STREAM     LISTENING     6322250 /var/run/ndc
[admin@abcd1234 admin]$

2) see if you can telnet localhost to another of the listening ports

Code:
# telnet localhost 23

Code:
[admin@abcd1234 admin]$ telnet localhost 23
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
SSH-1.99-OpenSSH_3.7.1p1

Connection closed by foreign host.
[admin@abcd1234 admin]$

If your not able to get to anything from the loopback then we can rule out Apache but otherwise it has to be apache not listening on the loopback (why I have no idea).

Good luck

Laurie.
 
Look for the "Listen" directive in your httpd.conf, it specifies which ports (and optionally IP addresses) it tries to listen on.

lsof -a -i -p <PID of httpd process> will show you what it is listening on right now.

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Hello Everyone,

I have managed to resolve this problem with the via RedHat; you were all so close to resolving the issue and I think they'll be some forehead slapping!

The entry in my httpd.conf file was:
Listen 123.456.789.200 80

I was asked to change it to:
Listen 80

It then worked, I'm not sure why though, the IP was the IP of the machine.


Thank you all so much for you help!
 
Sorry that should have read: Listen 123.456.789.200:80
 
Here's a rough explanation:

... http was not listening on the local host, only on port 443, but not on 80.

May be a bug?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top