1

I'm trying to virtualize a telnet server for multiple ip address's. While still being able to talk to the same remote servers.

What is the correct file path for a UNIX TCP Socket running on a virtualized IP? Or is there a way of connecting locally and ignoring the routing tables?

I have virtualized the IP's on loopback as follows:

 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet6 ::1 prefixlen 128 
    inet 127.0.0.1 netmask 0xff000000 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    inet 10.10.0.24 netmask 0xff000000  
    inet 192.168.10.2 netmask 0xffffff00 
    inet 192.168.10.3 netmask 0xffffff00 
    inet 192.168.10.4 netmask 0xffffff00  
    nd6 options=1<PERFORMNUD>

The Routing table is configured with static routes so that the outbound connection can still reach the intended destination. (I have tried turning this off and it still didn't help)

Routing tables
Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire

192.168.10.2       192.168.10.2       UH              0       75     en1
192.168.10.3       192.168.10.3       UH              0       75     en1
192.168.10.4       192.168.10.4       UH              0       75     en1

I can confirm that the servers are listening and bound to the correct socket.

sudo lsof -i -n | \grep 'telnet'
Python    69212           root    6u  IPv4 0x7002eb6c7a9b50e1      0t0    TCP 192.168.10.4:telnet (LISTEN)
Python    69212           root    7u  IPv4 0x7002eb6c7db219b1      0t0    TCP 192.168.10.3:telnet (LISTEN)
Python    69212           root    8u  IPv4 0x7002eb6c4f254b51      0t0    TCP 192.168.10.2:telnet (LISTEN)

I have tried a few different ways of connecting to the local server. And have removed the local servers so I can prove that I am connecting locally.

telnet -u /dev/tcp/192.168.10.5/23
    Trying /dev/tcp/192.168.10.5/23...
    /dev/tcp/192.168.10.5/23: No such file or directory

socat -v READLINE UNIX-CONNECT:/dev/tcp/192.168.10.5/23
    2015/01/27 11:32:39 socat[92588] E connect(6, LEN=26 AF=1 "/dev/tcp/192.168.10.5/23", 26): No such file or directory

1 Answer 1

0

You are mixing things up.

UNIX sockets are one thing: they use objects in the file system which have paths and can be addressed with them.

TCP/IP sockets are another thing. You can do the same over them, but you address them differently.

With telnet, you would do

telnet -u 192.168.10.5

and with socat it is like

socat -v READLINE TCP:192.168.10.5:23

The /dev/tcp stuff is just a thing made up by the shell; it does not really exist.

4
  • The socat version works a charm. When I run telnet -u 192.168.10.5 I get back 192.168.10.5: ai_family not supported. In looking at the documentation in a bit more detail, I need the AF_UNIX address. I'm curious now, is there a way of getting an AF_UNIX address from the ip and the port? I guess I hoped that was what was happening under the covers of /dev/tcp/hostname/port
    – Luke Exton
    Jan 27, 2015 at 21:25
  • @Luke Again, there is no AF_UNIX address for a TCP/IP connection. These are completely distinct namespaces. I don't know why it doesn't work with telnet...
    – glglgl
    Jan 28, 2015 at 7:28
  • BTW, what does -u do on your version of telnet?
    – glglgl
    Jan 28, 2015 at 7:30
  • The BSD flavour Forces telnet to use AF_UNIX addresses only. I worked out the issue though, I was using a relative path(./path-to-socket) rather than fully qualified path to the socket $(pwd)/path_to_socket. Not 100% sure why that matters, but its working now with telnet -u
    – Luke Exton
    Jan 28, 2015 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.