You are on page 1of 33

PART A

(TO BE REFFERED BY STUDENTS)


A.1 AIM:
Execute basic network commands and Network configuration commands in Linux.

A.2 PREREQUISITE
Basics of networking, Internet, Linux OS.

A.3 OUTCOME
 CO3: Analyse network layer, error control, flow control and routing algorithms

A.4 THEORY
Computers are connected in a network to exchange information or resources each other. Two
or more computer connected through network media called computer network. There are number of
network devices or media are involved to form computer network. Computer loaded with Linux
Operating System can also be a part of network whether it is small or large network by its
multitasking and multiuser natures. Maintaining of system and network up and running is a task of
System / Network Administrator’s job. In this lab we are going to review frequently used network
configuration and troubleshoot commands in Linux.

A.5 INSTRUCTIONS
1. Write in brief about each title provided in PART B.
2. Provide the following for each networking command.
Syntax, Purpose, Options and Arguments, Output.
PART B
(PART B: TO BE COMPLETED BY STUDENTS)
(Students must submit the soft copy as per following segments within two hours of the practical.
The soft copy must be uploaded on the Blackboard or emailed to the concerned lab in charge
faculties at the end of the practical in case the there is no Black board access available)

Roll No. I233 Name: Ravi Sista


Class : MBA TECH IT Batch : B
Date of Experiment: Date of Submission
Grade :

B.1 REPORT
1. Hostname

hostname command in Linux is used to obtain the DNS(Domain Name System) name and set
the system’s hostname or NIS(Network Information System) domain name. A hostname is a
name which is given to a computer and it attached to the network. Its main purpose is to
uniquely identify over a network.
Syntax :
hostname -[option] [file]

Example: We obtain the system hostname by just typing hostname without any attributes.

Options:

 -a : This option is used to get alias name of the host system(if any). It will return an empty line if no alias name is
set. This option enumerates all configured addresses on all network interfaces.

Syntax:
hostname -a

Example:

 -A : This option is used to get all FQDNs(Fully Qualified Domain Name) of the host system. It enumerates all
configured addresses on all network interfaces. An output may display same entries repetitively.

Syntax :
hostname -A
Example:

 -b : Used to always set a hostname. Default name is used if none specified.

Syntax :
hostname -b

Example:

 -d : This option is used to get the Domain if local domains are set. It will not return anything(not even a blank
line) if no local domain is set.

Syntax :
hostname -d

Example :

 -f : This option is used to get the Fully Qualified Domain Name(FQDN). It contains short hostname and DNS
domain name.

Syntax:
hostname -f

Example:

 -F : This option is used to set the hostname specified in a file. Can be performed by the superuser(root) only.

Syntax:
sudo hostname -F filename

Example:
 -i option:This option is used to get the IP(network) addresses. This option works only if the hostname is
resolvable.

Syntax:
hostname -i

Example:

 -I : This option is used to get all IP(network) addresses. The option doesn’t depend on resolvability of hostname.
hostname -I

Example:

 -s : This option is used to get the hostname in short. The short hostname is the section of hostname before the
first period/dot(.). If the hostname has no period, the full hostname is displayed.

Syntax :
hostname -s

Example:

 -V : Gives version number as output.

Syntax:
hostname -V

Example:

Note: To set the hostname we can use the command given below:
sudo hostname NEW_HOSTNAME

Here, NEW_HOSTNAME is the new hostname the user wants to give.

Example

2. Ping

PING (Packet Internet Groper) command is used to check the network connectivity between
host and server/host. This command takes as input the IP address or the URL and sends a
data packet to the specified address with the message “PING” and get a response from the
server/host this time is recorded which is called latency. Fast ping low latency means faster
connection. Ping uses ICMP(Internet Control Message Protocol) to send an ICMP echo
message to the specified host if that host is available then it sends ICMP reply message.
Ping is generally measured in millisecond every modern operating system has this ping pre-
installed.
Now let see the PING command :
PING Version:
To get ping version installed on your system.
sudo ping -v

