Page 1 of 4
Every programmer should understand how the Internet works and this means understanding IP addressing and routing. It's a good time to find out about such things with DOS attacks on the rise and IPv6 about to take over from IPv4.
To connect a network to the Internet you need a router. In a wider context routers make the Internet work.
They vary in size from super computers that handle huge quantities of data to the small, low cost, boxes we all know and . No matter how big or how expensive routers do the same job and work in the more or less the same way. Understanding how they work is essential if you want to know how IP addressing works in practice.
Routing and non-routing
Most networks carry data from one machine to another using packet switching.
Put simply all this means is that the data to be transmitted from one machine to another is broken up into small chunks and put into an data envelope complete with the address of the destination and the return address. The packet is then placed on the network and it makes the trip from the source machine to the destination machine as determined by the packet’s address.
If you have a small network then the problem of determining where the packet should go is fairly easy to solve because all of the computers connected to the network identify themselves by an address when they connect. Usually the device the delivers the packets is called a switch because it just maintains a table mapping addresses to machines that are directly connected to it.
In this case you don't need any complicated form of addressing and a non-routable protocol will do. Essentially a non-routable protocol just uses addresses that identify the destination without implying anything about how to find the destination. You could assign each machine an address that is a random number and use a lookup table to deliver the packets because all of the machines are connected to the same physical network. This is indeed how the basic ethernet connection works. Ethernet addresses are assigned to the network adaptor cards (the so called MAC address) when they are made and they have no real structure i.e. they might as well be random numbers.
Things start to a little more difficult when one of the machines wants to send a packet to a machine not directly connected to the local network. The Internet is a network of networks and to get a data packet from my local network to a machine connected to another local network, perhaps on the other side of the world, is what routing is all about.
A router is a piece of hardware, or software that forwards data packets to other networks. Each network "knows" about the machines that are connected to it but the router "knows" how to get packets from one network to another so as to find the machine that is the destination. To do this the addressing system has to be routable - it has to have a structure that lets you work out which network the machine is connected to.
So how does the router know which addresses are local and which need routing?
If you like what is it about the address that identifies a local or remote destination?
The answer is all about the way that Internet or IP addresses are constructed.
An IP (IPv4) address is composed of numbers separated by dots, for example, 22.214.171.124. Each of the numbers can be between 0 and 255 and they aren’t arbitrary. In fact, there is a structure built into IP addresses that allow data packets to be routed efficiently.
Each local network is assigned a block of IP addresses sufficient for one per machine connected to it. The way that this works is that the IP address is split onto a network ID and a host ID part.
The network ID identifies the network, for example, an IP address of 200.21.84.XXX, where XXX is any value, signifies that that 200.21.84 is the network ID and the XXX specifies the particular host connected to the network.
When a network is set up the network administrator has to apply for a block of IP addresses that identifies the network and then allocates each machine connected to the network a unique complete IP address – for example, 126.96.36.199, 188.8.131.52 and so on.
An IP address can be split in different ways to give a network ID and a host ID and this is usually indicated by a subnet mask. This is a pattern of ones and zeros that indicates which bit in the IP address is to be regarded as part of the network ID.
For example a subnet mask of 11111184.108.40.206 or 255.0.0.0 in decimal means that the first eight bits of the IP address are the network ID and the rest identify particular machines on that network.
So now we know how the router can decide if the data packet is destined for a local machine or needs to be routed to some other network. When the router is set up it is told its IP address and a subnet mask. Using the subnet mask it can look to see if any data packet has an address that belongs on the same local network or to some other network and hence needs to be routed into the wider world.
For example, if the router is told that its IP address is 192.168.253.1 and the subnet mask is 255.255.255.0 then it can ignore any packet with an address 192.168.253.x where x is any value but all other packets are to be routed to external networks.