socket communication between two device under sub-Lan - sockets

For two device both has public IP address, we can use socket IP and port to setup socket communication.
If both device do not has public IP but connect to sub-Lan then access public network through router (no port mapping in router), how can this two device setup socket connection?
For example in above diagram, how can machine A communicate with machine C?

Assuming that you have not set up a VPN tunnel between the two routers that connects both branches of the 192.168.1.0/24 network then the answer is: you can't.
If you set up a VPN tunnel then each side of the 192.168.1.0/24 network will be able to see the other side. Please note that the routers will need to be able to do ARP spoofing, i.e. the router for A & B will need to be able to spoof the MAC for C, i.e. intercept IP packages for C on their LAN and forward them through to the VPN to the other network half where they are delivered to C.
If you set up at least one port forwarding on one router, then you'll have other options, e.g. an SSH tunnel on C that connects to the port forward on either A & B. You can then use the -L option on C to setup port forwarding through the SSH tunnel to the other half of the network.

Related

How Can I ping or create a scoket connection with my friend?

When we ping to any Public IP of a router it give a reply,
we dont get reply, if we ping a local computer with its private IP of a particular network,
So is there a way so I can make direct connection or socket with a particular PC in a network.
I have heard that, I have to make connection with public IP of a particular network and the port number will decide, on which PC in that network , my request will go.
But this method is not working..
If the computer is behind a router that uses Network Address Translation (NAT) - that is, the computer has a private IP that is not visible to the internet - then you cannot ping or establish a connection to the computer from the outside. This is because the router does not know which computer you want since all the computers behind the router share the same public IP address.
The way to establish a connection in this case is to have the computer which is behind the router establish the connection to the outside computer. For example, when you go to a web site, you can do it from a computer behind a router since your computer is initiating the connection. However, the web server you are going to must have a public IP.
When a computer behind the router initiates a connection, the router does select a port number to associate with that connection so packets from the outside for that connection will go to the right computer. However, this only works for traffic on that particular connection; the port number is not a general purpose mapping to that computer.
Two computers behind the same router can establish connections with each other using the private IPs as they don't have to go through the router to do it.
You can decide with your friend who is going to be the client (the one initiation the TCP connection) and who is the server (the one receiving the TCP connection) and which port should be used (let's say X). Let's say that your friend is the server. Then he/she has to configure his/her router to redirect all the traffic to the router to port X to his/her private IP to port X (this is what Warren mentioned as NAT).
If you use a port above 1024, the server (running on your friend's PC) doesn't need root/administrator privileges.
Your program (the client) would then connect to the public IP address of your friend. He/she can check his/her public IP with: What is my IP

TCP/IP using Socket Test 3.0 software

I have 'Socket test v-3.0' software installed on two different PCs.
Using it can create a TCP server on 1st PC and a TCP client on 2nd PC.
When I connect both the PCs on LAN I can establish a connection & can communicate between the Server & Client.
But, When I connect both the PCs to individual Internet connections (Using dongles having different ISPs), I couldn't establish the connection between the Server & Client.
How can I do that?
Please help me out..
The private address 192.168.x.x is address that can be used for direct connection only in your private network. If you want to connect to your machine from public internet you have two options:
Get a public IP address
Configure a port forwarding
Public IP address could be get from your internet provider but it is usually requires some extra payment dependent on your service provider policy.
Port forwarding can be configured at the device at the border between your private network and internet. The device does the NAT (network address translation) between your private network and intenet. Use google if you are not sure about NAT.
Such a device can be your own device like an ADSL modem or a set top box. But such a device could be in the internet provider network. If you own the device then you can configure the port forwarding yourself. Modems usually have a web interface where you can easily configure port forwarding. See the documentation to your modem or whatever you have.
If the NAT device is in internet provider network then you have to ask it to configure port forwarding for you. Before you ask please read something about port forwarding so you are sure what you want to configure.

Connecting to TCP server running in a machine connected to private home LAN

I like to connect to a TCP server that run in a machine that is connected to the LAN in my home network. This LAN can be connected to internet via either following methods.
1. Through a router which has a wireless or wired WAN connection
2. Through a router which uses a mobile broadband connection, for example a router that accept a USB modem to connect to internet.
I know in the first case, we can use port forwarding.
In the second case, I believe telcos use PPP protocol and port forwarding does not work.
In addition, even in the first case, if ISP does not give a static IP, then we need to use DNS mapping service to map a fixed URL to the allocated dynamic IP and we need to configure router to go and register the dynamic ip at the start up.
My question is, are there any other better methods that can be used in this situation? I am wondering how chat applications connect to each other? I hope they maintain a TCP connection between two devices, without a central relay server?

Connection between arduino(wifi shield) and PC locally, with router

I want to connect my PC-with-arduino (server client) with TCP/IP socket. In my PC i have written java code to make this happen. My questions are : I have to make port forwarding to my router? If yes, i will pass the port socket(client-server) into router? I have the zte zxv10 h108l router and i can't find any instructions about port forwarding for this model!
You say locally, which means you do not need any port forwarding. All your devices are on the same subnet, and you can directly open connections with each other.
Port forwarding would only be necessary if something outside you network wants to open a connection to something inside. Basically, if something on the WAN side of the router wants to open a connection to something on the LAN side. For example, you at a coffee shop on your laptop connecting to Arduino in your house.
Note that the reverse does not hold: something on the LAN side can open a connection to something on the WAN side with no port forwarding -- that is the NAT function of the router and is always active. For example, that is how your computer connects to stackoverflow with no special configuration on the router.

How to connect to another machine behind multiple gateways using IP?

I did not know where to ask this so here it is. This is more of a networking technology question, but any pointers will help.
Suppose, I want to connect to a machine behind multiple gateways. Say I want to connect to my home computer from my office computer. My home computer is behind my ISP's gateway and then behind my wireless router at home. Let's say I know the IP's for all of them. (global IP for my ISP's gateway, local IP for my wireless router within my ISP's n/w and my home machine's local IP within my home). How do I initiate a TCP connection with my home computer ? The standard berkeley socket program only takes one IP and so I can only connect to machines that have global IPs.
Is there a solution ? Am I correct about the berkeley sockets ?
Thanks.
It is entirely possible, with the cooperation of the ISP. The fact that the ISP is giving private addresses should urge you to move to another.
The concept you're after is called DNAT or Port Forwarding.
Let's say you decide on accessing port 1234 on a PC. The address of the PC is Local2. The address of the wireless router (in the network with the ISP) is Local1.
The wireless router must do the translation Local1:X -> Local2:1234
The ISP router must do the translation Public:1234 -> Local1:X
The X means any port can be used.
You only need to know the destination IP address to connect from an application, the gateway address is for the forwarding (routing) of packets which is handled by the OS network stack. However, if the destination is behind NAT, you'll only know the public IP address of the destination's NAT device. Even in this scenario, all you have would be an IP address and you don't really know if there is NAT going on.
If your destination is fixed, you could set up port forwarding on the NAT device (if you control it). Otherwise, you just realized that NAT is pure evil.
In your situation, it appears you want to connect to your home computer. If your wireless device has a public IP address, you can setup port forwarding on that to forward all incoming traffic on a port to a port on your home computer.