- 1 Introduction
- 2 Video
- 3 IP to connect them all
- 4 Protocols using IP
- 5 Client / Server
- 6 BELOW ARE DRAFT MATERIAL
- 7 Network tools
- 8 Links
In this chapter we will only deal with computer networks. The title Network:Introduction may be misleading but we figured it was ok since our books are all about programming and IT. Anyhow, what is a network, or rather what is a computer network. As the name suggests it's a network of computers. This means that we have a bunch of compter connected to each other. Today we take this connectivity for granted. So much that some even get angry when not being connected to the internet. What is internet byt the way? And how does it work? In this chapter we will only focus on IP networks, which mean that we will not talk about bus network, star networks and ring networks. We will also not deal with how the internet is governed. This is indeeed an interesting topic, but our focus is on getting things done practically. We will focus entirely on IP networks, where the internet is the biggest one.
We have tried to simplify things as much as we can. If you're a network wizard you may dislike our simplifications, but as an introduction we believe they will do fine. If you want to dive deeper into computer networks we provide a couple of links at the end of this page.
- Network Introduction - 1 (pdf)
- Network Introduction - 2
- Network Introduction - 3
- Network Introduction - 4
IP to connect them all
The computers on the internet are connected using something called IP (internet protocol). IP is a protocol send/receiving packages over a computer network. A protocol, when it comes to computer networks, is basically a set of rules and syntax for how communication should be performed. Each computer on a specific computer network has its own IP address, a so called IP address. Two computers, each with an IP address, can communicate (send messages to each other) if they are physically connected, most often using other equipments, for example routers. Think of IP addresses a bit like a telephone numbers. You can communicate with a person using telephones if you have the telephone number.
In order to get an IP address you need to have a network card. Each network card can have an IP address and a computer can have many network cards but usualy they have two (one ehternet and one wireless).
Assigning an IP address
You can either specify your IP address on your computer directly, either using a graphical tool or a command line tool, such as
ifconfig</cond> (Linux, Mac, BSD) or <code>ipconfig (Windows). You can use the tools above to see the IP address:
$ ifconfig wlp58s0 wlp58s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.166 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a973:76b5:22a6:7cf8 prefixlen 64 scopeid 0x20<link> ether 44:85:00:1d:90:16 txqueuelen 1000 (Ethernet) RX packets 570993 bytes 574915140 (548.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 298978 bytes 112290806 (107.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Note: in the above command the word
wlp58s0 is the name of a network card. You can list information about each network card (including the so called
lo device) using
If we want to change the IP address of a network card we can use
ifconfig. But we will skip this in this chapter. Most common is to get an IP address automatically once we connect to a network. This is done using something called dhcp, a protocol to dynamically provide an IP address.
DHCP is used to automatically give computers, phones, routers, printers etc a IP. DHCP can give a device:
- IP address
- gateway (including netmask)
- name server
Note: it is possible to specify what MAC addresses can not get an address and to give special addresses to some other MAC addresses. This and more can be done with DHCP.
In order to get an IP address you need yo have a network card. You most likely have on eor two network cards on your computer, one wireless and one ethernet. In short, without going into details, the first is used with wired networks and the latter for wireless networks. If the network you're connected is connected to the internet you almost certainly also can connect to the internet so your data is routed via something called a router (see below). Each network card has a MAC address which is used by protocols "below" IP to send IP packages between IP addresses. We will go below IP addresses but bring up MAC addresses since we believe it explains some of the information we get from the command ifconfig. It also explains how one networkd card can get one IP.
$ ifconfig wlp58s0 wlp58s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.166 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a973:76b5:22a6:7cf8 prefixlen 64 scopeid 0x20<link> ether 44:85:00:1d:90:16 txqueuelen 1000 (Ethernet) RX packets 755184 bytes 770976668 (735.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 361174 bytes 128037814 (122.1 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
The highlighted lines show the MAC address
For the fun of it: you can connect to two different network if you have two network cards. It is then possible to route data between the networks.
Router and gateway
Imagine having to hook up your computer with a long cable (we mean long, as in really long) to some kind of central computer with severanl millions connectors. Seems silly. Instead we divide internet in to smaller networks. It is such networks your computer can, and most likely do, connect to. This means your computer communicates from the smaller network with the bigger network. The piece of hardware routing the traffic between the network is called a router. There are wireless routers, wired routers and a mix of them.
Often your router at home has an internal network set up. This means, or rather the implications for you, are that the computers on the network can reach the internet via the router only. So even if you have several computers at home connected to the router - only one IP address is seen by the outside network. This IP address is shared by your computers on the "inside". This is then called a LAN (Local Area network). To get from one network to another you specify a gateway typically your router.
On Unix system (Linux, Mac, BSD etc) you can use the command
route to get information about the routing tables for your system.
$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.1 0.0.0.0 UG 600 0 0 wlp58s0 192.168.1.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp58s0
The table says that all traffic NOT on the internal network (192.168.1.xxx) uses the gateway
192.168.1.1, which is a router. The router send the data from your computer further and when it gets response it sends the response back to your computer.
If your router allow computers to connecto to it via wlan and ethernet it is called a wireless router.
Your mobile phone is not using wired networks. Instead you use wireless network, in case you're near a network you can connect to. What if you don't have access to any wireless networks? Good thing is that mobile phone come with a modem. A modem is another way to connect to a network. With the modem you can also get hold of an IP address and can get access to the internet.
How many computers can connect to your router via ethernet at home? Just count the number of ethernet connectors. Let's say you have 8 ethernet connectors. Is this the maximum number of computers? You can connect so called switch with say 24 connectors wicth which you get 24 additional connectors (minus the one you use to connect the switch to the router, so in practice you get 23 additional connectors).
Sending data between IP addresses
Since modems, wireless and ethernet cards use different hardware that transfer packages differently between them. We can skip this part and focus on what we can do with IP. Just trust us that it is possible to send a package from IP
192.168.1.15 (both being IP addresses on a local network). How can we use this? We have a couple of standards that we use to make it easier to send IP packages. Using standards make things a whole lot easier. If you send a package in a special way the receiver knows what to expect. The standardised way to send data is called protocls. We have three important protocols which we're going to look at:
- TCP - Transmission Control Protocol
- UDP - User Datagram Protocol
- ICMP - Internet Control Message Protocol
When sending a TCP package (UPD or ICMP) you put the data you want to send in one (or many) IP package. This means that your IP package contain information needed to reach the recepient and the data for the recipient.
+-------------------------------------------+ | | +----------------------+ | | IP package | | TCP data | | | | +----------------------+ | +-------------------------------------------+
Each IP have a couple of so called ports associated. Think of this as something like that there are several apartments on one address in an aprtment house. You can address severl different people on the same address. Same thing with IP. You can address web traffic (usually on port 80), email (usually on port 25) and several others on the same IP address.
Port numbers associated with services you likely have used:
- 21: File Transfer Protocol (FTP)
- 22: Secure Shell (SSH)
- 25: Simple Mail Transfer Protocol (SMTP)
- 53: Domain Name System (DNS) service
- 80: Hypertext Transfer Protocol (HTTP) used in the World Wide Web
- 110: Post Office Protocol (POP3)
- 143: Internet Message Access Protocol (IMAP)
- 443: HTTP Secure (HTTPS)
- 8080: Not a standard, but often used for running a web server in user space - ports above 1024 can be used for servers started without administrator/super user priviledges!
DNS - Using named hosts instead of IPs
It's a bit(!!) cumbersome to learn all the IP addresses of the servers you want to use. Not only that they are many, they are also subject for change. That's two of the reasons not to learn them. You can use the name of computers instead. These names are translated to IP addresses. So you can type in
www.sunet.se instead of
126.96.36.199 which is the real IP (at nov 19 2017) in your browser. The translation is done automatically by your browser. The translation is done using DNS (Domain Name System). You can look up ip addresses yourself with different tools (nslookup, dig and host).
Here's an example using
nslookup to find the IP for
$ nslookup www.gnu.org Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: www.gnu.org canonical name = wildebeest.gnu.org. Name: wildebeest.gnu.org Address: 188.8.131.52 Name: wildebeest.gnu.org Address: 2001:4830:134:3::a
The important line is highlighted. It says that the IP of
Protocols using IP
As we mentioned there a three protocols with we can send data over an IP network. One of them is TCP. The data you send using TCP can be assumed to arrive on the correct order with correct content. So if an IP package is lost or late the TCP software stack takes care of this and you can trust the content, unless you receive an error which may happen if your ethernet cable is unplugged or similar things. The applications we assume your most familiar that use TCP are browers (www/world wide web) and email. Sometimes TCP is used for streaming.
Sending emails, using SMTP, or streaming data is not covered in this chapter, but if you're interested in how emails are sent you can get a short introduction here. We have an entire page covering how to use HTTP to send data over TCP.
THe last thing we're going to look at is how what it looks loke when sending a HTTP package over TCP. You put the data you want to send in one (or many) TCP package(s). This means that your TCP package contain information needed to reach the recepient and the data for the recipient.
+-------------------------------------------+ | | +----------------------+ | | TCP package | | HTTP data | | | | +----------------------+ | +-------------------------------------------+
Note: the TCP package is located in an IP package so a more correct picture would be:
+-------------------------------------------------------------+ | | +----------------------------------------+ | | | | | +----------------------+ | | | IP package | | TCP package | | HTTP data | | | | | | | +----------------------+ | | | | +----------------------------------------+ | +-------------------------------------------------------------+
The recipient who get the IP package, extracts the TCP package and from that extracts the HTTP data. This is a simplified version of what happens but it will suffice for this chapter.
Client / Server
When you browse the internet and click on a link, you're sending a request to see a new page. Your browser is then a so called client and the computer you're requesting to get data from is a server - serving you with data. When requesting a printer to print a page for you, your program is a client sending a request to the printer which is the server. This client/server relation is very common in computers and computer networks.. We can discuss how to define client/server for hours, but will settle for the following. A server is someone providing a resource or service and clients are the ones requesting the resource or service. A common example is, again, a web server (server) and a browser (client). The web server runs on a separate machine responding to requests from clients.
A program creating a String object is not a client/server communication. A program requesting JSON data from a web server is in client/server relation with the web server.
Note: There seems to be a bit of confusion about what client/server is. We have our own example of this confusion.
BELOW ARE DRAFT MATERIAL
- lo device
- IP range
- Wireless network
- Wireless LAN
- Datorkommunikation (pdf) (Swedish) by Marcus Rejås. For Henrik (one of the authors on this site), Marcus has been a motivation factor for many years. Thank you Marcus for all your work and kind support. You rock!