Using PING:
ping www.geeksforgeeks.org
To stop pinging we should use ctrl+c otherwise it will keep on sending packets.

 min: minimum time to get a response


 avg: average time to get responses
 max: maximum time to get a response

Controlling the number of pings:


Earlier we did not define the number of packets to send to the server/host by using -c option we can do so.
ping -c 5 www.geeksforgeeks.org

Controlling the size of packets send:


Ealier a default sized packets were sent to a host but we can send light and heavy packet by using
-s option.

ping -s 40 -c 5 www.geeksforgeeks.org

Changing the time interval:


By default ping wait for 1 sec to send next packet we can change this time by using -i option.
ping -i 2 www.geeksforgeeks.org

Now, the ping interval will change to 2 seconds.


To get only summary:
To only get the summary about the network use -q option

ping -c 5 -q www.geeksforgeeks.org

To Timout PING:
To stop pingig after sometime use -w option.
ping -w 3 www.geeksforgeeks.org

This will stop pinging after 3 seconds

Flooding with PING:


To send packets as soon as possible. This is used to test network performance.
ping -f www.geeksforgeeks.org

To Add Timestamp
It is current time of event recorded by a machine over a network. It works by using TS option of IP packet.
We have three option with it

1. tsonly (timestamp only)


2. tsandaddr (timestamp and address)
3. tsprespec (timestamp pre-specified for multiple hosts)
ping -T tsonly -c 2 127.0.0.1
ping -T tsandaddr -c 2 127.0.0.1

Time to wait for response:


Sets time to wait for a response.
ping -c 5 -W 3 www.geeksforgeeks.org
To fill packet with data:
We can fill data in packet using -p option. Like -p ff will fill packet with ones.

ping -c 5 -p ff www.geeksforgeeks.org

Path MTU discovery:


It is a simple protocol to find out the maximum MTU(Maximum Transmission Unit) a TCP path can take.
We use an option with -m do (prohibit fragmentation), want (do PMTU discovery, fragment locally when packet size is
large), or dont (do not set DF flag).
ping -c 5 -M want www.geeksforgeeks.org

Specify TTL(Time To Live):


It is maximum hop a packet can travel before getting discarded.A value 0 will restricty packet to same host.
ping -c 5 -t 64 www.geeksforgeeks.org
3. Host

host command in Linux system is used for DNS (Domain Name System)
lookup operations. In simple words, this command is used to find the IP
address of a particular domain name or if you want to find out the
domain name of a particular IP address the host command becomes
handy. You can also find more specific details of a domain by specifying
the corresponding option along with the domain name.
Syntax:
host [-aCdlriTWV] [-c class] [-N ndots] [-t type] [-W time]
[-R number] [-m flag] hostname [server]

host command without any option: It will print the general syntax of the command along with the various options that
can be used with the host command as well as gives a brief description about each option.

Example:
Different options with the host command:

 host domain_name: This will print the IP address details of the specified domain.

Example:
host geeksforgeeks.org

 host IP_Address: This will display the domain details of the specified IP Address.

Example:

host 52.25.109.230

 -a or -v: It used to specify the query type or enables the verbose output.

Example:
host -a geeksforgeeks.org

 -t : It is used to specify the type of query.

Example 1:
host -t ns geeksforgeeks.org

Example 2: To print SOA record


host -t SOA geeksforgeeks.org

Example 3: To print txt record


host -t txt geeksforgeeks.org

 -C : In order to compare the SOA records on authoritative nameservers.

Example:
host -C geeksforgeeks.org

 -R : In order to specify the number of retries you can do in case one try fails. If anyone try succeeds then the
command stops.

Example:
host -R 3 geeksforgeeks.org

 -l :In order to list all hosts in a domain.For this command to work you need to be either an admin or a node
server.

Example:
host -l geeksforgeeks.org
4. ifconfig

