Professional Documents
Culture Documents
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)
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:
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:
Syntax:
hostname -V
Example:
Note: To set the hostname we can use the command given below:
sudo hostname NEW_HOSTNAME
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.
ping -s 40 -c 5 www.geeksforgeeks.org
ping -c 5 -q www.geeksforgeeks.org
To Timout PING:
To stop pingig after sometime use -w option.
ping -w 3 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
ping -c 5 -p ff www.geeksforgeeks.org
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
Example 1:
host -t ns geeksforgeeks.org
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
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
Syntax:
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
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.
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.
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
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.
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
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.
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.
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.
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]
-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).
-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:
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]
11.route
12.cat /etc/resolv.conf
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.
Options Description
-v : This prints out all the lines that do not matches the pattern
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.3 Conclusion:
We executed the Linux networking commands and have achieved the Lab
objectives.
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.