You are on page 1of 7

BITS-Pilani Hyderabad Campus

CS F303 (Computer Networks) Laboratory 1

AIM:
• To understand and use various network commands.
• To know various network elements.
Note:
• To see more details about a command, type man <command_name> or
<command_name> -h
• The screenshots values may (not) match with the paragraph contents. You may get
different set of values.
• Things written in [] such as [...options] are optional but the things written in <> such
as <interface> are mandetory for any command.

Network Commands: Networking is a very important part of any computer system.


Isolated computers (those which are not connected to the internet/intranet) may not be
very useful. The above characteristics are very similar to a community and a single person
in isolation.

Following are a few commands to understand a network and diagnose it for possible
network issues.

1. Ifconfig [...options] [interface]: ifconfig utility is used to configure and understand


the networks interface and their parameters. Mostly we use this command to check
the IP address assigned to the interfaces. We can also identify the interfaces

Figure 1: Output of ifconfig


available on the system. There are two different interfaces that are shown in Figure
1, enp2s0 and lo. Lets take a closer look at the output fields of the ifconfig
command.
• Link encap:Ethernet - This denotes that the interface is an Ethernet related
device.
• HWaddr 48:4d:7e:cf:f6:38 - This is the hardware address or MAC address
which is unique to each Ethernet card which is manufactured. Usually, the
first half part of this address will contain the manufacturer code which is
common for all the Ethernet cards manufactured by the same manufacturer
and the rest will denote the device Id which should not be the same for any
two devices manufactured at the same place.
• inet addr - indicates the machine IP address.
• Bcast - denotes the broadcast address.
• Mask - is the network mask which we passed using the netmask option (see
above).
• UP - This flag indicates that the kernel modules related to the Ethernet
interface has been loaded.
• BROADCAST - Denotes that the Ethernet device supports broadcasting - a
necessary characteristic to obtain IP address via DHCP.
• NOTRAILERS - indicate that trailer encapsulation is disabled. Linux usually
ignore trailer encapsulation so this value has no effect at all.
• RUNNING - The interface is ready to accept data.
• MULTICAST - This indicates that the Ethernet interface supports
multicasting. Multicasting can be best understood by relating to a radio
station. Multiple devices can capture the same signal from the radio station
but if and only if they tune to a particular frequency. Multicast allows a source
to send a packet(s) to multiple machines as long as the machines are
watching out for that packet.
• MTU - short form for Maximum Transmission Unit is the size of each packet
received by the Ethernet card. The value of MTU for all Ethernet devices by
default is set to 1500. Though you can change the value by passing the
necessary option to the ifconfig command. Setting this to a higher value
could hazard packet fragmentation or buffer overflows. Do compare the MTU
value of your Ethernet device and the loopback device and see if they are
same or different. Usually, the loopback device will have a larger packet
length.
• Metric - This option can take a value of 0,1,2,3... with the lower the value the
more leverage it has. The value of this property decides the priority of the
device. This parameter has significance only while routing packets. For
example, if you have two Ethernet cards and you want to forcibly make your
machine use one card over the other in sending the data. Then you can set
the Metric value of the Ethernet card which you favor lower than that of the
other Ethernet card. I am told that in Linux, setting this value using ifconfig
has no effect on the priority of the card being chosen as Linux uses the
Metric value in its routing table to decide the priority.
• RX Packets, TX Packets - The next two lines show the total number of
packets received and transmitted respectively. As you can see in the output,
the total errors are 0, no packets are dropped and there are no overruns. If
you find the errors or dropped value greater than zero, then it could mean
that the Ethernet device is failing or there is some congestion in your
network.
• collisions - The value of this field should ideally be 0. If it has a value greater
than 0, it could mean that the packets are colliding while traversing your
network - a sure sign of network congestion.
• txqueuelen - This denotes the length of the transmit queue of the device. You
usually set it to smaller values for slower devices with a high latency such as
modem links and ISDN.
• RX Bytes, TX Bytes - These indicate the total amount of data that has
passed through the Ethernet interface either way.
• Interrupt - From the data, I come to know that my network interface card is
using the interrupt number 9. This is usually set by the system.

