Search code examples
network-programmingiprouterportforwardingnat

Identifying correct IP address of my machine


Let's say we have a wifi at home. When I google "whatsmyip", it gives me public IP address, which is essentially IP address of my router on the internet.

Now lets say I have two machines (A and B) both hosting a web server. I want to reach to a web-server on my machine 'A' from outside my local network (from some other corner of the world), how I can ping to that specific machine to my network. I understand for outgoing requests from my machine we have NAT, but what about incoming request to a specific machine? How router resolves it?

How I can check that IP(for incoming requests) in my windows/linux machine?

e.g let's say I have a tomcat server running on port 8080 on machine A. Now if I do localhost:8080/home, it displays "Hello World". Now one of my friend in let's say in Europe wants to access "/home" end point. What ip would he use?{IP}:8080/home. Means how he'll identify my machine, as to the internet only router's IP address is visible


Solution

  • To be able to reach your comptuer on the LAN behind your router you will need to do a port forward.

    All connections to your public x.x.x.x:p ip/port address are forward to y.y.y.y:p
    

    You can't forward different connections with the same port to a different machine in your lan, you will have to implement a more sophisticated approach to be able to do that, like a load balancer and apply a rule's base on the domain etc.

    To be able to ping, you have to forward ICMP request to your lan machine.