Networks

INPUT · Slides

Counting IP addresses

01 / 11

There are two addresses

In the last lesson you met the IP address as the thing that points at a destination. In fact a machine carries a second address as well, called the MAC address.

The difference is whether it changes. A MAC address is burned into the hardware when it is made and stays the same wherever you take it. An IP address is decided by where you plug in, so it is a different value at home and at work.

Each gets used at a different moment. The IP address is for carrying something far, the MAC address is for handing it across the one hop in front of you. While something travels across routers the IP address stays put the whole way, but the MAC address is rewritten at every hop.

02 / 11

An address splits into a front and a back

An IP address is written as four numbers, like 192.168.0.10. Those 32 bits split so that the front is the address of the network and the back is the number of a machine inside it. Think of it as a street name and a house number.

What decides where to cut is the subnet mask. You write it like 255.255.255.0, and it means the network part runs as far as the ones do.

The same thing is also written /24. That declares the first 24 bits as the network part, and it is shorter. Both forms turn up in the exam, so get comfortable going between them.

255.255.255.0   = /24255.255.254.0   = /23255.255.255.240 = /28240 -> 11110000       four more ones

03 / 11

Apply the mask and out comes the network address

When you want to know which network an address belongs to, set the whole host part to 0. What you get is the network address.

All you do is fill everything past the cut with zeros. For /28, that is the bottom four bits.

Here it is worked through. Cut 10.170.70.19 with 255.255.255.240 (which is /28). The last number, 19, is 00010011 in binary. Zero the bottom four bits and you get 00010000 = 16. So the network address is 10.170.70.16.

  19 = 0001 0011 240 = 1111 0000  v  zero the low 4 bits       0001 0000 = 16-> 10.170.70.16

04 / 11

The two at either end cannot go to a machine

The one with a host part of all zeros and the one with all ones already mean something special, so no machine can have them.

  • Host part all 0 … the network address. The name for the network itself
  • Host part all 1 … the broadcast address. The destination for everyone on that network

In the /28 example just now, the range was the 16 addresses from .16 to .31. Both ends, .16 and .31, are reserved, so what you can give to a machine runs from .17 to .30.

10.170.70.16 - .31, 16 in all.16  <- network.17  + :   | 14 you can hand out.30  +.31  <- broadcast

05 / 11

How many addresses you get

With that much you can work the count out. Count the bits in the host part, raise 2 to that power, and take away 2. That is all there is to it.

For /28 the host part is 32 - 28 = 4 bits. 2 to the 4th is 16, minus 2 gives 14.

For /23 the host part is 9 bits. 2 to the 9th is 512, minus 2 gives 510.

Forget the subtraction and there will be a choice waiting for you with exactly that answer. That is the trap being set.

/28 -> 32-28 = 4 bits       2^4 = 16 -> 14/24 -> 32-24 = 8 bits       2^8 = 256 -> 254/23 -> 32-23 = 9 bits       2^9 = 512 -> 510

06 / 11

Telling whether two addresses share a network

To find out whether two addresses are on the same network, work out both network addresses and see if they match. That is the whole method.

Cutting with 255.255.255.240 (/28), you can just check whether the last number divided by 16 gives the same result. .17 and .29 both sit in 16 to 31, so they match. .29 and .33 fall into 16 to 31 and 32 to 47, so they do not.

Once you see that the cuts land every 16, drawing the lines in your head is enough to get the answer.

boundaries for /28  0-15 / 16-31 / 32-47 ....17 and .29 -> both in 16-31            -> same.29 and .33 -> 16-31 and 32-47            -> different

07 / 11

Addresses for outside, and addresses just for inside

There are only about 4.3 billion IPv4 addresses, nowhere near enough to hand one to every machine on earth. So they are split into global IP addresses for facing outward and private IP addresses for use inside an organisation only.

The ranges you are allowed to use privately are fixed, and there are three of them.

  • 10.0.0.0 to 10.255.255.255 (class A)
  • 172.16.0.0 to 172.31.255.255 (class B)
  • 192.168.0.0 to 192.168.255.255 (class C)

The reason the router at home mostly hands out addresses starting 192.168. is that it is drawing on the third of these.

08 / 11

NAT and NAPT - sharing one way out

A private address cannot reach the internet as it stands. The arrangement that rewrites it into a global address on the way out is NAT.

But NAT only swaps one address for another, so the number of machines that can be out there at once is capped at the number of global addresses you hold. A home is usually given a single global address, which by this method would let exactly one machine out.

So what actually gets used is NAPT (also called IP masquerade). It rewrites the port number along with the address, so any number of machines can share one global address. When traffic comes back, the port number is what says which machine it belongs to.

inside 192.168.0.10:50001inside 192.168.0.11:50002inside 192.168.0.12:50003  v NAPT folds them togetherdifferent ports on 203.0.113.5

09 / 11

Borrowing an address - DHCP

When you put a laptop on the Wi-Fi in a cafe, you will not remember typing in an IP address. That is because a free address is lent out automatically to whatever connects, and the arrangement for it is DHCP.

An address is not all it hands out. The subnet mask, the address of the router that serves as the way out, and the DNS server to ask questions of all come down together.

Learn it beside the names it gets muddled with. DHCP hands out, DNS looks up, NAT rewrites. Three separate jobs.

10 / 11

From IP to MAC - ARP

Actually handing data over inside a LAN needs a MAC address. But all you have is an IP address. ARP is what finds the MAC address that goes with an IP address.

What it does is simple: it calls out across the LAN, "whoever has this address, tell me your MAC", and the owner answers. Once asked, the pairing is kept to hand for a while, so it does not have to ask again every time.

There is also RARP, whose name is the other way round — and so is the job. It works out an IP address from a MAC address. It always turns up in the choices, so learn them as a pair with their directions.

ARP  ... IP -> MACRARP ... MAC -> IP

11 / 11

IPv6, for when you run out

IPv6 is the attempt to solve the shortage not by stretching what is there but by adding digits.

The biggest difference is length: 128 bits, against 32 for IPv4. There are more than could ever be used up, so private addresses and NAT stop being necessary.

The way you write one changes too. Instead of four numbers joined by ., you put down hexadecimal in groups of four, separated by :. It comes out looking like 2001:0db8:0000:0000:0000:0000:0000:0001.

Worth being careful about: IPv4 and IPv6 do not map one to one. The number of digits is wildly different, so there is no way to pair every one of them off.

IPv4   32 bits  192.168.0.10IPv6  128 bits  2001:0db8:85a3:0000:  0000:8a2e:0370:7334