The values of almost all the options listed above can be modified using the requisite
ifconfig options.
If we run ifconfig with argument -a, it displays the status of all interfaces, even those that
are down.
Questions:
Write a command that can change the IP address of the system, verify the same and
change it back to the previous value.
How will you enable or disable a particular interface?
2. ping [...options] <destionation>: It stands for Packet InterNet Groper), is the most
commonly used tool for troubleshooting a network. It is used to test the ability of
your computer to reach a specified destination computer. The ping command is
usually used as a simple way to verify that a computer can communicate with
another computer over the network. It also outputs some information about the
network performance, e.g. the round trip time time (the time from the packet
transmission to reception).

Figure 2: Output of ping command.

Figure 2 depicts that a correctly-formed ping packet is typically 56 bytes in size, or 64 bytes
when the Internet Protocol(IP) header is considered.
Questions:
How frequently ping sends a packet? Change its value?
Write a command to change the default packet size of the ping packet?
Write a command to send only 5 packets to the destination.

Figure 3: Output of ifplugstatus


3. ifplugstatus [options] [interface]: The ifplugstatus command will tell you whether
a cable is plugged into a network interface or not. It isn’t installed by default on
Ubuntu. Use the following command to install it: sudo apt-get install ifplugd
4. arp: displays and modifies entries in the Address Resolution Protocol (ARP) cache,
which contains one or more tables that are used to store IP addresses and their
resolved Ethernet or Token Ring physical addresses. There is a separate table for
each Ethernet or Token Ring network adapter installed on your computer. Used
without parameters, arp displays help.
-a display (all) hosts in alternative (BSD) style
-s, --set set a new ARP entry
-d, --delete delete a specified entry
-v, --verbose be verbose
-n, --numeric don't resolve names
-i, --device specify network interface (e.g. eth0)
-D, --use-device read <hwaddr> from given device
-A, -p, --protocol specify protocol family
-f, --file read new entries from file or from /etc/ethers

Figure 4: Output of arp -a

5. You can use the arp command to view and modify the ARP table entries on the
local computer. This may display all the known connections on your local aream
network segment (if they have been active and in the cache). The arp command is
useful for viewing the ARP cache and resolving address resolution problems.
6. traceroute [...options] <destination>: traceroute print the route packets take to
the network host. By default the number of hops are limited to 30.
After the first line, each subsequent line represents a "hop", or intermediate host
that your traffic must pass through to reach the computer represented by the host
you specified. Each line has the following information:
• hop_number: A sequential count of the number of degrees of separation the
host is from your computer. Traffic from hosts with higher numbers have to go
through more computers to get routed.
• host_name: This field contains the result of a reverse DNS lookup on the
host's IP address, if available. If no information is returned from the reverse
DNS query, the IP address itself is given.
• IP_address: This field contains the IP address for this network hop.
• packetroundtrip_times: The remainder of the line gives the round-trip times
for a packet to the host and back again. By default, three packets are sent to
each host and each attempt is appended to the end of the line.

Figure 5: Output of traceroute


If a packet is not acknowledged from a host within the expected timeout, an
asterisk is displayed.
7. nslookup [...option] [name | -] [server]: nslookup is a program to query Internet
domain name servers and can troubleshoot DNS related problems.
nslookup www.bits-pilani.ac.in

Figure 1: Output nslookup finding IP Address

8. scp [...option] [[user@]host1:]file1 ... [[user@]host2:]file2 It securely copies files


from one host to another. scp by default uses port number 22.
host1, host2 can be IP addesses.
scp user@host:/path/to/source-file /path/to/destination-folder will copy the file
“source-file” (located at /path/to/) of the remote host host to your local directory
(/path/to/destination-folder).
9. netstat [...options]: netstat command lets you print network connections, routing
tables, interface statistics etc of your computer.
Question: Count the TCP ports open on your computer.
Network Elements:
Please note the label on these ethernet ports: the port labeled as Internet is also called as
WAN port which connects the Internet connection. Ports 1 to 4 are labeled as ethernet on
which we connect various devices. The devices connected on these ports can share the
Internet connection.

Figure 6: Router with port labels

Figure 7: PCI LAN card

You might also like