Cannot make a TCP connection on private network

1

I am testing the local connection between two OS X computers using netcat. They are both connected to the same router (through wifi) and have the same public IP, so I believe they have access to the same private network. Both have their firewalls turned off.

On one computer, I entered

nc -l 2000

and on the other computer,

nc localhost 2000

My understanding is that with a successful connection, whatever message that is entered into the client side should appear on the listening side. Currently, the second command is not starting netcat, which means that a connection was not established.

What are some potential issues preventing me from accessing the local network through these tests?

MakotoE

Posted 2018-01-12T02:04:15.973

Reputation: 131

It is extremely unlikely your second command is 'not starting netcat', since that would give an error message. Almost certainly it is starting netcat, which tries to connect and fails and therefore immediately exits. Try nc -v localhost 2000 to see the error. But localhost resolves to a loopback address (127.0.0.1 and/or ::1) which does not access any network at all, not even the (or a) local network. – dave_thompson_085 – 2018-01-12T07:06:11.113

Answers

0

In the second command, you should not be connecting to localhost, as this is your local machine. Instead, you should enter the hostname or IP address of the first machine.

multithr3at3d

Posted 2018-01-12T02:04:15.973

Reputation: 516

He is talking about "localhost", so I don't think that's the case. – davidgo – 2018-01-12T06:02:38.773

@davidgo I do not believe so. – multithr3at3d – 2018-01-12T06:09:38.157

Wow, thank you. I did not know until now that IPv4 (private) addresses and public IP addresses are different. – MakotoE – 2018-01-12T07:17:35.480

0

If your statement "and have the same IP" is true - if it is, that explains the problem. An IP address needs to be unique within the environment. IP addresses need to be in the same subnet (range), but should not be identical - In the case of 2 computers with the same IP address, they will not be able to communicate with each other (they will communicate with themselves), and it will cause massive issues for other devices trying to speak to the IP in question.

davidgo

Posted 2018-01-12T02:04:15.973

Reputation: 49 152

I think the OP means they have the same public IP and are behind a NAT. – multithr3at3d – 2018-01-12T05:29:57.433

My bad, I have corrected the question. I did mean to say they have the same public IP addresses. – MakotoE – 2018-01-12T07:12:37.773