ifconfig(interface configuration) command is used to configure the kernel-


resident network interfaces. It is used at the boot time to set up the
interfaces as necessary. After that, it is usually used when needed during
debugging or when you need system tuning. Also, this command is used to
assign the IP address and netmask to an interface or to enable or disable a
given interface.
Syntax:
ifconfig [...OPTIONS] [INTERFACE]

Options:

 -a : This option is used to display all the interfaces available, even if they are down.

Syntax:
ifconfig -a

Output:
 -s : Display a short list, instead of details.

Syntax:
ifconfig -s

Output:

 -v : Run the command in verbose mode – log more details about execution.

Syntax:
ifconfig -v

Output:

 up : This option is used to activate the driver for the given interface.

Syntax:
ifconfig interface up

 down : This option is used to deactivate the driver for the given interface.

Syntax:
ifconfig interface down

 add addr/prefixlen : This option is used to add an IPv6 address to an interface.

Syntax:

ifconfig interface add addr/prefixlen

 del addr/prefixlen : This option is used to remove an IPv6 address to an interface.

Syntax:
ifconfig interface del addr/prefixlen

 [-]arp : This option is used to enable/disable the use of ARP protocol on an interface.
Syntax:
ifconfig interface [-]arp

 [-]promisc : This option is used to enable/disable the promiscuous mode on an interface. If it is selected, all the
packets on the network will be received by the interface.

Syntax:
ifconfig interface [-]promisc

 [-]allmulti : This option is used to enable/disable all-multicast mode for an interface. If it is selected, all the
multicast packets will be received by the interface.

Syntax:
ifconfig interface [-]allmulti

 mtu N : The user uses this parameter to set the Maximum Transfer Unit(MTU).

Syntax:
ifconfig interface [-]allmulti

 –help : Display help related to ifconfig command.

Syntax:
ifconfig --help

Output:

5. ip addr, ip neigh
Many times it happens that you feel the need of knowing the IP address of your device. Internet Protocol address or IP
address is a set of numeric digits that are needed to identify your device and enable network communication because all
the devices that are connected through a network know each other only through their IP addresses. Moreover, the IP
address also specifies the location of a device. So it becomes necessary for you at times to know what is the IP address of
whichever device you are using. Now how to find this IP address is the real question. In the article below, we will tell you
all the ways through which you can find the IP address of your device while working in Linux environment, in our case
Ubuntu 18.04.

Four ways to find your current IP Address in Linux


Following are the four methods through which you can find the IP address of your device:

Method # 1: On the Desktop


The first method of finding the IP address of your device is through the Linux desktop interface. For this, you need to
proceed as follows:

Click on your network connection icon (Wi-Fi icon) shown at the top right of the title bar on which Ubuntu Desktop is
written. A cascading menu will appear which is shown below:

From the menu shown above, click on Connection Information. A new Connection Information window will appear which
is shown below:
In the window shown above, the red highlighted rectangle shows the IP address of your device written in front of IP
Address field.

Method #2: On the Shell with ip command


The second method of finding the IP address of your device is through a terminal command. In order to do this, you need
to perform the following steps:

First of all, open terminal by pressing Ctrl+ T or you can click on the terminal icon directly if it is shown on your task bar.
You can also click on the search icon located on the taskbar and then type Terminal and press enter to open it. The newly
opened terminal window is shown below:
Type the command ip addr show in the terminal and press enter.
ip addr show

This command is shown below:

As soon as you will press enter, some information will be displayed on the terminal window. From the information shown
below in the terminal screen, the highlighted rectangle shows the IP address of your device beside the inet field.

Method # 3: On the Shell with ifconfig command


The third method of finding the IP address of your device is through another terminal command. For this you need to
follow the steps mentioned below:

Launch terminal by pressing Ctrl+ T or clicking on the terminal icon or searching for terminal in the search window shown
below and pressing enter.
Then type the command:
/sbin/ifconfig

