3

I have a network with the following structure.

enter image description here

The server in PC2 is simple socket server TCP in 8080 port.

I need to access to PC2 from other external network by socket client. This socket client knows the public IP (85.xxx.xxx.x), the private IP (192.168.0.21) and the port.

How I can access PC2 without port forwarding on the router?

If possible, I would like to have a reference in any programming language of this case.

Additional info

SdevDavid
  • 33
  • 1
  • 1
  • 4

1 Answers1

2

How I can access PC2 without port forwarding on the router?

Assuming a NAT router (which is almost certain given a 192.168.0.0/24 internal network), you can't do this without port-forwarding at the router. Or something very similar.

For example if you can SSH to the router and then to the server you could use SSH tunelling (which is a form of port-forwarding).

You could also have PC2 SSH to a public server and make available a tunelled endpoint there. (you might need something like netcat or socat to assist with this)

In general, port-forwarding at the router is the way to go.


Protocols for NAT traversal

There are ways to enable this sort of communication without manual configuration of port-forwarding but they usually rely on router support and/or an external connection broker.

General

Specific


I would like to have a reference in any programming language of this case

If you are writing the software at both ends there are probably many examples you can follow.

For example, see

RedGrittyBrick
  • 3,792
  • 1
  • 16
  • 21
  • This question comes because I used on my Android device an application that establishes a socket TCP server when the device is connected through Wi-Fi (Tested with Nmap), and I can access with a client on another device of another network without any redirection ports. – SdevDavid Jun 12 '14 at 14:10
  • @SdevDavid: And does that app use an external server that mediates the connection? – RedGrittyBrick Jun 12 '14 at 14:19
  • Yes, it has a server to identify clients and servers, but communication between (Android client-Android server) is directly between two Android devices. – SdevDavid Jun 12 '14 at 14:29
  • For more information, this app does is, turn your device in an IP camera server and lets you connect with a client without port forwarding. And I'd like to know how it does. – SdevDavid Jun 12 '14 at 14:33
  • @SevDavid: To find out what your WiFi IP-camera does, you'd need an 802.11 sniffer. Or plug it into an intermediary Ethernet switch that has port-mirroring (or use a hub). But see IGDP in updated answer. – RedGrittyBrick Jun 12 '14 at 15:40
  • I have looked at the router's manual, and do not put it anywhere that supports IGDP. What I will do is sniff all traffic from the Wi-Fi network with a Wi-Fi card in a PC, use the Wi-Fi password and use wireshark to see what it does. When I do that, I will comment here which is the origin and destination of the frames. – SdevDavid Jun 12 '14 at 16:11
  • I have done the test with the server connected to Wifi and clinet by 3G. I search frames by TCP.port == 8014 in wireshark. I found that all communications are direct between the two devices, no server between them. – SdevDavid Jun 13 '14 at 13:53
  • @SdevDavid: Searching by the listening port on the Android device means you don't see any set-up traffic between device and router (or external service) prior to the establishment of an inbound TCP connection. – RedGrittyBrick Jun 13 '14 at 14:16
  • I tried to understand the connection setup but I not have enough knowledge to understand. I edited the first post with the frames captured in additional info if you can help me. – SdevDavid Jun 13 '14 at 16:44
  • You really linked to the Wikipedia page for "Hole punch"? (as in hole punch for a 3 ring binder kinda hole punch). Not sure thats relevant, lol. – Justin May 22 '18 at 17:29
  • @Justin: Thanks. Either I messed up 4 years ago or Wikipedia changed the disambiguation for the term. I'd like to think it's them, but it's probably me. – RedGrittyBrick May 22 '18 at 18:35
  • @Justin: Aha! It was Wikipedia pulling the rug from under me! https://web.archive.org/web/20140606023215/http://en.wikipedia.org/wiki/Hole_punching – RedGrittyBrick May 22 '18 at 18:39