# Data Networking/Fall 2016/SARA
## Motivation

This project builds a deeper understanding of basic Networking fundamentals through practical implementation of a Domain Name System Server (DNS), Dynamic Host configuration Protocol Server (DHCP), Web Server, Firewall, Backup Server. The concepts that are part of the Data Networking class (TELE5330) became clearer through the implementation of this project.
The aim of this project is to deliver a complete network solution in which the servers and clients will be able to obtain an IP address from the DHCP server, and then with the help of our DNS Server, the users within our network should be able to successfully fetch the web page that is being host in our own web server... Moreover, we will implement and configure extra networking tools like firewall, backup server etc. to provide a robust, secure, intelligent inter-networking scheme that could be used at any company or organization.

### Team Members

1. Shriya Kane
2. Aditya Kulkarni
3. Rohit Dongare
4. Amruta Kondra

## Behaviour of Protocols
### Domain Name System

DNS resolves domain names into corresponding IP addresses also vice versa. It runs over primarily on UDP and on TCP on port number 53. Reverse look up is facilitated by in-addr.arpa. It follows hierarchical system of Local name servers, Root name servers, Top level domain (TLD) servers and Authoritative name servers. Generally, queries from host to local name server are recursive and rest all are iterative. Resource record is a four-tuple: {Name, Value, Type, TTL}
1. A: Name is hostname and Value is IP address.
2. AAAA: Name is hostname and Value is IPv6 address.
3. NS: Name is hostname and Value is the hostname of the authoritative server.
4. CNAME: Value is the canonical name for a Name hostname.
5. MX: Translation of an alias mail server to its canonical name.
6. PTR: Gives IP address to hostname translation.

### Dynamic Host Configuration Protocol

Dynamic Host Configuration Protocol is a client/server protocol that automatically assigns IP-addresses to client machines. It also provides related configuration information like the subnet mask, DNS server, default gateway etc. DHCP is controlled by a DHCP server which helps in automatic allocation of the IP addresses to the machines from a defined range of IP's for a given network .
There are 3 ways of IP address allocation:
* Static Allocation:-IP addresses are assigned statically and remain fix until changes are made by the network administrator.
* Dynamic Allocation:-IP addresses are assigned to the machines from a specified IP address range in the DHCP server.We can assign both IPv4 and IPv6 addresses.In dynamic allocation to avoid wastage of IP addresses , we need to provide a suitable subnet mask for correct IP address allocation.
* Automatic Allocation:-Same IP address is allocated when a machine connects to a network.

### Webserver & Firewall

A Webserver is a program that uses HTTP to respond to requests made by clients. A computers browser acts as a client which makes a request to a server. The Server can be requested using the fixed IP address of the server as well. Since it is difficult for users to remember the IP address of servers the fixed IP address is mapped with to a unique name using the DNS server. In this case the fixed IP address of the server is 10.10.10.5 and the name it is mapped to is Linuxsara.com. The secondary web server IP 10.10.10.6 is also mapped to the same name. Apache2 is one of the most commonly used web server. This web server is sed to serve Web pages requested by client computers.
A firewall is a network security implementation that allows or denies specific network traffic to the monitored incoming and outgoing traffic. Ubuntu has an inbuilt firewall called “uncomplicated firewall”- ufw. By default, ufw is disabled. We need to enable ufw and add the specific commands to allow or deny IP addresses and protocols.

### Backup Server

In order to prevent the loss of data due to any unforeseen events backing up of the data is of at most importance. System backup provides security to the network by retaining compressed versions of the filesystems of various nodes in the network.The web server has to create a backup of its files and store in a remote server. In the event of system crash, corruption or failure, the filesystem can be restored from the backup that was stored beforehand. Systems backups are taken as frequently as desired.

## Signalling
### Domain Name System

1. DNS request is sent to Local DNS server.
2. Local DNS forwards the query to Root name server.
3. Root name server responds with the A record for TLD server.
4. Local DNS then sends query to TLD.
5. TLD responds with NS and A record for the Authoritative server.
6. Local DNS then queries Authoritative server and it in turn responds with the A record for the queried hostname.
7. Local DNS then responds with that reply from Authoritative server to the client.