in the newly opened terminal window and press enter.

As soon as you will press enter, a lot of information will be displayed on the terminal screen. From the displayed
information below, the highlighted rectangle shows the IP address of your device besides the field of inet addr.

The ifconfig command works in the same way for finding the IP address of a device using terminal in Linux as ipconfig
command works for finding the IP address of a device using command prompt in Windows.

Method # 4: On the Shell by using hostname command


The method four for finding the IP address of your device makes use of yet another terminal command. For this method,
you need to follow the following steps:

Launch terminal by pressing Ctrl+ T or clicking on the terminal icon located on the taskbar or search for terminal in the
search window and press enter.

When the terminal window will appear, type the command:


hostname -I

and press enter. This command is shown in the following window:


As soon as you will press enter, the IP address of your device will be displayed on the terminal right below your entered
command. This is shown below:

6. traceroute/tracepath

tracepath
command
in Linux is used to traces path to destination discovering MTU along this path. It uses UDP port or
some random port. It is similar to traceroute, but it does not require superuser privileges and has
no fancy options. tracepath6 is a good replacement for traceroute6 and classic example of the
application of Linux error queues. The situation with IPv4 is worse because commercial IP routers
do not return enough information in ICMP error messages. Probably, it will change, when they will
be updated. For now, it uses Van Jacobson’s trick, sweeping a range of UDP ports to maintain trace
history.
Syntax:
tracepath [-n] [-b] [-l pktlen] [-m max_hops] [-p port] destination

traceroute command in Linux prints the route that a packet takes to reach the host. This command is useful
when you want to know about the route and about all the hops that a packet takes. Below image depicts how
traceroute command is used to reach the Google(172.217.26.206) host from the local machine and it also
prints detail about all the hops that it visits in between.

The first column corresponds to the hop count. The second column represents the address of that hop and
after that, you see three space-separated time in milliseconds. traceroute command sends three packets to the
hop and each of the time refers to the time taken by the packet to reach the hop.

Syntax: traceroute [options] host_Address [pathlength]


7. arp

arp command manipulates the System’s ARP cache. It also allows a complete dump of the ARP
cache. ARP stands for Address Resolution Protocol. The primary function of this protocol is to
resolve the IP address of a system to its mac address, and hence it works between level 2(Data link
layer) and level 3(Network layer).
Syntax:
arp [-v] [-i if] [-H type] -a [hostname]

-v, –verbose: This option shows the verbose information.

-n, –numeric: This option shows numerical addresses instead of symbolic host, port or usernames.

-H type, –hw-type type, -t type: This tells arp which class of entries it should check for. Default value
is ether. List of possible hardware types(which support ARP) are ash(Ash), ether(Ethernet),
ax25(AMPR AX.25), netrom (AMPR NET/ROM), rose (AMPR ROSE), arcnet (ARCnet), dlci (Frame
Relay DLCI), fddi (Fiber Distributed Data Interface), hippi (HIPPI), irda (IrLAP), x25 (generic X.25),
eui64 (Generic EUI-64).

-e: Shows the entries in default(Linux) Style.

-i If, –device If: Select an interface. When dumping the ARP cache, only entries matching the
specified interface will be printed. Note: This has to be different from the interface to which the IP
datagrams will be routed.

-s hostename hw_address: Manually create an ARP address mapping entry for the host hostname
with its mac address as hw_address.
8. dig

dig (stands for domain information groper) is a tool used to perform DNS
lookups in Linux. It is known for its flexibility, ease of use and the clarity of its
output. dig performs more complex DNS lookups than the host command and
displays more detailed information.

To display only the Answer section, use the +noall and +answer options:

To display all DNS record types, use the -t any option:


To perform a DNS reverse look up, use the -x option:
9. netstat

Netstat command displays various network related information such as network


connections, routing tables, interface statistics, masquerade connections, multicast
memberships etc.,

Examples of some practical netstat command :


