69

Do two computers connected on the same Wi-Fi have the same IP address (for example, my dad's computer and my computer, at home)?

If so, how does the outside world distinguishes one computer with the other? (for example, when a server wants to send us back some data).

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Thomas
  • 815
  • 1
  • 7
  • 10
  • 7
    possible duplicate of [How does the router know which device to send packets to?](http://superuser.com/questions/524241/how-does-the-router-know-which-device-to-send-packets-to), [How does Network Address Translation (NAT) works on a home router?](http://superuser.com/questions/715939/how-does-network-address-translation-nat-works-on-a-home-router) – Ƭᴇcʜιᴇ007 Aug 21 '14 at 16:06
  • 1
    This kind of question reaffirms my belief that IPv6 is easier to learn than IPv4. – kasperd Aug 21 '14 at 18:15
  • 1
    @kasperd be that the case or not, the fact that there's 2, very different protocols, used for the same goal, makes it confusing for everyone! We really need IPv6 adoption fast. – Cruncher Aug 21 '14 at 19:53
  • 1
    Your two computers are on a LAN, they cannot have the same IP on that LAN. Your router is also part of the LAN with a LAN address. It is also part of the ISP network with the IP provided by the ISP (a single public IP that is different from the LAN ones). Your router knows how to relay packets in and out between LAN and ISP network, by translating LAN addresses into public ports and vice-versa. This conversion is known under [NAT acronym](http://en.wikipedia.org/wiki/Network_address_translation#Port_address_translation). NAT allows to use a single public address for multiple LAN computers. – mins Aug 21 '14 at 21:26
  • 4
    IP addressesing, ARP tables, NAT, DHCP, and routing fill entire books. This question is entirely too broad to be answerable in its current format. – CodeGnome Aug 22 '14 at 12:09
  • Yes, both computers will have the same external IP address. Your router will adjust the data you send to a webserver, adding a unique identifier, so that I can send incoming replies, to that unique ID, to your computer (see NAT). – BlueCacti Aug 23 '14 at 23:47
  • The computers have different IP addresses from each other, but whenever you access the outside Internet, the router changes the request so it looks like it came from the router itself. The router remembers which computer the request came from so it can send the response back to that computer. To any server on the Internet, it looks like the router is the only thing sending packets. This is NAT. – user253751 Aug 24 '14 at 06:00

8 Answers8

94

You're both seen as having the same IP address externally.

Your router will relay requests to the originating computer. The procedure used for this is network address translation (NAT).

One of the ways computers on the same network get distinguished in communication with the same public server is by assigning them by the router different port numbers in the communication. Their public IP address is the same, but the port number part is not. From the article:

To avoid ambiguity in how to translate returned packets, further modifications to the packets are required. The vast bulk of Internet traffic is TCP and UDP packets, and for these protocols the port numbers are changed so that the combination of IP and port information on the returned packet can be unambiguously mapped to the corresponding private address and port information.

However, if you were to try to communicate to your father's computer, you will be using your internal addresses.

These use a custom range intended only for internal use: private address range.

Computerphile has a YouTube video on this exact subject: Network Address Translation (video).

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Reaces
  • 1,095
  • 9
  • 13
  • 7
    it is possible that the wirless router doesn't do NAT, for example a internal accesspoint in a business office where the NAT box is elsewhere – ratchet freak Aug 21 '14 at 20:59
  • 8
    Which is true, however I honestly doubt it's the case for this guys home setup :) – Reaces Aug 22 '14 at 07:12
  • 1
    My home setup is that the router is access point, and all devices using wi-fi have different IP addresses (up to 5 at the same time according to the provider). So, -1. – Anixx Aug 22 '14 at 11:19
  • 5
    @Anixx From inside the network that's how it would appear. Go to http://whatismyip.com from each device and check your external address using that. – Daenyth Aug 22 '14 at 16:21
  • 1
    @Daenyth all of devises use different external address of course. This is ACCESS POINT mode, not NAT. – Anixx Aug 22 '14 at 17:43
  • 2
    @Anixx, access point mode is very rare for home users. The vast majority of ISPs only allow you to have one external IP, or charge you extra to get more than one. – Karl Bielefeldt Aug 22 '14 at 17:44
  • @Karl Bielefeldt I am not charged extra, by default each user here has up to 5 real external IPs. – Anixx Aug 22 '14 at 17:46
  • 3
    This answer could be improved by adding notes about AP vs NAT modes and how to check what state your local network is in. – Daenyth Aug 22 '14 at 17:49
  • I have the same setup as @Anixx at home. WiFi running in AP mode (actually, my AP doesn't have NAT) and each time a device connects to it, it gets a new external IP from the ISP. Kinda sucks when it comes to Firewalling the devices, but nice because I use P2P and I hate portforwarding. – Adi Aug 22 '14 at 18:09
  • 4
    @Anixx, that sounds like a fairly poor setup: you cannot use a 6th device on your wifi and, worse, every device you use is wide open on the internet. – Martin Argerami Aug 23 '14 at 13:27
26

Here's a VERY brief outline of how IP addressing works in this situation:

You have your home computer, it has a network interface (Ethernet port or Wi-Fi card), and each of these have unique MAC addresses which identify them globally.

Network interfaces are given IP addresses by your router/modem/switch/access point. Your access point (AP) is part of or connected to a modem/router/switch which gives the AP an IP address. This is how things look so far:

Your computer (IP)->Access Point(IP)->CableModem(IP)

Here is an example of what those IP addresses might be. In the example, the 4th octet (the last number of each set) determines your device's IP address, the 3 to the left of them determine the devices network.

192.168.1.50---------->192.168.1.25-------->192.168.1.1

Essentially, in this example, the modem creates a network called 192.168.1 All devices on the network are given a different x value (1-255), the last digit.

Here's an important distinction. There are two types of IPv4 IP addresses, Public and Private. Public IP addresses are the ones you see on the Internet (if you ping google.com you'll get a public IP address). Inside of a network you typically have a Private IP setup (192.168.x.x and 172.x.x.x and 10.x.x.x - they are all IP addresses that do not exist on web servers in the internet; they are reserved for local networks).

Typically, your home network has a gateway which is something like x.x.x.1 (192.168.1.1, 10.1.1.1, for instance). This means that they are not accessible from the outside world, they are meant to be INSIDE your network.

How do internal network devices get on the Internet then?

If you go to http://www.whatismyip.com/ you'll see an IP address listed which is not your computer, your AP, or your modem/router. This is your Public IP address.

Typically, your modem/router has two functions. 1) Receive an IP address from the outside world and talk to your ISP's network with that address 2) Create an internal network and let them talk through its external interface.

So here's, effectively what your modem does:

Public IP (cable jack) <----> [Modem|Ext IP address/Int LAN] ---> Ethernet ports <---> [computers]

The modem bridges the public Internet to your network. Requests from your internal network get sent to your modem which forwards them to the Internet. This way only one public IP address is needed for ALL of your devices to talk to the Internet.

On the Internet side of the modem you have an IP address assigned by your ISP which is the one www.whatismyip.com shows you. This is put on the interface of your modem which is attached to your cable/DSL/T-1 line. The other side of the modem/router (where you plug in your access point, switch, or computers) is given an IP address you can configure. The way people are able to have servers visible to the public is that they can tell the modem things like this: "When a request comes to our PUBLIC IP address asking for a resource, connect that traffic to an INTERNAL IP ADDRESS OR RESOURCE"

When you send a message, your computer's IP address basically becomes 'encapsulated' within various 'headers' on your data. Ultimately, the computers seeing your traffic see your external IP address from your modem and not your physical computers internal IP address. More data is sent containing MAC addresses and things like that but, essentially one public IP address can represent an entire network of devices behind it.

More information can be found in What is an IP address? (or all over the Internet :)

NAT is the process by which your router translates the internal addresses to your public address and your public incoming traffic to the correct internal IP address.

There's a lot more to it, but that should be the general idea. For more, look in to the OSI Model, IP "Sockets", and another good article is How Does the Internet Work?.

Abraxas
  • 4,306
  • 6
  • 30
  • 47
  • 2
    so is it the MAC address encapsulated in incoming packets that tell the NAT to redirect to my computer / my dad's ? – Thomas Aug 22 '14 at 07:20
  • 4
    no MAC is lower level than IP, and it doesn't leave the network (messages from outside use your router's MAC), a NAT box essentially is a [MitM](http://en.wikipedia.org/wiki/Man-in-the-middle_attack) that looks at each TCP connection that an internal pc wants to make and makes its own connection and forwards its incoming messages. – ratchet freak Aug 22 '14 at 07:35
  • 1
    so in the packets from the outside server to me, there is something that helped the modem know that it had to be addressed to me and not to my dad. what is it ? – Thomas Aug 22 '14 at 15:03
  • http://www.theshulers.com/whitepapers/internet_whitepaper/index.html#http and http://www.tcpipguide.com/free/t_IPDatagramEncapsulation.htm will explain better than I can :) – Abraxas Aug 22 '14 at 15:16
15

Any of these topics could be examined in far greater detail.

You and your dad have the same external address, but different internal addresses.

External IP addresses are like a street address. The whole world can find you using that address.

Internal IP addresses are like rooms in a house. Only someone in a house can use directions to find the specified room. In your case, only someone connected to the same wifi can see your internal IP address.

Using default settings, a wifi network will have a single external IP address. When the mailman brings mail to your house, someone has to get it from the mailbox and distribute it to who it belongs to. Each wifi network has a router, which acts like your personal doorman. The router "collects the mail" and gives it to you only if it is addressed to you. Mail addressed to your dad goes to him.

The outside world only sees one address, your external address. Computers and other devices inside the network only see the inside. The router is the only thing that sees both sides.

To see this in action, go to Google and type "what is my ip?". This will be your external (or public) address. Next, find your internal address. In Windows, open a command prompt. Then type: ipconfig and hit enter. You will see a whole bunch of stuff similar to this. The picture highlights your internal IP address. Running this command on your dad's computer would get a different number, but googling your IP address from his computer would get the same number.

For your curiosity, the default gateway listed is the internal IP address of your router. If you are using a Mac, google "find your IP on mac" for directions to find your internal IP.

Taejang
  • 251
  • 1
  • 5
  • We use almost this same house analogy where I work to teach networking basics to some of our students that don't quite get how routing works. Works every time. – Sarge Aug 21 '14 at 22:32
  • so in a packet sent on the internet, does the router encapsulate the internal ip address (or another internal id) ? – Thomas Aug 22 '14 at 07:30
  • @Sarge I've never heard the analogy before. What differences are there between my version and what you use for students? I might nab better parts from your version for future use. – Taejang Aug 22 '14 at 14:15
  • @Thomas Routers almost always use the internal IP address inside a network. That said, routers can be configured to use MAC addresses, names that correspond to a DNS list stored on a server, or even other ids manually stored in the router's config. Such methods are just about exclusive to businesses, universities, and other large networks. Routers can also be configured to route things to other routers to divide the work in large networks; this is usually done with router IP addresses (which are internal). – Taejang Aug 22 '14 at 14:24
  • 1
    @Dan, where you use house, we sometimes use apartment building, office building or even show the progression of mailing a letter from one state to another and how it moves through the US Postal System. – Sarge Aug 22 '14 at 23:40
  • Complete except you stop at "only if it is addressed to you" and don't describe what form this takes (i.e. port forwarding), which is bad because your answer quite correctly begins by enforcing the point that, to the outside, the mail is _never_ directly addressed to you. – Lightness Races in Orbit Aug 23 '14 at 14:39
6

Do two computers connected on the same Wi-Fi have the same IP address (for example, my dad's computer and my computer, at home)?

Answer: externally yes, within your network no

If so, how does the outside world distinguishes one computer with the other? (for example, when a server wants to send us back some data)

Answer: The outside world does not distinguish, it will communicate to/from your external IP address. The router's job is to distinguish. Each device on your Wi-Fi will have a unique local IP address.

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
pyker
  • 194
  • 4
2

No. Two computers with the same IP address will cause issues. They will have similar addresses, but not the same. You will have the same "external" address, however, and you can find this by typing in "What is my IP" into Google. All the traffic on your network will appear to come from this IP address, regardless if you have one machine on your home network, or your computer, your dad's computer, your phone, tablet, smart TV, smart fridge, smart dishwasher, etc.

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
tombull89
  • 6,706
  • 11
  • 45
  • 65
2

This depends on whether the router in in the access point mode. If so the computers will have different addresses, otherwise there would be NAT and only one IP address.

Anixx
  • 628
  • 1
  • 12
  • 20
1

The external IP address is assigned by your ISP to your router which in turn assigns different internal IP addresses to all devices in the network. The outside world can only see your external IP address. In short, it cannot distinguish between your dad's computer and yours.

When a server sends you some data, it will be transmitted only to your device by your router (because you requested it) and not your dad's. (Please correct me if I'm wrong.)

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
neo321
  • 21
  • 3
  • 2
    Can you expand? This answer is quite low in quality, especially given the other answers here. Feel free to [edit] to give more information, but make sure you don't duplicate information. – Canadian Luke Aug 21 '14 at 16:32
0

It was curious how nobody thought about same (internal/local) ip address for both computers connected to the same AP. I found this when looking on why all the devices at home connected to one XFINITY AP have the same IP. some answers I have found talk about VLANs [A combination of vlans, tagging and mac/ip ]

Mario
  • 19
  • 1
  • 2