1

I might sound silly, but I'm beginner.

If there are two hosts with the same IP but one is public and the other is private.

If I send a packet to that IP. Will it be forwarded to the local host on my LAN or to the public host on the Internet ?

  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you can provide and accept your own answer. – Ron Maupin Dec 25 '18 at 8:21
1

How does the router know if this ip is local or global ?

I believe you mean "private" or "public" IP addresses, and the answer is: the router doesn't care. IP addresses are IP addresses, and they're all routed the same. If you're using private addresses, and the network is connected to the Internet, then somewhere a device is performing Network Address Translation to change your private addresses into public (globally routable) ones.

Then how does the router know if it should redirect it inside the local net or send it to Internet ?

Again, the router doesn't distinguish between private and public addresses. It simply looks in its routing table and forwards based on the destination IP.

  • If say for example, I have a local host on my LAN with IP: 1.2.3.4 and my machine IP: 1.2.3.5 and I want to ping the public IP 1.2.3.4 so I typed "ping 1.2.3.4" now what will the router do ? – Kh5 Apr 23 '18 at 11:43
  • First of all you would have a terrible setup. You should never use anything but 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 as private IPs. That being said: The router would check it's route table and would find 1.2.3.4 belonging to an attached device and route the packet to it directly. – Matthias Merkel Apr 23 '18 at 11:49
  • 2
    1.2.3.4 and 1.2.3.5 are on the same subnet, so your machine will determine the target address is on the directly connected subnet, and ARP for the layer 2 address. . The router will not be involved at all. – Ron Trunk Apr 23 '18 at 11:50
  • Well, I think he assumed that - for some reason - the router did get the packet. – Matthias Merkel Apr 23 '18 at 11:51
  • 2
    @MatthiasMerkel The machine would never send the packet to the router, so it's not involved. – Ron Trunk Apr 23 '18 at 11:51
1

If there are two hosts with the same IP but one is public and the other is private.

Two hosts can't have the same IP address (from the router's perspective). Accordingly, the router has only a singular destination for any IP address.

Whether the IP address is public or private is a matter of convention. 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 are set aside for priate networks (RFC 1918), ie. they aren't routed on the public Internet and can be used by anyone privately.

A router generally doesn't make a difference between public and private. It might be configured to translate (NAT) in one direction or the other, but this is actually more a matter of the interfaces used rather than the addresses alone.

If I send a packet to that IP. Will it be forwarded to the local host on my LAN or to the public host on the Internet ?

The router checks the routes in its routing table and the most specific one (longest network mask) that matches the IP address is used. Depending on the ingress and egress interfaces, additional actions like source or destination NAT may be used (especially on the edge between private and public address space).

1

Of course it depents on what you have configured (The router doesn't care about public/private IPs, he does that what you configured him to do), but I assume a "normal" environment as you probably don't want to here an exact and every-possibility-including-answer - so: your home (normal configured) router and a LAN with a private-IP-Range and "somehow" a device on the outside which has the same IP as one device in your LAN.

To the one on your LAN as normally an interface of your router is configured to be in your LAN (if you haven't configured it differently). Because of that the router makes an entry in his routing-table (which the routers desitions to forward packets are based on) that this network and the hosts in it can be reached by this interface. You cannot configure another interface with the same or with an overlapping network, therefore there is just that one interface and one entry in your routing table. If there should be a host on the outside with the same IP, nothing is configured (no routing-table-entry) on the router to forward packets to him, so he doesn't even care, as there is just one entry belonging to one interface - pointing to your LAN.

0

According to standards set forth in Internet Engineering Task Force (IETF) document RFC-1918, the following IPv4 address ranges have been reserved by the IANA for private internets, and are not publicly routable on the global internet:

10.0.0.0/8 IP addresses: 10.0.0.0 -- 10.255.255.255
172.16.0.0/12 IP addresses: 172.16.0.0 -- 172.31.255.255
192.168.0.0/16 IP addresses: 192.168.0.0 – 192.168.255.255

If the ipv4 address is public (routable) then the router will use the NAT protocol to find the host.

  • 3
    But, the router doesn't know or care about public or private addresses. There is nothing in IP that distinguishes public or private addresses. The ISPs have simply agreed to not route traffic to the addresses in RFC 1918 on the public Internet. That has nothing to do with whether or not a router knows the difference. – Ron Maupin May 2 '18 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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