What is a network
A collection of computing devices connected to each other. It allows computers to communicate with each other and transfer information in the form of data among each other.
Types of Networks:
Networks are mainly divided into three types.
Local Area Network: A computer network that spans over a small area. It connects computers, workstations to share data and resources such as printers, file-share etc.
Metropolitan Area Network: Interconnection of networks in a city, optimized for a larger geographical area than a LAN, ranging from several blocks of buildings to entire cities. Its geographic scope falls between a WAN and LAN. For example connection between an Organisation and its Local Datacenter.
Wide Area Network: It covers a wide geographical area which includes multiple MANs or LANs. It connects computers through public networks.
Here is a comparison between the three types of Networks:
|Connects computers and workstations in a home or office .||Connects multiple LANs in a town or city.ex: Cable TV||Connects geographically separated LANs or MANs|
|Covers a local area of 1 km||Covers larger area than LAN but smaller than WAN, 2 - 100 km||Spans larger geographical area more than 100 km|
|High Speed, Data Transmission Rate (10/1000 Mbps)||Lower speed compared to LAN (10Mbps or 100Mbps)||Less speed and bandwidth than LANs (150 Mbps)|
|Layer 2 devices like switches ,hubs etc||Users both layer 2 and layer 3 devices||Layer 3 devices like routers , L3 switches.|
|Low Cost||Costlier than LAN less costly than WAN||High Cost|
Now that we have known about various types of networks and their characteristics, let us see how traffic or information flows in networks.What happens when we try to send information from one computer to another computer in a network.This brings us to next topic in this chapter called the Open System Interconnection model.
Flow of data in network has been described conceptually by International Standards Organization(ISO) in the form of a model called OSI or Open System Interconnection model.The OSI model explains flow of information in any network through 7 layers as below.
In Theory here is what the 7 layers do.
This flow happens both upwards and downwards. This is how the data flow from sender to receiver looks like through the OSI model:
An IP address is a unique number assigned to a any device in a network to communicate with other devices on the network. Ip addresses can be of two types based on how they are assigned:
Dynamic: When ip addresses are assigned for temporary connectivity to devices like laptops, tablets and mobile phones using WiFi, they are called dynamic ip addresses. The most common protocol used for dynamic ip address assignment is DHCP(Dynamic Host control Protocol), we will learn more about this in later chapters.These ip addresses might change after sometime.
Static: Ip addresses assigned for more permanent devices such as to servers or hosts for longer duration and which are persistent. Once assigned to a device, a static ip address does not change by itself.
IP addresses can be classified into two categories: Classful and Classless
Classful Ip Addresses:There are 5 classes of ip addresses. All these are 32 bit addresses.
|Address Class||Network Address||Usage|
|Class A||0.0.0.0 - 126.96.36.199||Designed to serve ip addresses for bigger organizations|
|Class B||188.8.131.52 - 184.108.40.206||Designed to serve mid level organizations|
|Class C||192.0.0.0 - 220.127.116.11||For smaller organizations|
|Class D||18.104.22.168 - 22.214.171.124||Multi cast reserved|
|Class E||240.0.0.0 - 255.255.255.255||Reserved for experimental usage|
Classless IP Addresses: Classless ip address are designed to overcome the shortcomings of classful ip addresses. Classful ip addresses led to waste on many addresses.e.g: Though Class A address ranges from 0-127 0th and 127th addresses are reserved for special use. Each of network blocks in class A contains 16,777,214 hosts which is difficult to have in the same network , thus many class A ip addresses are wasted. To overcome these drawbacks classless ip addresses were designed. Unlike classful where the host address portion is fixed , classless addressing can borrow from host address to extend the network blocks.
Subnet Mask & CIDR Notation:
Ip Subnet: Dividing a network into several sub networks where each sub-network has its own address.Subnet Mask specifies the part of ip address that is to be used for identifying a subnetwork.
Classless Inter-Domain Routing(CIDR): Classless addressing scheme of IP addresses and efficient usage of ip addresses compared to Classful addressing.e.g: /x indicates the first 21 bits are used for network and remaining 11 are used for host id./x indicates the subnet mask./8 , /16, /24 represents the default for class A , class B , Class C.
|Address Class||Subnet Mask||CIDR notation||Examples|
|Class A||255.0.0.0||/8||10.0.0.0/8; (10.0.0.1 - 10.255.255.255); 10.0.0.1/255.0.0.0|
|Class B||255.255.0.0||/16||10.10.0.0/16; (10.10.0.1 - 10.10.255.255); 10.10.0.10/255.255.0.0|
|Class C||255.255.255.0||/24||10.10.10.0/24;(10.10.10.1 - 10.10.10.255); 10.10.10.20/255.255.255.0|
The last two octets in the subnet mask identify the network address and decides how many host ips can be assigned. Each octet ranges from 0-255 , in short each octet can have 256 hosts. Its very important to assign correct subnet mask to your ip address because that will decide whether you can connect to hosts on the same network.Any host on the same network has to have the same subnet mask in order to communicate with each other.
Internet consists of many computers. Communication among these devices can be achieved by using unicast, broadcast or multi-cast addresses.
Unicast Address: One to one communication.These addresses belong to Class A, Class B, Class - C.
Multicast Address: One to many communication. These belong to Class D. e.g ISP wan ips
Broadcast Address: One to many communication. The last address of any network is used as the broadcast address. e.g: DHCP broadcast in a network
Exercises: Setup A Local Area Network
Hardware: At least 1 or 2 laptops, Network cables(optional), Switch/Hub(optional)
Software: Virtual Box(for virtual machines) Download a Linux ISO.In this exercise we will use centOS-6.6-minimal.iso
Today we are going to setup a LAN with class B network range 192.168.10.0/24(you can choose your own network)
1. How to connect machines a Local Area Network(LAN):
Option 1: If you have two laptops/ machines then connect both the machines with a network cable to a switch. In case you don’t have a switch connect each other with a network cable. In this case the two laptops are the hosts on your LAN
Option 2: In case you have only one laptop, install virtual box and create two virtual machines in it. Install centos downloaded above.
Assign both the vms to host-only network.
Enable the network interfaces in both the vms.
In this case the two virtual machines are your host on your LAN.
2. How to find out LAN ip of a computer: Run below commands from command line interface of your respective system.It will show the lan ip assigned. In most cases this ip is dynamic.
$ ifconfig -a eth0 Link encap:Ethernet HWaddr 08:00:27:61:20:86 BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:5 errors:0 dropped:0 overruns:0 frame:0 TX packets:13 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1540 (1.5 KiB) TX bytes:1426 (1.3 KiB) eth1 Link encap:Ethernet HWaddr 08:00:27:EF:01:D8 inet addr:192.168.56.103 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:feef:1d8/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:180 errors:0 dropped:0 overruns:0 frame:0 TX packets:107 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:19479 (19.0 KiB) TX bytes:16859 (16.4 KiB)
As you can see above eth1 is up and has an ipaddress but eth0 is not yet up.You can bring up an interface with the command below:
$ ifup eth0 Determining IP information for eth0... done.
and ifconfig show both eth0 and eth1 are up:
$ ifconfig eth0 Link encap:Ethernet HWaddr 08:00:27:61:20:86 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe61:2086/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:6 errors:0 dropped:0 overruns:0 frame:0 TX packets:19 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2130 (2.0 KiB) TX bytes:2110 (2.0 KiB) eth1 Link encap:Ethernet HWaddr 08:00:27:EF:01:D8 inet addr:192.168.56.103 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:feef:1d8/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:250 errors:0 dropped:0 overruns:0 frame:0 TX packets:146 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:25623 (25.0 KiB) TX bytes:23065 (22.5 KiB) Incase ifup fails then you will have to enable it.In centos or any other linux distros here is how you do it. $vi /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=dhcp Enable ONBOOT=yes to enable the eth in centos.
3. How to assign static ip addresses to hosts in the LAN
4. How to connect to hosts in the LAN
Once you find out the ip addresses of both the hosts, use ping to test the connectivity between both the hosts.
e.g: Host1 ip => 192.168.10.1
Host2 ip => 192.168.10.2
from host1 ping host 2 ; if both hosts are configured correctly, you should see the below output.
> ping 192.168.10.2 > PING 192.168.10.2 (126.96.36.199): 56 data bytes > 64 bytes from 192.168.10.2: icmp_seq=0 ttl=56 time=0.021 ms > 64 bytes from 192.168.10.2: icmp_seq=1 ttl=56 time=0.645 ms
Once you can see both hosts ping each other, your LAN is up and running.
5. How to find out wan ip of a computer: visit http://whatismyip.com from browser, it will show you the wan ip of that computer.Depending upon your setup, others may or may not be able to reach you on this IP, as we’ll learn in the NAT section later