Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

18B15CS311: Computer Networks and Internet of Things (CN & IoT) Lab

Assignment – 01 & 02

UNIX/Linux and Windows General and Networking Commands

The objective of the lab assignments 01 and 02 is to make the students familiar with the general and
networking commands used in UNIX/Linux and Windows operating systems.

1. Environment Setup

To practice the general and networking commands one may use 1) A computer with UNIX/LINUX and
Windows Installed, 2) A virtual machine environment with Linux and windows installed; or 3) Online platforms.
If one does not have the choice of using options 1 or 2, here is the list of online resources for practice. One
needs to register in corresponding websites to utilize the services of online simulators/emulators. Read and
follow the instructions in the websites given below to utilize the services.

Online Linux simulators and emulators

OnWorks https://www.onworks.net/ (Multiple OS platforms)


Linux Zoo https://linuxzoo.net/ (for Linux)
Webminal https://www.webminal.org (for Linux)

2. UNIX/LINUX Commands

The following are the general commands [8]


Command Description

pwd prints working directory (prints to screen, ie displays the full path, or your location on the filesystem) ls lists contents of current
directory
ls –l lists contents of current directory with extra details
ls /home/user/*.txt lists all files in /home/user ending in .txt

cd change directory to your home directory


cd ~ change directory to your home directory
cd /scratch/user change directory to user on scratch

cd - change directory to the last directory you were in before changing to wherever you are now mkdir mydir makes a directory
called mydir

rmdir mydir removes directory called mydir. mydir must be empty


touch myfile creates a file called myfile. updates the timestamp on the file if it already exists, without modifying its contents cp myfile myfile2 copies
myfile to myfile2. if myfile2 exists, this will overwrite it!

rm myfile removes file called myfile

rm –f myfile removes myfile without asking you for confirmation. useful if using wildcards to remove files *** cp –r dir newdir copies the
whole directory dir to newdir. –r must be specified to copy directory contents recursively rm –rf mydir this will delete directory mydir
along with all its content without asking you for confirmation! *** nano opens a text editor. see ribbon at bottom for help. ^x means CTRL-
x. this will exit nano nano new.txt opens nano editing a file called new.txt

cat new.txt displays the contents of new.txt

more new.txt displays the contents of new.txt screen by screen. spacebar to pagedown, q to quit head new.txt displays
first 10 lines of new.txt

tail new.txt displays last 10 lines of new.txt

tail –f new.txt displays the contents of a file as it grows, starting with the last 10 lines. ctrl-c to quit. mv myfile newlocdir
moves myfile into the destination directory newlocdir
mv myfile newname renames file to newname. if a file called newname exists, this will overwrite it! mv dir subdir
moves the directory called dir to the directory called subdir
mv dir newdirname renames directory dir to newdirname

top displays all the processes running on the machine, and shows available resources du –h --max-depth=1 run this in your
home directory to see how much space you are using. don’t exceed 5GB ssh servername goes to a different server. this
could be queso, brie, or provolone
grep pattern files searches for the pattern in files, and displays lines in those files matching the pattern date shows the
current date and time
anycommand > myfile redirects the output of anycommand writing it to a file called myfile

date > timestamp redirects the output of the date command to a file in the current directory called timestamp anycommand >>
myfile appends the output of anycommand to a file called myfile

date >> timestamp appends the current time and date to a file called timestamp. creates the file if it doesn’t exist command1 |
command2 “pipes” the output of command1 to command2. the pipe is usually shift-backslash key date | grep Tue displays any line in
the output of the date command that matches the pattern Tue. (is it Tuesday?) tar -zxf archive.tgz this will extract the contents of the
archive called archive.tgz. kind of like unzipping a zipfile. *** tar -zcf dir.tgz dir this creates a compressed archive called dir.tgz that
contains all the files and directory structure of dir
time anycommand runs anycommand, timing how long it takes, and displays that time to the screen after completing anycommand man
anycommand gives you help on anycommand

cal -y free calendar, courtesy unix


CTRL-c kills whatever process you’re currently doing
CTRL-insert copies selected text to the windows clipboard (n.b. see above, ctrl-c will kill whatever you’re doing) SHIFT-insert pastes
clipboard contents to terminal

*** = use with extreme caution! you can easily delete or overwrite important files with these.

Absolute vs relative paths.


Let’s say you are here: /home/turnersd/scripts/. If you wanted to go to /home/turnersd/, you could type: cd /home/turnersd/. Or you could use a
relative path. cd ..(two periods) will take you one directory “up” to the parent directory of the current directory.
. (a single period) means the current directory
.. (two periods) means the parent directory
~ means your home directory
A few examples
mv myfile .. moves myfile to the parent directory

cp myfile ../newname copies myfile to the parent directory and names the copy newname cp
/home/turnersd/scripts/bstrap.pl . copies bstrap.pl to “.” i.e. to dot, or the current directory you’re in cp myfile
~/subdir/newname copies myfile to subdir in your home, naming the copy newname

more ../../../myfile displays screen by screen the content of myfile, which exists 3 directories “up”

Wildcards (use carefully, especially with rm)


* matches any character. example: ls *.pllists any file ending with “.pl” ; rm dataset*will remove all files beginning with “dataset” [xyz]
matches any character in the brackets (x, y, or z). example: cat do[or]m.txt will display the contents of either doom.txt or dorm.txt

Refer the link [9] for some more commands to practice on Linux/Unix operating
systems. 3. Windows Commands

Refer the link [10] for windows commands

4. Networking Commands

4.1 Windows networking commands

Refer the link [4] to know about the following commands.

Ping – Ping is probably the most familiar of networking command line tools. With it, you are able to send an
echo request to a device locally, or on the Internet, and receive a reply.
Netstat – Stands for Network Statistics, this command will display connection information, routing tables and so
on. Entering the command will display what’s going on while you use the network and Internet. Use netstat -e
for interface stats.

Arp – Stands for Address Resolution Protocol displays and modifies entries in the ARP cache, which contains
one or more tables that are used to store IP addresses and their resolved Ethernet or Token Ring physical
addresses.

NbtStat – The nbtstat command is a diagnostic tool for NetBIOS over TCP/IP. Its primary design is to help
troubleshoot NetBIOS name resolution problems. It’ll display the human-friendly names of devices on the
network along with their IP addresses.

Hostname – If you’re struggling to find the name of a Windows computer you’ve got on your network, simply
enter the hostname command and it’ll display the computer’s local name.

Tracert – Stands for Trace Route will examine the path to a remote computer, either locally or on the Internet.
For example, entering tracert google.com will display the hops taken over networking devices to get to one of
the Google servers.

Ipconfig – Probably one of the most used networking command in Windows. Ipconfig will display information on
the local computer’s network interfaces, such as IP addresses (both IPv4 and IPv6), Hostname, gateway and
so on.

Nslookup – This tool can be used to look up the and diagnose the Domain Name System (DNS) of a location
on the local network or Internet.

Route – The Windows Route command allows you to view the device’s routing tables. To do so, simply type
Route Print. This will print the network interfaces, IPv4 and IPv6 route tables.

Pathping – This is a handy command that combines the best elements of Ping and Tracert. It will display the
latency and packet loss between one computer and another (either locally or on the Internet), and after 300
seconds display a detailed report.

Getmac – Every network interface has a unique Media Access Code assigned to it. Some routers are able to
limit connection to the network by only allowing user-entered MAC addresses in. You can get the MAC address
of a windows computer by entering getmac.

Netsh – This is a complex command that when entered will put you into a different shell, the Network Shell
(netsh). It’s capable of displaying and configuring information regarding a computer’s networking setup.

Telnet – This is a command that can be used to connect to another computer, or manage a router or switch.
You can send and receive files, send command and much more. With Telnet you’re also able to connect to
active Bulletin Board Systems. For example, enter: telnet jiit.ac.in

4.2 Linux networking commands

Linux Networking Commands

Refer the link [3] and practice the Linux networking commands

ifconfigDisplay and manipulate route and network interfaces.


ip It is a replacement of ifconfig command.
traceroute Network troubleshooting utility.
tracepath Similar to traceroute but doesn't require root privileges.
ping To check connectivity between two nodes.
netstat Display connection information.
ss It is a replacement of netstat.
dig Query DNS related information.
nslookup Find DNS related query.
route Shows and manipulate IP routing table.
host Performs DNS lookups.
arp View or add contents of the kernel's ARP table.
iwconfig Used to configure wireless network interface.
hostname To identify a network name.
curl or wget To download a file from internet.
mtr Combines ping and tracepath into a single command.
whois Will tell you about the website's whois.
ifplugstatus Tells whether a cable is plugged in or not.

Refer the link [5] for some more networking commands related to 1) General networking; 2) Network
Configuration; 3) Internet Specific Commands; and 4) Remote Administration.

Further, refer the link [6] for Linux Networking.

5. Network Scanning

NMAP (Network mapper) is a tool popularly used for network scanning. One may download the nmap tool from
its official website [11] according to the operating system. Refer the link [10] for its usage and practice the
following scanning techniques

a. Port scanning (TCP scanning)


b. Ping and UDP scanning
c. OS fingerprinting
d. Services scanning

Refer the link [12] for video lecture on NAMP tool for basic network scanning.

6. Linux Firewalls

IPTABLES was explained in this section for describing configuration of Linux Firewalls. The given
instructions are w.r.t to Debian based LINUX. Use admin/root privileges to work with iptables. Refer the
link [13] for video lecture on iptables. Further, to practice the linux firewall settings, one may use the
online service available with link [14].

1. Installation

apt-get install iptables

2. If you update your firewall rules and want to save the changes

apt-get install iptables-persistent


netfilter-persistent save

3. To accept all traffic on your loopback interface

iptables -A INPUT -i lo -j ACCEPT


iptables -A OUTPUT -o lo -j ACCEPT

4. To allow established and related incoming connections

iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT


5. To allow established and related outgoing connections

iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT

6. To move traffic from internal to External

iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

7. To drop invalid packets


iptables -A INPUT -m conntrack --ctstate INVALID -j DROP

8. To block an IP address

iptables -A INPUT -s IP Address -j DROP

9. To block a network interface

iptables -A INPUT -i eth0 -j DROP

10. Allowing/Blocking services

SSH - 22
Telnet - 23
HTTP - 80
HTTPS - 443
SMTP - 25
POP3 - 110
POP3S - 995
MySQL - 3306
PostgreSQL - 5432
IMAP - 143

SSH
iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j
ACCEPT iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j
ACCEPT

SSH from specific IP

iptables -A INPUT -p tcp -s network_id/24 --dport 22 -m conntrack --ctstate


NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT

Telnet
iptables -A INPUT -p tcp --dport 23 -m conntrack --ctstate NEW,ESTABLISHED -j
ACCEPT iptables -A OUTPUT -p tcp --sport 23 -m conntrack --ctstate ESTABLISHED -j
ACCEPT

HTTP

iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW,ESTABLISHED -j


ACCEPT iptables -A OUTPUT -p tcp --sport 80 -m conntrack --ctstate ESTABLISHED -j
ACCEPT
11. Listing rules and other commands

By specification

iptables -S
iptables -S TCP

Listing rules as table

iptables -L
Listing INPUT rules

iptables -L INPUT

Showing packet count and aggregated size

iptables -L INPUT -v

Deleting rules by specification

iptables -D INPUT -m conntrack --ctstate INVALID -j DROP

Deleting rules by chain number

iptables -L --line-numbers

Flushing chains

sudo iptables -F

12. Activating multiple NICs in Linux (Ex. Kali Linux)

vim /etc/network/interfaces

# The loopback network interface


auto lo
iface lo inet loopback

# NAT
auto eth0
iface eth0 inet dhcp

# Host-only
auto eth1
iface eth1 inet dhcp

13. Providing internet on a LAN (eth0 has internet and eth1 is LAN subnet)

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE


iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j
ACCEPT iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

echo 1 /proc/sys/net/ipv4/ip_forward
Next, edit /etc/sysctl.conf and change the line that says net.ipv4.ip_forward = 0 to net.ipv4.ip_forward =
1. and reboot the system.

Refer the links [15-18] for more information on iptables firewall settings.

7. References
[1] https://download.microsoft.com/download/5/8/9/58911986-D4AD-4695-BF63-F734CD4DF8F2/ws
commands.pdf
[2] https://www.computervillage.org/articles/CommandLine.pdf
[3] https://www.javatpoint.com/linux-networking-commands
[4] https://www.computernetworkingnotes.com/networking-tutorials/basic-networking-commands-explained with-
examples.html
[5] https://tldp.org/LDP/GNU-Linux-Tools-Summary/html/c8319.htm
[6] https://www.actualtechmedia.com/wp-content/uploads/2017/12/CUMULUS-NETWORKS-Linux101.pdf [7]
https://groups.inf.ed.ac.uk/tulips/projects/1617/mjartan.pdf
[8] Linux/Unix Command Line Cheat Sheet - GettingGeneticsDone.blogspot.com
[9] http://www.tjhsst.edu/~dhyatt/superap/unixcmd.html
[10]https://nmap.org/bennieston-tutorial/
[11]https://nmap.org/
[12]NMAP tool for basic network scanning: https://youtu.be/MK7WPH79gR8
[13]Configuring Linux firewall iptables https://youtu.be/ADemvnfXjP8
[14]https://groups.inf.ed.ac.uk/tulips/projects/1617/FirewallWebApp/
[15]From HowToGeek by : Korbin Brown https://www.howtogeek.com/177621/the-beginners-guide-to-iptables the-linux-
firewall/
[16]From nixCraft - 25 iptables Examples https://www.cyberciti.biz/tips/linux-iptables-examples.html/ [17] Here is
Juniper Networks instructions on implementing a Stateful Firewall on their hardware devices. Take few minutes and
compare this with what you have already learned about iptables.
https://www.juniper.net/documentation/en_US/junos/topics/usage-guidelines/services-configuring-stateful firewall-
rules.html/
[18]https://www.digitalocean.com/community/tutorials/a-deep-dive-into-iptables-and-netfilter
architecture#:~:text=The%20Mangle%20Table,be%20altered%20in%20similar%20ways.

You might also like