1. -a -all : Show both listening and non-listening sockets. With the –
interfaces option, show interfaces that are not up
# netstat -a | more : To show both listening and
non-listening sockets.
1. List all tcp ports.

# netstat -at : To list all tcp ports.


Computer Network Lab Manual BTech IT(Sem: V)

2. List all udp ports.


# netstat -au : To list all udp ports.

10.nslookup
Nslookup (stands for “Name Server Lookup”) is a useful command for getting
information from DNS server. It is a network administration tool for querying the
Domain Name System (DNS) to obtain domain name or IP address mapping or any
other specific DNS record. It is also used to troubleshoot DNS related problems.

Syntax:
nslookup [option]

Mukesh Patel School of Technology Management and Engineering Page 29


Computer Network Lab Manual BTech IT(Sem: V)

11.route

Route command is used to show/manipulate the IP routing table. It is


primarily used to setup static routes to specific host or networks via an
interface.

12.cat /etc/resolv.conf

Mukesh Patel School of Technology Management and Engineering Page 30


Computer Network Lab Manual BTech IT(Sem: V)

conf is resolver configuration file for Linux and UNIX like operating systems.
It is used to configure dns name servers. The file /etc/resolv. conf file
contains information that is read by the resolver routines the first time they
are invoked by a process.

13.cat /etc/services | grep ssh(ftp/snmp/nfs/http)

The grep filter searches a file for a particular pattern of


characters, and displays all lines that contain that
pattern. The pattern that is searched in the file is
referred to as the regular expression (grep stands for
globally search for regular expression and print out).
Syntax:
grep [options] pattern [files]

Options Description

-c : This prints only a count of the lines that match a pattern

-h : Display the matched lines, but do not display the filenames.

Mukesh Patel School of Technology Management and Engineering Page 31


Computer Network Lab Manual BTech IT(Sem: V)

-i : Ignores, case for matching

-l : Displays list of a filenames only.

-n : Display the matched lines and their line numbers.

-v : This prints out all the lines that do not matches the pattern

-e exp : Specifies expression with this option. Can use multiple


times.

-f file : Takes patterns from file, one per line.

-E : Treats pattern as an extended regular expression (ERE)

-w : Match whole word

-o : Print only the matched parts of


a matching line, with each such part
on a separate output line.

14. New Networking command identified by student

w:
prints a summary of the current activity on the system, including what each user is
doing, and their processes.
Also list the logged in users and system load average for the past 1, 5, and 15 minutes.

B.2 Observations and learning:


 Able to understand and execute each networking command.
 Able to understand the output of each networking command.

B.3 Conclusion:
We executed the Linux networking commands and have achieved the Lab
objectives.

B.4 Question of Curiosity

1. What is the use of /etc/hosts file?


Ans- conf is resolver configuration file for Linux and UNIX like operating
systems. It is used to configure dns name servers. The file /etc/resolv. conf
file contains information that is read by the resolver routines the first time
they are invoked by a process.

2. What is the command to check all the open ports of your machine?
Mukesh Patel School of Technology Management and Engineering Page 32
Computer Network Lab Manual BTech IT(Sem: V)

Ans- To find open ports on a computer, use netstat command line. To display
all open ports, open DOS command, type netstat and press Enter. To list
all listening ports, use netstat -an |find /i "listening" command.

3. Mention all the network configuration files you would check to


configure your Ethernet card.
Ans- /etc/sysconfig/network-scripts/ifcfg-eth*
/etc/sysconfig/network
/etc/resolv.conf
/etc/nsswitch.conf

4. What is loop-back interface?


Ans- A loopback interface is a logical, virtual interface in a Cisco Router. A
loopback interface is not a physical interface like Fast Ethernet
interface or Gigabit Ethernet interface. ... By default, router doesn't
have any loopback interfaces (loopback interfaces are not enabled by
default), but they can easily be created.

Mukesh Patel School of Technology Management and Engineering Page 33

You might also like