Emmanuel Stapf [ES] wrote:
> I'm writing a local server and I basically want the server to listen to
> the loopback address. On machines that supports both IPv4 and IPv6, I
> default to listening to ::1. Unfortunately, if I try to do:
>
> turin [Manu] : telnet 127.0.0.01 12111
> Trying 127.0.0.1...
> telnet: Unable to connect to remote host: Connection refused
>
> but if I use the IPv6 address it works.
>
> turin [Manu] : telnet -6 ::1 12111
> Trying ::1...
> Connected to ::1.
> Escape character is '^]'.
> quit
> Connection closed by foreign host.
>
> Conversely if instead of defaulting to the IPv6, I choose IPv4, then it
> is the reverse that is happening: I can connect to 127.0.0.1 but not on
> ::1.
>
> Any idea why it is like that?
>
> Thanks,
> Manu
>
> PS: If instead of listening to the loopback ::1, I listen on all
> addresses ::, then it works for both IPv4 and IPv6.
127.0.0.1 and ::1 are different addresses.
Chances are you're listening on the loopback because you expressly do
*not* want to listen on non-loopback (e.g., wired) addresses.
In that case, you should define both 127.0.0.1 and ::1 as localhost in
/etc/hosts and use "telnet localhost 12111" to connect. There's an RFC
that specifies that applications should use IPv6 preferably, but fall
back to IPv4 if IPv6 fails and an IPv4 address is available. telnet
complies with that RFC.
/etc/hosts
127.0.0.1 localhost
::1 localhost
You may also need to set "multi" in /etc/host.conf as well to allow
multiple numeric addresses per name. I use RH-flavored distros. In
RHEL5 and F9, it's not necessary to set multi. In F11, it is necessary,
but it's the default, anyway. YMMV
|