Next Previous Contents

4. This IP Thing

So the role of the IP layer is to figure out how to `route' packets to their final destination. To make this possible, every interface on the network needs an `IP address'. An IP address consists of four numbers separated by periods, like `'. Each number is between zero and 255.

Interfaces in the same network tend to have neighboring IP addresses. For example, `' sits right next to the machine with the IP address `'. Remember also that a router is a node with interfaces on more than one network, so the router will have one IP address for each interface.

So the Linux Kernel's IP layer keeps a table of different `routes', describing how to get to various groups of IP addresses. The simplest of these is called a `default route': if the IP layer doesn't know better, this is where it will send a packet onwards to. You can see a list of routes using `/sbin/route'.

Routes can either point to a link, or a particular node which is connected to another network. For example, when you dial up to the ISP, your default route will point to the modem link, because that's where the entire world is.

  Rusty's              ISP's  ~~~~~~~~~~~~ 
   Modem               Modem {            }
       o------------------o { The Internet }
                             {            }

But if you have a permanent machine on your network which connects to the outside world, it's a bit more complicated. In the diagram below, my machine can talk directly to Tridge and Paul's machines, and to the firewall, but it needs to know that packets heading the rest of the world need to go to the firewall, which will pass them on. This means that you have two routes: one which says `if it's on my network, just send it straight there' and then a default route which says `otherwise, send it to the firewall'.

                         o  Tridge's
                         |    Work Machine      ~~~~~~~~~~~~
  Rusty's                |                     {            } 
   Work Machine o--------+-----------------o--{ The Internet }
                         |            Firewall {            } 
                         |                      ~~~~~~~~~~~~
                         o  Paul's
                              Work Machine

4.1 Groups of IP Addresses: Network Masks

There is one last detail: there is a standard notation for groups of IP addresses, sometimes called a `network address'. Just like a phone number can be broken up into an area prefix and the rest, we can divide an IP address into a network prefix and the rest.

It used to be that people would talk about `the 1.2.3 network', meaning all 256 addresses from to Or if that wasn't a big enough network, they might talk about the `1.2 network' which meant all addresses from to

We usually don't write ` -'. Instead, we shorten it to `'. This weird `/16' notation (it's called a `netmask') requires a little explanation.

Each number between the dots in an IP address is actually 8 binary digits (00000000 to 11111111): we write them in decimal form to make it more readable for humans. The `/16' means that the first 16 binary digits is the network address, in other words, the `1.2.' part is the the network (remember: each digit represents 8 binary digits). This means any IP address beginning with `1.2.' is part of the network: `' and `' are, and `' is not.

To make life easier, we usually use networks ending in `/8', `/16' and `/24'. For example, `' is a big network containing any address from to (over 16 million addresses!). is smaller, containing only IP addresses from to is smaller still, containing addresses to

To make things confusing, there is another way of writing netmasks. We can write them like IP addresses:

Finally, it's worth noting that the very highest IP address in any network is reserved as the `broadcast address', which can be used to send a message to everyone on the network at once.

Here is a table of network masks:

Short   Full                    Maximum         Comment
  Form    Form                    #Machines

/8      /              16,777,215      Used to be called an `A-class'
/16     /            65,535          Used to be called an `B-class'
/17     /          32,767
/18     /          16,383
/19     /          8,191
/20     /          4,095
/21     /          2,047
/22     /          1,023
/23     /          511
/24     /          255             Used to be called a `C-class'
/25     /        127
/26     /        63
/27     /        31
/28     /        15
/29     /        7
/30     /        3

Next Previous Contents