0

I cannot access local services such as ldap when a network cable is not connected to the host. Should the address to these local services be the ip to the host or should it be 127.0.0.1 for all of them?

This is my etc hosts files:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.236 my-ldap my-ldap
10.10.10.236 my-ntp my-ntp
10.10.10.236 my-db my-db
joaerl
  • 397
  • 1
  • 3
  • 11
  • Use localhost (127.0.0.1) for local services. Or bring up eth0 with static ip 10.10.10.236 at boot. – Ipor Sircer Oct 19 '16 at 12:16
  • More interesting is your /etc/network/interfaces file. My guess is that you have your IP 10.10.10.236 assigned as fixed but if the cable is unplugged the interface is down and thus the IP isn't assigned any more. – Broco Oct 19 '16 at 12:16
  • Or, if you're on a RedHat variant, your `/etc/sysconfig/network-scripts/ifcfg-eth0` file. – MadHatter Oct 19 '16 at 12:31
  • @Ipor eth0 is assigned static ip 10.10.10.236. Using 127.0.0.1 for local services in etc hosts works, but is it "as intended"? – joaerl Oct 19 '16 at 12:44
  • Yes. Never use public interface address for localhost access. It will make more troubles when you begin to use iptables to filter incoming traffic. – Ipor Sircer Oct 19 '16 at 12:55
  • @Ipor Could you please make that an answer out of what you have said so that I can accept it. Even if the answer from mzhaase contains some useful information it does not describe the solution to my problem. – joaerl Oct 25 '16 at 10:30

1 Answers1

3

IPs are only assigned when the interface is 'UP' which is only the case when the cable is plugged in. The localhost IP 127.0.0.1 is always up, though. As such, if you want to access services locally, you might want to have them listen on localhost as well.

mzhaase
  • 3,798
  • 2
  • 20
  • 32
  • Are you suggesting that my problem lies in the configuration of the services? So what I should do is to reconfigure ldap, ntp and the database to listen on localhost? – joaerl Oct 19 '16 at 12:52
  • As much as I dislike 'rtfm' as an response, you will indeed have to look up the documentation of these services to see how to change the listen address. Usually you can just listen on every IP with 0.0.0.0 or similar. This is different from service to service. – mzhaase Oct 19 '16 at 12:54