is public IP unique? I mean that we have two kind of IP: private and public and if public IP belongs to router,does every one connect to one router have a single IP address or not?
In general terms the answer is yes, public IPs are globally unique.
In the IPv4 context, the IPs (v4) known for not being unique are the private IPs, these are found in the following ranges:
- From 10.0.0.0 to 10.255.255.255.
- From 172.16.0.0 to 172.31.255.255.
From 192.168.0.0 to 192.168.255.255.
The IP your home router has on the "internet side" interface is public, given by your ISP. The IPs you use in your home's WiFi side or Ethernet Lan connection those are private, so they are not unique but it's not a problem because those never leave your home before being NATed or translated by the NAT.
Now, as mentioned on the comments below, there is an exception to what I just said. There are some techniques that allow us to be more flexible about the one-to-one communication original internet protocol paradigm to allow one-to-nearest. These techniques are used for example when talking about services that need high availability, redundancy or low latency like DNS, or CDN services. Given a certain IP (IPv4 or IPv6),there might be more that one server in the world configured to answer to that IP, nevertheless only one will be answering.
Moreover, IPv6 introduced a new addressing system that copes with these "new needs", and it defined the "Anycast Address"
IP Version 6 (IPv6) defines a new type of address, known as an "anycast" address, that allows a packet to be routed to one of a number of different nodes all responding to the same address [2, 3]. The anycast address may be assigned to one or more network interfaces (typically on different nodes), with the network delivering each packet addressed to this address to the "nearest" interface based on the notion of "distance" determined by the routing protocols in use.
About IPv6 Anycast Address
An anycast address is an address that is assigned to a set of interfaces that typically belong to different nodes. A packet sent to an anycast address is delivered to the closest interface (as defined by the routing protocols in use) identified by the anycast address. Anycast addresses are syntactically indistinguishable from unicast addresses, because anycast addresses are allocated from the unicast address space. Assigning a unicast address to more than one interface makes a unicast address an anycast address. Nodes to which the anycast address is assigned must be explicitly configured to recognize that the address is an anycast address.
see cisco source
No, it’s not. This is in fact quite common. The technology behind this is called Anycast and used by many content-distribution networks, like CloudFlare.
Anycast is a network addressing and routing methodology in which datagrams from a single sender are routed to the topologically nearest node in a group of potential receivers, though it may be sent to several nodes, all identified by the same destination address.
Then, there’s also the possibility to (temporarily) steal others’ IP addresses. This is relatively easy if you’re an Autonomous System operator. You can simply announce that you’re hosting some IPs and traffic will magically be directed to you. Of course, the legitimate owner also broadcasts these announcements, so the effect is temporary and incomplete at best.
Only in unicast addressing is an IP address unique.
Public IP is the one you are visible with in the Internet.
Private IP is the one you are visible with in your private network, like behind router.
Everyone who connects to router has a single private IP, but in most common configuration they all share single public IP which, in common case, is assigned to the router, not computer.
It is possible to assign public IP for every single computer, but you have router which allows so and you must own enough of public addresses to assign. You have to buy them first.
Your public IP is unique by definition. It it was not unique, it could not be a public address, as it would be impossible to determine where to route your traffic.
In other words: your public IP address is the external (Internet-facing) address of the router closest to you which is still unique world-wide. That may or may not be your own router at home, although it usually is.
As pointed out though, some ISPs use NAT to conserve IPv4 addresses, in which case your home router's external address may not be a unique one and your public IP address belongs to a router further along, at your ISP (and you share it with other customers of the ISP).