### Dynamic Host Configuration Protocol

DHCP signalling:-
DHCP is a connection-less service model which uses UDP (User Data-gram Protocol). DHCP uses two UDP ports for its operations , 67 is used by the DHCP server and 68 is used by the DHCP client. These ports are similar to the BOOTP protocol.
The DHCP operates as follows:-
1) DHCP DISCOVER: The DHCP server starts with a client broadcasting a request using a destination address or a specific subnet broadcast address.This is the IP address lease request.
2) DHCP OFFER: Once the DHCP server receives the DHCPrequest from the client, the server reserves an IP address for that client and makes the lease offer by sending a DHCPOFFER message to the client. The DHCP OFFER message contains the MAC address of the client, the leased IP address, the subnet mask, the lease duration and the the IP address of the DHCP server.
3) DHCP REQUEST: In response to the DHCPOFFER message, the client replies with a DHCPREQUEST to the server,requesting the offered address.The client can receive DHCP offers from multiple DHCP servers,but the client accepts only one offer. The servers are informed about whose offer is accepted by the client.When the other servers receive this message, they withdraw their offer and send back the offered IP address back to the IP pool.
4) DHCP ACKNOWLEDGEMENT: When the DHCP server receives the DHCPREQUEST message from the client,the configuration goes into the final state.In this phase a DHCPACK packet is sent to the client.This packet has the information about the lease duration and other details requested by the client.

### Web Server

1.Download the apache2 package for webserver.
2.After the package is installed, the Apache 2 web server is started.
3.Change the directory if desired. (It has been done in this project)
4.The web page of the server is changed and restarted.
5.Add specific address to web server port.
6.To listen only on specific IP address we add commands to ensure web server listens only on specific IPv4 and IPv6 address. Server listens on port 80.
7.Backup data in compressed form which the backup server can retrieve when required.

### Firewall

1. The IP tables are configured in the web server.
2. The HTTP response and HTTP request from the web server are accepted, forwarded or rejected based on the IP tables.

### Backup Server

1. The web server backs up its data with backup server.
2. It retrieves the compressed data of .zip file format by using rsync command and with the help of ssh protocol, the data is synced between the web server and the backup serve
3. All these commands are automated using crontab

## The Requirements

* Implement a DHCP server that assigns IP addresses to the clients in the network
* Implement a web server that hosts a web page
* Implement a master DNS server and a slave DNS server
* Ensure that the clients in the network can access the web pages in the server by getting the name-to-IP address resolved by the DNS server
* Create backups of the webpages of the web server to another backup server on the network

## Hierarchy

Dynamic Host Configuration Protocol (DHCP)
Client -> DNS Server -> Client
Web Server
Backup Server

## Configuration
### DNS

BIND9 DNS server is used. Master and slave configuration is implemented in which slave is updated automatically with the master DNS. Both forward and reverse look ups have been implemented.
Steps to configure Master DNS server:
1.Installing BIND9 DNS server:
2.Change hostname:
3.Edit hosts file:
4.Edit file
5.Edit this file to configure forwarders:
6.Create forward and reverse zones:
* Reverse IPv6 Zone
7.Create folder ‘Zones’
8.Copy contents of local hostname file to the file ‘db.linuxsara.com’
9.Edit ‘db.linuxsara.com’ file to create records for forward and reverse zones
10.Copy contents of local hostname file to ‘db.10’
11.Edit ‘db.10’ to add reverse records.
12. Create file ‘db.2001’ in a same way as created for IPv4
Steps to Configure Slave DNS Server:
Repeat steps from 1 to 5.
Create forward and reverse zones:
* Forward zone
* Reverse IPv4 Zone
* Reverse IPv6 Zone
Testing
1.Use ‘nslookup’ command to query DNS server for multiple hostnames.
Example: nslookup linuxsara.com nslookup www.linuxsara.com nslookup sloth.linuxsara.com
2.Use ‘dig’ command for the detailed analysis of DNS records and authoritative servers

### DHCP

