2024_CN_Practicals_1_to_10
2024_CN_Practicals_1_to_10
IT Department
L E College, Morbi (Degree)
Academic Year: 2024-25
Lab Experiments
Course: Computer Networks (3150710)
No. Aim
1 To study basic network configuration of a PC.
2 (a) Define IP address. Give an example.
(b) Discuss how to identify class of an IP address.
(c) Discuss how classes differ in netid and hostid.
(d) Write network masks for class A, B and C.
(e) Explain allocation of block of addresses for each class using diagram (No
description required)
3 (a)Define subnetting.
(b)Perform subnetting as follows.
1. Consider a block of IP addresses whose one IP address is 132. 14. 23.
4. Divide this block into 8 subnets.
2. Consider a block of IP addresses whose one IP address is 10. 0. 0. 4.
Divide this block into 4 subnets.
3. Consider a block of IP addresses whose one IP address is 221. 182. 3.
4. Divide this block into 4 subnets.
a.What is network address and broadcast address of the block without subnetting ?
b.How many hosts can be present in the block without subnetting.
c. What is network mask without subnetting ?
d.What is subnet address and broadcast address of each subnet?
e.How many hosts can be present in each subnet
En:230313116010
Practical 4
Aim: Perform subnetting using cisco packet tracer. Demonstrate for both
cases- classful and classless addressing.
CLASSFUL
1. Place 5 pcs on the workspace and connect them together with the help of a switch
2. Now 4 of the following pcs belong to the same subnet and the other one belongs to a
different subnet.
3. Dividing network 142.16.0.1 into 4 subnets
So the pcs in one subnet can interact whereas the ones lying in different subnets
cannot.
En:230313116010
CLASSLESS
Once the installation completes, the service will be disabled initially, therefore, we need to start it manually
for the mean time and also enable it to start automatically from the next system boot
On SystemD
# systemctl start vsftpd
# systemctl enable vsftpd
On SysVInit
# service vsftpd start
# chkconfig --level 35 vsftpd on
Next if system has UFW firewall enabled, you have to open ports 20 and 21 where the FTP daemons are
listening, in order to allow access to FTP services from remote machines, then add the new firewall rules as
follows:
$ sudo ufw allow 20/tcp
$ sudo ufw allow 21/tcp
$ sudo ufw status
Now, configure VSFTPD to allow/deny FTP access to users based on the user list file /etc/vsftpd.userlist.
Note that by default, users listed in userlist_file=/etc/vsftpd.userlist are denied login access with
userlist_deny=YES option if userlist_enable=YES.
En:230313116010
But, the option userlist_deny=NO twists the meaning of the default setting, so only users whose username is
explicitly listed in userlist_file=/etc/vsftpd.userlist will be allowed to login to the FTP server.
userlist_enable=YES # vsftpd will load a list of usernames, from the filename given by
userlist_file
userlist_file=/etc/vsftpd.userlist # stores usernames.
userlist_deny=NO
*Important: When users login to the FTP server, they are placed in a chrooted
jail, this is the local root directory which will act as their home directory for the FTP
session only.
Now add/modify or uncomment these two following options to restrict FTP uses to their home directories.
chroot_local_user = YES
allow_writable_chroot = YES
The option ‘chroot_local_user = YES’ importantly means local users will be placed in a chroot jail, their
home directory by default after they login. VSFTPD doesn’t allow chroot jail to be writable but however we
can do it by second option ‘allow_writable_chroot = YES’ to disable that default setting.
Save the changes and restart the VSFTPD services for the changes above to take effect:
On SystemD
# systemctl restart vsftpd
On SysVInit
# service vsftpd restart
Here, the user aaronkilik in the file /etc/vsftpd.userlist with the echo command and tee command will be
listed explicitly as below
Let’s try with anonymous log in then we’ll test with not listed user and then with the listed user. Here
outputs are present in the same order
# ftp 192.168.56.104
Connected to 192.168.56.104 (192.168.56.104).
220 Welcome to FTPexample.com FTP service.
Name (192.168.56.104:aaronkilik) : anonymous
530 Permission denied.
Login failed.
ftp> bye
221 Goodbye.
En:230313116010
# ftp 192.168.56.104
Connected to 192.168.56.104 (192.168.56.104).
220 Welcome to FTPexample.com FTP service.
Name (192.168.56.10:root) : user1
530 Permission denied.
Login failed.
ftp> bye
221 Goodbye.
# ftp 192.168.56.104
Connected to 192.168.56.104 (192.168.56.104).
220 Welcome to FTPexample.com FTP service.
Name (192.168.56.104:aaronkilik) : aaronkilik
331 Please specify the password.
Password:
230 Login successful.
Remote system type is
UNIX.
Using binary mode to transfer files.
create the alternative local root directory for the user (aaronkilik, yours is possibly not the same) and set the
required permissions by disabling write permissions to all other users to this directory
$ sudo mkdir /home/aaronkilik/ftp
$ sudo chown nobody:nogroup /home/aaronkilik/ftp
$ sudo chmod a-w /home/aaronkilik/ftp
Then, create a directory under the local root with the appropriate permissions where the user will store his
files:
$ sudo mkdir /home/aaronkilik/ftp/files
$ sudo chown -R aaronkilk:aaronkilik /home/aaronkilik/ftp/files
$ sudo chmod -R 0770 /home/aaronkilik/ftp/files/
Afterward add or modify the options below:
user_sub_token=$USER # inserts the username in the local root directory
local_root=/home/$USER/ftp # defines any users local root directory
Save the file and restart the VSFTPD services with recent changes
At last perform the final check that the user’s local root directory is the FTP directory we created in his home
directory.
# ftp 192.168.56.104
Apache is available at official Ubuntu software repositories. Update the system’s package index and then
install Apache package.
$ sudo apt update
$ sudo apt install apache2
After successful installation, check important Apache default files and directories
Main config files directory: /etc/apache2/
Main config file: /etc/apache2/apache2.conf
Additional configuration snippets: /etc/apache2/conf-available/ and /etc/apache2/conf-enabled
Pre-site virtual host configuration snippets: /etc/ apache2/sites-available/ and /etc/apache2/sites-
enabled/.
Configuration snippets for loading modules: /etc/apache2/mods-available/ and /etc/apache2/mods-
enabled/.
Web DocumentRoot: /var/www/html/.
Log files (error and access logs) directory: /var/log/apache/.
After the Apache installation web-server service should be started automatically, for verification use
command
$ sudo systemct1 status apache2
Now that your Apache web server up and running, let’s go over some basic management commands to
manage the Apache service using these following commands.
$ sudo systemctl status apache2
$ sudo systemctl stop apache2
$ sudo systemctl start apache2
$ sudo systemctl restart apache2
$ sudo systemctl reload apache2
$ sudo systemctl enable apache2
$ sudo systemctl disable apache2
Next, if you have the UFW firewall enabled and running on your system, you need to open the ports 80 and
443 to allow client requests to Apache web server via HTTP and HTTPS respectively, then reload the firewall
settings using following commands.
En:230313116010
$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp
$ sudo ufw reload
Next, create a test html index page for your site in the root directory of your website.
$ sudo vim /var/www/html/apacheexmp.com/index.html
En:230313116010
<html>
<head>
<title>Welcome to Apacheexmp.com!</title>
</head>
<body>
<h1>The apacheexmp.com virtual host is working!</h1>
</body>
</html>
Save and close the file when you are finished.
Now create a apacheexmp.com.conf virtual host file for your site under /etc/apache2/sites-
available/ directory.
$ sudo vim /etc/apache2/sites-available/apacheexmp.com.conf
Paste in the following configuration directive, which is similar to the default, but updated with new
new directory and domain name.
<VirtualHost *:80>
ServerName apacheexmp.com
ServerAlias www.apacheexmp.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/apacheexmp.com/
ErrorLog ${APACHE_LOG_DIR}/apacheexmp.com_error.log
CustomLog ${APACHE_LOG_DIR}/apacheexmp.com_access.log combined
</VirtualHost>
Save and close the file when you are finished.
Next, test your Apache2 config for any errors, if all is Ok, restart the apache2 service, as shown.
$ sudo apache2ctl configtest
$ sudo systemctl restart apache2
Since the domain name apacheexmp.com is a dummy domain (not a fully registered domain), you also need
to setup local DNS by adding it the /etc/hosts file.
$ sudo vim /etc/hosts
Then add the following line at the bottom of the file, make sure to replace 192.168.56.101 and
apacheexmp.com with your server’s IP address and local domain name.
192.168.56.101 apacheexmp.com
Save the file and exit.
Finally open a web browser and access the test site’s index page using
http://apacheexmp.com
The output will be displaying the text as: “The apacheexmp.com virtual host is working!”
En:230313116010
Practical-7
Step 4: Now it’s Time to configure Static Route over all those Four Routers R0,R1,R2 and R3
Ststic Routing Configuration on Router R0:
R0(config)#ip route 192.168.5.0 255.255.255.0 192.168.4.2
At the and test the communication b/w two PC to test whether your routing is property
configured or not.
Then ping with another PC:
En:230313116010
En:230313116010
\
En:230313116010
Practical 8
Step 1: First, open the Cisco packet tracer desktop and select the devices given
below:
1. PC PC 6
2. Switch PT-Switch 3
3. Router PT-router 3
IP Addressing Table:
Step 2: Configure the PCs (hosts) with IPv4 address and Subnet Mask
according to the IP addressing table given above.
To assign an IP address in PC0, click on PC0.
Then, go to desktop and then IP configuration and there you will IPv4
configuration.
Fill IPv4 address and subnet mask.
En:230313116010
En:230313116010
Step 4: After configuring all of the devices we need to assign the routes to
the routers. To assign RIP routes to the particular router:
First, click on router0 then Go to CLI.
Then type the commands and IP information given below.
CLI command : network <network id>
RIP Routes for Router0 are given below:
o Router(config)#network 192.168.1.0
o Router(config)#network 192.168.4.0
En:230313116010
o Router(config)#network 192.168.2. 0
o Router(config)#network 192.168.4. 0
o Router(config)#network 192.168.5. 0
o Router(config)#network 192.168.3.4
o Router(config)#network 192.168.5.3
En:230313116010
A simulation of the experiment is given below we are sending PDU from PC0 to
PC2 and PC3 to PC5:
En:230313116010
En:230313116010
Practical 9
Aim: To implement packet transfer between two processes using TCP sockets.
Client-Side Programming
Communication
To communicate over a socket connection, streams are used to both input and output the data.
Java Implementation
// A Java program for a Client
import java.net.*;
import java.io.*;
while (!line.equals("Over"))
{
try
{
line = input.readLine();
out.writeUTF(line);
}
catch(IOException i)
{
System.out.println(i);
}
}
Communication
getOutputStream() method is used to send the output through the socket.
Java Implementation
// A Java program for a Server
import java.net.*;
import java.io.*;
socket = server.accept();
System.out.println("Client accepted");
}
catch(IOException i)
{
System.out.println(i);
}
}
System.out.println("Closing connection");
En:230313116010
// close
connection
socket.close();
in.close();
}
catch(IOException i)
{
System.out.println(i);
}
}
Important Points
Server application makes a ServerSocket on a specific port which is 5000. This starts our
Server listening for client requests coming in for port 5000.
Then Server makes a new Socket to communicate with the client.
socket = server.accept()
The accept() method blocks(just sits there) until a client connects to the server.
Then we take input from the socket using getInputStream() method. Our Server keeps
receiving messages until the Client sends “Over”.
After we’re done we close the connection by closing the socket and the input stream.
To run the Client and Server application on your machine, compile both of them. Then
first run the server application and then run the Client application.
En:230313116010
To run on Terminal or Command Prompt
InetAddress ip =
InetAddress.getLocalHost(); byte buf[] =
null;
System.out.println("Client:-" + data(receive));
En:230313116010
***