Networking Forums

Networking Forums > Computer Networking > Linux Networking > How to listen on loopback address on both IPv4 and IPv6?

Reply
Thread Tools Display Modes

How to listen on loopback address on both IPv4 and IPv6?

 
 
Emmanuel Stapf [ES]
Guest
Posts: n/a

 
      05-08-2009, 06:15 PM
Hi,

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.
 
Reply With Quote
 
 
 
 
Pascal Hambourg
Guest
Posts: n/a

 
      05-08-2009, 07:12 PM
Hello,

Emmanuel Stapf [ES] a écrit :
>
> 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

[...]
> 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?


Obvious : ::1 and 127.0.0.1 are different addresses. If you want to
listen to the same port on several adresses - but not all local
addresses - I am afraid you must open a separate socket per address.
E.g. this is what BIND does for its control channel on port 953 :

tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN
tcp6 0 0 ::1:953 :::* LISTEN

> PS: If instead of listening to the loopback ::1, I listen on all
> addresses ::, then it works for both IPv4 and IPv6.


:: listens on any local IPv6 address, and by default on any local IPv4
address too.
 
Reply With Quote
 
Allen Kistler
Guest
Posts: n/a

 
      05-08-2009, 09:09 PM
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
 
Reply With Quote
 
Emmanuel Stapf [ES]
Guest
Posts: n/a

 
      05-11-2009, 04:16 PM
Allen Kistler wrote:
> 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.


This is correct because I'm writing a piece of software that runs on
both Windows and Unix and on Windows if you have the firewall enabled
and that you listen on :: then you trigger a dialog box which we don't
want since the sockets will be used locally.

Is there a better way to listen to loopback 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


This is beyond my control, I cannot ask people using the software to
modify this low level configuration file.

Thanks for the clarification,
Regards,
Manu
 
Reply With Quote
 
Pascal Hambourg
Guest
Posts: n/a

 
      05-11-2009, 08:14 PM
Emmanuel Stapf [ES] a écrit :
>
> Is there a better way to listen to loopback addresses?


Open two sockets, one IPv6 socket listening on ::1 and one IPv4 socket
listening on 127.0.0.1.
 
Reply With Quote
 
Emmanuel Stapf [ES]
Guest
Posts: n/a

 
      05-13-2009, 04:26 PM
Pascal Hambourg wrote:
> Emmanuel Stapf [ES] a écrit :
>>
>> Is there a better way to listen to loopback addresses?

>
> Open two sockets, one IPv6 socket listening on ::1 and one IPv4 socket
> listening on 127.0.0.1.


Doesn't this require to have two running threads?

Manu
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IPv6 address not connecting but IPv4-mapped -IPv6 does. Please help. DanielJohnson Network Routers 0 01-07-2009 12:10 AM
Using IPv4 TCPMSS target with IPv6-in-IPv4 Mark T.B. Carroll Linux Networking 1 03-18-2007 10:30 AM
IPv6 to IPv4 tjm Windows Networking 0 03-23-2006 07:53 PM
IPv4 IPv6 And routers kernel.lover Linux Networking 3 02-03-2005 06:17 AM
IPv4 --> IPv6 Anthony T. Wilson Linux Networking 2 12-20-2003 08:23 PM



1 2 3 4 5 6 7 8 9 10 11