STEPS TO CONFIGURE DHCP server for IPv4:-
Step 1: Update all the packages
Step 2: Install DHCP server
Step 3: Edit the configuration file
static IP address using DHCP
STEP 4: edit the interface
STEP 5: Assign a static IP to ETH0
* DNS
STEP 6: Restart the interfaces and the DHCP server
STEPS TO CONFIGURE DHCP server for IPv6
STEP 1:Configure the /etc/network/interfaces with static IP of IPV6
STEP 2:Set in /etc/sysctl.conf the following configuration
STEP 3:Execute the following command to make changes in the kernel
STEP 4:Install the router advertisement daemon
STEP 5:Configure the radvd.conf file
STEP 6:Start the daemon
STEP 7:Create and edit the dhcpd6.conf file
STEP 8:Start the dhcp server6
DHCP Testing:-
a) ifconfig
Check whether the client has been assigned with an IP address from the given range.
b)grep -i dhcp /var/log/syslog
Check logs on the client for the DHCP message
c)sudo dhclient -r
Releases the current IP address assigned.

### Webserver

1) Install the apache2 package:
2)Change the Default Directory apache2 server: -
a)Change the directory to the user defined directory in apache2.conf file
b)Change the Document root to point towards the Particular folder containing the html page.
3)Change the HTML file
4)Assigning IP addresses to the Webservers:-
5)Listen for HTTP requests on both IPv4 and IPv6 address for primary and secondary webservers:-
6)Restart the server
Testing
1. Enter the URL in the web browser and check if the hosted html page is displayed or not.

### Firewall

Firewall allows the system administrator to accept, forward or drop the packets using ip tables. Ubuntu has an inbuilt firewall called “uncomplicated firewall”- ufw. By default, ufw is disabled. We need to enable ufw and add the specific commands to allow or deny IP addresses or protocols.
Testing:

### Backup

rsync is a protocol built for Unix-like systems that provides unbelievable versatility for backing up and synchronizing data. It can be used locally to back up files to different directories or can be configured to sync across the Internet to other hosts.
First, we need to install/update the rsync client:
To configure rsync for external backup, we will use method of tunneling rsync through SSH. Most servers and even many clients already have SSH, and it can be used for your rsync backups.If not, install ssh on webserver and backup server:
Create and share hey generated to allow ssh access from secondary to primary without password access:- To generate a rsa key (The default is a 2048 bit key):-
Allows a host to transfer the generated key to another host. By sharing of such a key a ssh can be perfomed without the use of any password
Automatically create a backup zip file on Primary server:-
The data files on the webserver are first zipped and compressed:
Then, this compressed .zip is moved to the backup server using the following command:
Automatically retrieve backup zip file from primary server and unzip it to be in synch with the primary server:-
Then this file is decompressed using unzip to obtain original files.
Unzip File:-
Testing:

## Integrated Testing

1) DHCP should be up and running
2) Ensure the Primary and Secondary DNS is up and running.
3) Enter the command 'ifconfig' in the terminal and check whether IP address is assigned to the client from the range assigned.
4) Execute 'nslookup' linuxsara.com' on the client. This will confirm that the client can access the DNS server.
5) Client requests for the WEB-PAGE "www.linuxsara.com" which is hosted by the webserver.
6) The firewall will authenticate the request and send the webpage as a reply to the client request.
7) Client request for the Web-Page and is blocked by the Firewall.This is because the client has the IP address which belongs to the denial range.
8) Check the system time , modify the crontab accordingly , confirm backup is taken and copied to the backup server.

## ALGORITHM

1) DHCP:
Client request for an IP from DHCP server
2) DNS:
DNS Query is generated by the client and sent to the DNS server
3) Webserver:
Client gets an IP address after DNS resolving
Client sends an HTTP request to the webserver to get the web page hosted on the server
4) FIREWALL:
The packet received by the Web Server is authenticated

## Future Improvements

1) Security and Robustness can be improved by adding security features like VPN, NTP etc.
2) Dyanamic DNS can be implemented
3) Simulation of real-time network traffic and validating network performance.