GNU Linux Networking Tutorial
GNU Linux Networking Tutorial
M K Saravanan
Centre for Internet Research
[email protected]
Contents
1 License 2
2 Introduction 2
3 Further Information 2
4 Networking fundamentals 2
4.1 Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
4.2 Origin of Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4.3 Birth of TCP/IP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.4 Packet Switched Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.5 IP Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4.5.1 More about IP Addresses . . . . . . . . . . . . . . . . . . . . . . . . 6
4.6 Domain Name System (DNS) . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.7 TCP/IP Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.8 Network Interface Card (NIC) . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.9 Routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.10 Relation between IP Address and MAC address . . . . . . . . . . . . . . . . 11
4.11 Data Flow from End-to-End . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.12 Note on RFCs/STDs/FYIs/BCPs . . . . . . . . . . . . . . . . . . . . . . . 12
1 License
Copyright c 2002 M K Saravanan
Permission is granted to copy, distribute and/or modify this document under the terms of
the GNU Free Documentation License, Version 1.1 or any later version published by the Free
Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover
Texts. A copy of the license is available at http://www.gnu.org/copyleft/fdl.txt.
2 Introduction
This tutorial assumes that you already know the basics of GNU/Linux. It won’t teach
you the basic things like editing a file, cp, rm, etc. . . Throughout the tutorial we will
assume Redhat 7.2 distribution though the commands are similar in other distribution.
This tutorial will teach you only the very minimum basics of networking. I will try to
update this guide whenever i get free time. You can download the latest copy of this
tutorial at http://mksarav.tripod.com.
3 Further Information
A large number of tutorials are available for GNU/Linux on all possible topics. Kindly do
a GNU/Linux google search at http://www.google.com/linux. To start with you can go
through the following HOWTOs:
• LINUX: Rute User’s Tutorial and Exposition by Paul Sheer
http://rute.sourceforge.net
• DOS-Win-to-Linux-HOWTO
• Unix-and-Internet-Fundamentals-HOWTO
• Networking-Overview-HOWTO
You can download all the HOWTOs and mini-HOWTOs from http://www.linuxdoc.
org. Most of the time the answer for the question you are asking will be available by doing
a google search at http://groups.google.com. Please don’t expect spoon-feeding. Be
prepared to go through man pages first whenever you are in doubt.
4 Networking fundamentals
4.1 Protocols
If you want to share the resources available in various computers (hardware as well as
software), then through some means we can connect all of them and make use of the
4.2 Origin of Internet 4
available resources with each other. We call the interconnection of all these computers as
a Network. To connect two computer with each other, first they should understand what
the other computer is saying. Say, if you talk in chinese and the opposite guy in Russian,
then both of you won’t understand what each other is saying. To solve this problem say
both of you are following a rule: each should employ a translator whose common language
is english. Then you can establish communication with each other like:
Chinese Russian
Chinese→English English→Russian
(Translator) (Translator)
Since you followed a rule here, both of you are now able to communicate. Here the rule
is: Employ a translator whose common language is english. In networking terminology, a
set of rules is often called a PROTOCOL. Thus if both of you follow a common protocol,
you can establish communication with each other. This is what happening in a computer
network. Thus to establish communication with two computers, both of them must follow
a common protocol.
UNIX WIN-XP
TCP/IP TCP/IP
Slowly TCP/IP became the de-facto standard for Internet Communications. Nowa-
days almost all the Intranet also started using TCP/IP. But remember TCP/IP is not the
only protocol available for networking. Several other protocols like IPX/SPX, AppleTalk
Protocol, etc. . . are also in use.
If you install TCP/IP in all the computers then you can establish communication with
each other by properly configuring each of them. GNU/Linux comes with inbuilt TCP/IP
support in the kernel. So you don’t have to do anything special to install TCP/IP.
4.5 IP Addressing
To uniquely identify a computer in a network, a new addressing scheme was introduced
called “IP Addressing”. According to this, each computer will be identified by a unique
IP address made up of 32 bits. For simplicity, it is usually written in “Dotted Decimal
Notation” where each octet in the IP address will be written in decimal form. For e.g.
11001010 00110110 00000110 00010100 is written as 202.54.6.20
IP Addresses are classified as follows:
x - can be either 0 or 1
# - constitute Net Id.
% - constitute Host Id.
The different classes of IP addresses are discriminated by their MSB bits. Out of these,
Class-E is reserved for future use and Class-D is meant for “Multicast Group Ids”. If we
send a packet to all the host in a network, then we will call it as broadcast. Instead if we
send only to a group of host within a network, then it is called multicast.
Each of the Class-A, B, & C addresses are further logically divided into two parts
namely, “Net id.” and “Host id.”. For e.g. consider,
202.54.6.20 - 11001010 00110110 00000110 00010100
since the address starts with MSB 110, it belongs to Class-C. In Class-C the first three
octet with MSBs 110 will form the network id. and the last octet is the host id. Therefore
the net id is: 202.54.6 and 20 is the host id.
4.5 IP Addressing 7
Thus, we are actually having < 232 IP Addr. Further Class-E addr. are reserved for
future use and Class-D is meant for “Multicast Group Ids.”. Therefore for any practical
usage we are left with Class-A, B and C IP Address space. After the introduction of World
Wide Web (WWW) in 1990’s by Tim Berners Lee, the growth rate of number of hosts on
Internet started becoming exponential. Unfortunately the IPv4 address classification are
not planned appropriately to tackle the enormous growth rate of various capacity networks
on Internet.
To understand the Net id., consider a University Network. If it want to put a server in
each dept. and connect all the departments with Internet, it may easily need 150 to 200
IP addresses approximately. Instead of getting individual IP addr. eachtime we introduce
a new server, it is good to get a Class-C (the nearest match) Net Id. like 202.54.7.0.
For a given Class-C net id. you can connect a maximum of 254 hosts. For e.g. let us
take 202.54.7.0 - Class-C Network Id. (imaginary) representing the Univ. N/W. To this
network, now we can connect a max.of 254 hosts with IP addr. from:
202.54.7.1 to 202.54.7.254
All one’s (binary) in the host portion of a Net Id. is a special IP address called “Net
Directed BROADCAST IP Address”. Thus in our case, 202.54.7.255 is the Broadcast IP
Addr. for the Univ. N/W. Any packet with this IP addr. as destination will reach all the
hosts in the Univ. N/W (Hence the name Broadcast).
Given an IP address, to extract the network id. from it, “netmask” are used. For e.g.
to extract the net id. portion from a Class C address, say 202.54.6.20, we need to do a
binary AND operation with the first 24 most significant bits. Remember in Class-C, the
first 24 MSBs will form the network id. Let us work out an example.
4.6 Domain Name System (DNS) 8
To obtain the netmask for a given IP address, count the number of bits which forms
the network id.. Then netmask can be obtained by writing that many number of binary
ones starting from the first MSB and leaving the remaining bits as binary zeroes.
Due to the exponential growth of Internet, IP addresses started exhausting drastically.
Within few years from now, we don’t have any more addresses available in IPv4. To solve
this problem, the Internet Engineering Task Force (IETF) came up with a new version of
Internet Protocol called IPv6. IPv6 addresses are 128 bits wide and won’t be exhausted in
the foreseeable future. The transition to IPv6 will take considerable amount of time and
will happen slowly. Several mechanism are being proposed for IPv4 & IPv6 interoperability
till the whole world changes to IPv6. In the mean time, to prevent the quick exhaustion
of IPv4 addresses, IP subnetting and CIDR (ClassLess Inter Domain Routing) techniques
are introduced.
IP addresses are globally unique. That means, no two host on the Internet will have
the same IP address. But in real life, we may need to have private networks within the
organisation. Depending upon the organisation policy, these private network may or may
not be merged with the Internet in the future. In IPv4, it is not possible to assign a unique
IP address to each and every host on the Planet. Thus the following network ids. are
reserved for private networking purpose.
Anybody can use the above addresses, to setup their own private networks. On Internet
you will never find these IP addresses; if you – then your router is not configured properly.
IP Addr. follows Left to Right hierarchy whereas the DN follows Right to Left hierarchy.
The Domain Names can be made up of two or more words separated by dot. e.g. domain
names are:
www.mitindia.edu
www.comp.nus.edu.sg
ftp.gnu.org
chn.vsnl.net.in
For Administrative and maintenance purposes, a set of Top Level Domains (TLD) were
introduced.
/ (root)
|
|-----|-----|------|-----|------|-------|------|-----------|----------|
.com .net .org .mil .gov .int .edu .arpa (countrywise)
| .in
| .jp
| .de
| (etc.)
Organisational Classification
=============================
Countrywise Classification
===========================
.in - India
.jp - Japan
.de - Germany
4.7 TCP/IP Layers 10
.ru - Russia
.sg - Singapore
.my - Malaysia
etc..,
It is the job of the Network Administrator to maintain a server called DNS server in
each network. The DNS server will maintain a table of Domain Name & IP Address Pairs of
all the hosts in that network. Normally the ISPs (Internet Service Provider) will maintain
atleast two DNS servers namely Primary and Secondary (for backup purpose). DNS as a
whole is a distributed database. No single host on the Internet will maintain the DN, IP
Address pairs of all hosts exists on the Internet.
==============================================================================
7 Layer - OSI Model 4 Layer - TCP/IP Model
==============================================================================
(7) * Application Layer * Application Layer
(6) * Presentation Layer "
(5) * Session Layer "
(4) * Transport Layer * Transport Layer
(3) * Network Layer * Network Layer
(2) * Data Link Layer * Link Layer
(1) * Physical Layer "
==============================================================================
The logical structure of the TCP/IP layers can be represented as shown in the figure.
This figure was taken from RFC#1180 and slightly modified to include ICMP and IGMP.
----------------------------
| network applications |
| |
|... \ | / .. \ | / ...|
| ----- ----- |
| |TCP| |UDP| |
| ----- ----- |
| \ / |
| -------- |
| (ICMP)-| IP |-(IGMP) |
| ----- -*------ |
| |ARP| | (RARP) |
| ----- | / |
| \ | / |
| -------------- |
| | ETHERNET | |
| ---@---------- |
----------|-----------------
|
----------------------o---------
Ethernet Cable
ACRONYMS USED:
==============
Examples:
and is used by the vast majority of LANs. Thus the NIC that uses Ethernet is commonly
called as Ethernet Card. Each ethernet card comes with its own address called “Hardware
Address or MAC Address” which consists of 6 bytes (48 bits) represented in Hexa Colon
Notation. Here is an e.g. of a MAC address:
00:E0:00:5A:D1:2A
4.9 Routing
If you want to connect your host to more than one network – say, three network, then you
will need three ethernet card to connect to the three networks. Thus, a host may contain
more than one ethernet card. Such a host is called a “multi-homed” host. Sometimes, you
want to pass data from one network to another network. For such a situation, you can
use a multi-homed host by configuring the host to forward data between a pair of ethernet
cards. Such a host is called a Router. Thus all routers are essentially a multihomed host
but the reverse may not be true.
In a network, to reach a particular destination, there may be more than one path. To
find out the optimum path, routers may use “Routing Algorithms”. In a small network
where the network topology rarely change, we can use fixed (static) routes. But for a large
network, we need to use dynamic routing algorithms to update the routing table as soon
as the route changes are detected.
{Source IP Address, Source Port Number, Destn. IP Address, Destn. Port Number}
(IP Address, Port Number) pair is also called as SOCKET. Thus each TCP connection
can be uniquely identified by two sockets: source socket and destination socket. Remember
a SOCKET identifies one end of a TCP connection.
IP may receive data from one or more sources like TCP, UDP, ICMP, IGMP etc. . .
To distinguish each one of them it uses a unique number called protocol number [8-bit
protocol field in the IP Header]. In Unix machine you can find the protocol numbers in
/etc/protocols file. For e.g. the value of protocol number for TCP is 6 and that of UDP
is 17.
Ethernet may receive data from one or more sources like IP, ARP, RARP etc. . . To
distinguish each one of them it uses a unique number called frame type [16-bit frame type
field in Ethernet Header].
Thus, at the remote end, the Ethernet receive the frame, check its frame type and
demultiplex the datagram to either IP/ARP/RARP. If IP receives the datagram, based
on the 8-bit protocol field, it demultiplex the data to either TCP/UDP/ICMP/IGMP. If
TCP receives the data, based on the 16-bit port number, it demultiplex the data to the
corresponding application.
ICMP, IGMP make use of IP Datagram Delivery Service & ARP, RARP make use of
Ethernet for sending ARP/RARP packets. Thus IP may receive data from TCP/UDP/ICMP/IGMP
(other sources are also possible, but that is not important here).
GNU/Linux supports a wide variety of Ethernet Cards. If you have the Ethernet Card
in your computer, most distribution will automatically detect it during installation and
include the appropriate driver modules. We just need to configure the ethernet cards with
appropriate IP addresses. The ethernet card will be automatically assigned the device name
“eth0” by the kernel. If you have more than one ethernet card in a host, then the remaining
will be assigned with the device name eth1, eth2, etc. . . respectively. Whether you have
ethernet card or not, by default all the host will be configured for local loopback interface.
There is no any real hardware associated with loopback device. It is just a software in-
terface. Those who don’t have real network interface card, can make use of this software
loopback interface. The kernel will assign the device name “lo” for this interface. By de-
fault all the GNU/Linux distribution will configure the local loopback interface with the
IP address 127.0.0.1. Theoretically you can use any of the 127.x.x.x. To view/modify the
configuration of an interface we can use the “ifconfig” command. First do a “man ifconfig”.
bash-2.05# ifconfig lo
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
We can find out whether a interface is alive or not by using the “ping” command. It will
send ICMP ECHO REQUEST message to the destination host. If the destination host is
alive, it will respond with an ICMP ECHO REPLY message. Upon receiving the response
from the destination host, ping will print the round trip time.
The option -c1 tells the ping command to send just one ICMP ECHO REQUEST
message.
Let us give the name feynman1 and ramanujan2 to our host respectively. Using the
“hostname” command, you can set/view the hostname.
1
Feynman is a Nobel Laurette in Quantum Electrodynamics. Feynman lectures in Physics are world
famous
2
Ramanujan is a great Indian mathematician and considered as a genius in number theory.
5 Setting up a small network 15
To distinguish both the host, let us change the command prompt to reflect the username
and hostname. The command prompt is stored under the environment variable name PS1
(“man bash” for more details). Here \ u represent username, \ h represent hostname, \ W
represent current working directory.
You execute similar commands in the other host with the hostname “ramanujan”. None
of the settings you did will exist once you reboot the computer. To make the configuration
permanent you need to include the configuration commands in the system startup script.
On Redhat 7.x machines, these scripts are located under the directory /etc/rc.d/. It may
be under different directory in other distributions. At any given time, all UNIX systems
will be in one of the several possible runlevels. Redhat 7.x systems uses the following set
of runlevels:
You can set the default runlevel in the /etc/inittab file. For e.g. the line:
id:3:initdefault:
will set the default runlevel as 3. During bootup, first the system initialisation will be done
using the script in /etc/rc.d/rc.sysinit. Then depending upon the runlevel, several
initialisation scripts will be started by /etc/rc.d/rc with runlevel as argument. You can
change the runlevel at anytime using the init <runlevel>. If you hate doing everything
on command line, you can use the “linuxconf” utility to do most of the settings without
bothering about the various configuration filenames. linuxconf will need root previlege.
Hackers will do everything on command line :-)
We can configure the ethernet cards using “ifconfig”. To run the command you will
need root previlege. So login as root (or use su - ) and type the following command:
The output shows the interface is UP and running. To shutdown a interface you can
use “down” option (e.g. ifconfig eth0 down).
Similarly you can configure the host “ramanujan” with the IP address 192.168.1.2. Now
we can try to ping ramanujan from feynman:
What happenned? We have not yet connected both the hosts physically using a ethernet
cable. You need a piece of CAT-5 UTP (UnTwisted Pair) Ethernet Cable for each host,
crimped on the both ends with a RJ-45 connector. You need one more device called a HUB
(or a switch) to complete the network. A HUB is nothing but a electronic repeater. It will
simply repeat the incoming data from a port to all the other ports. You can find 8-port,
16-port, 24-port hubs in the computer store. Connect one end of the cable to the ethernet
card and other end to one of the ports in the HUB. Repeat the same for the other host.
Now that the circuit is complete, you can ping ramanujan/feynman from each other.
Now add the IP address <TAB> hostname for the hosts ramanujan and feynman in
both the systems.
Also add the following line in the /etc/nsswitch.conf which tells the order the DNS
resolver will try to resolve the hostname (Most probably this line will be already there by
default).
The above line tells the DNS resolver, to look for the file /etc/hosts first and then the
DNS server.
From now onwards, you can simply use the hostname instead of specifying the IP address
in most of the commands. If you have Internet access through a appropriate gateway in your
network, then you need to set the domain name server entries in the file /etc/resolv.conf.
A sample /etc/resolv.conf file will look like:
In the above e.g. the line “nameserver 137.132.90.2” represent the first name server that
the system will use for any DNS query. You can add optional second and third entries if
you want. The line “domain comp.nus.edu.sg” tells you that the example host (hanuman)
belongs to the “comp.nus.edu.sg” domain.
e.g.
rpm -e anonftp-4.0-9
To compile a software from the source code (.tar.gz), mostly you will need to perform the
following steps:
[mksarav@feynman mksarav]$ su -
Password:
[root@feynman root]# cd /usr/local/src
[root@feynman src]# tar -zxvf /home/mksarav/download/ipgrab-0.9.8.tar.gz
[root@feynman src]# cd ipgrab-0.9.8/
[root@feynman ipgrab-0.9.8]# ./configure
[root@feynman ipgrab-0.9.8]# make
[root@feynman ipgrab-0.9.8]# make install
Installing and upgrading software packages with out any conflict is an art. For a thor-
ough understanding of various methods of software installation and other details kindly
refer the following HOWTOs:
• Software-Building-HOWTO
• Software-Proj-Mgmt-HOWTO
5.3 Internet Services 19
• Software-Release-Practice-HOWTO
• RPM-for-Unix-HOWTO
• RPM-HOWTO
For the rest of the tutorial we will assume that all the necessary client and server programs
are already installed in the system. We will only explain the basic configuration details.
• SMB Protocol (e.g. Samba - to share files across WIN and GNU/Linux systems)
• finger
• discard
• echo
etc. . . To quickly go through the various possible services have a look at /etc/services
file. However all of the services listed in the file may not be available in your system. The
entries in /etc/services tell you the port number that the particular service will listen
for any incoming connection and the possible protocols (tcp/udp) that can be used.
Most of the network server programs can be run in two modes either as a standalone
program or invoked by the inetd daemon (inetd stands for Internet services daemon). A
daemon is nothing but a process running in the background. In the standalone mode,
the server will be always running in the background and ready to serve for any incoming
connections. In case of inetd, whenever some incoming connections request for a particular
service, it will be lauched by the inetd daemon. In most of the UNIX systems, the inetd
configuration will be in the file /etc/inetd.conf. However in Redhat 7.x systems, it
has been put in a separate directory /etc/xinetd.d (xinetd stands for Extended Internet
services). Here is an excerpt from the xinetd man page:
. . . xinetd performs the same function as inetd: it starts programs that provide Internet
services. Instead of having such servers started at system initialization time, and be dormant
until a connection request arrives, xinetd is the only daemon process started and it listens
5.4 Telnet 20
on all service ports for the services listed in its configuration file. When a request comes in,
xinetd starts the appropriate server. Because of the way it operates, xinetd (as well as inetd)
is also referred to as a super-server. The services listed in xinetd’s configuration file can be
separated into two groups. Services in the first group are called multi-threaded and they
require the forking of a new server process for each new connection request. The new server
then handles that connection. For such services, xinetd keeps listening for new requests
so that it can spawn new servers. On the other hand, the second group includes services
for which the service daemon is responsible for handling all new connection requests. Such
services are called single-threaded and xinetd will stop handling new requests for them
until the server dies. Services in this group are usually datagram-based. So far, the only
reason for the existence of a super-server was to conserve system resources by avoiding to
fork a lot of processes which might be dormant for most of their lifetime. While fulfilling
this function, xinetd takes advantage of the idea of a super-server to provide features such
as access control and logging. Furthermore, xinetd is not limited to services listed in
/etc/services. Therefore, anybody can use xinetd to start special-purpose servers. . . . ”
The /etc/xinetd.conf file will include the scripts in /etc/xinetd.d. You can en-
able/disable a particular service from the configuration file for that service under the di-
rectory /etc/xinetd.d. You can start/stop/restart the xinetd service using the script
/etc/rc.d/init.d/xinetd.
5.4 Telnet
Telnet is the good old protocol, to connect and work in a remote system. To connect to
the remote system, the telnet server must be running on the remote system. To enable the
telnet server you need to change the line
disable = yes
to
disable = no
Now you can telnet to feynman from ramanujan. Follow similar steps in the host
ramanujan to telnet from feynman.
5.5 ssh
Telnet has been in wide spread use for almost two decades now. However, it has a potential
secuirty problem. Both the data and password transmitted over the network are clear
text. That means, any intermediate node on the network can sniff the telnet packets and
crack down your password. To avoid this potential problem, most of the installation started
switching over to the secure shell (ssh) instead of telnet. “ssh” encrypts all traffic (including
passwords) to effectively eliminate eavesdropping, connection hijacking, and other network-
level attacks.
OpenSSH is a FREE version of the SSH protocol suite. Additionally, OpenSSH provides
a myriad of secure tunneling capabilities, as well as a variety of authentication methods.
The OpenSSH suite includes the ssh program which replaces rlogin and telnet, scp which
replaces rcp, and sftp which replaces ftp. Also included is sshd which is the server side of
the package, and the other basic utilities like ssh-add, ssh-agent, ssh-keygen and sftp-server.
OpenSSH supports SSH protocol versions 1.3, 1.5, and 2.0. You can download openssh from
http://www.openssh.org.
You can run “sshd” as a standalone daemon. As a root user start the sshd using
“ssh” comes with lot of other utilities. For more details kindly refer the manual pages.
disable = yes
to
disable = no
scp
Similar to telnet, ftp also send everything including your password as plain text on the
network thus creating a major security problem. Nowadays most of the organisations
started using the “scp” program that comes as a part of “ssh”.
[mksarav@feynman mksarav]$ scp file1.dat mksarav@ramanujan:
mksarav@ramanujan’s password:
file1.dat 100% |*****************************| 3041 00:00
[mksarav@feynman mksarav]$
The above command will copy the file1.dat file in feynman to the host ramanujan under
the home directory of user mksarav. Don’t forget to type the colon at the end.
+---------------------+
| SMB |
+---------------------+
| TCP/IP |
+---------------------+
your domain name. You also need to add an DNS entry either with a commercial DNS
service provider or you can run your own DNS server also. Only then your hostname will
be resolved to the appropriate IP address from any part of the world. Explaining all these
details is beyond the scope of this tutorial.
5.8 Samba
Samba is a set of tools originally written by Andrew Tridgell to share the resources such
as disk and printers between UNIX and Windows hosts. IBM and Sytec developed a
proprietary network system called “PC-Network” to share files between various PCs on a
small LAN. This PC-Network used a small device driver known as NetBIOS (Network Basic
Input/Output System). PC-Network came with its own proprietary hardware later being
replaced by Ethernet. Lots and lots of software was written for use with the NetBIOS API
(Application Programming Interface). Several vendors implemented the NetBIOS API on
top of protocols such as IPX/SPX, and TCP/IP. NetBIOS over TCP/IP is often called NBT
and has become the preferred NetBIOS transport. The workings of NBT are described in
RFC#1001 and RFC#1002 (collectively known as Internet STD#19).
In the early 1980’s, Intel and Microsoft came up with a protocol called SMB (Server
Message Block) which was designed to run PC-Network LAN using the NetBIOS API to
send and receive packets.
+---------------------+
| SMB |
+---------------------+
| NetBIOS |
+---------------------+
| TCP/IP |
+---------------------+
• Session Service
NetBIOS uses a name to identify each host on the network. Remeber NetBIOS names are
nothing to do with Domain Name System and the whole thing happenned much before the
DNS was invented. The NBT Name Service keeps track of which names are in use at which
IP addresses, thus allowing the underlying IP network to find the nodes and transport
NetBIOS messages between them. The Name Service runs on UDP port 137 whereas the
Datagram Service (connectionless) and Session service (connection-oriented) runs on port
138 and 139 respectively.
[mksarav@feynman mksarav]$ grep netbios /etc/services
netbios-ns 137/tcp # NETBIOS Name Service
netbios-ns 137/udp
netbios-dgm 138/tcp # NETBIOS Datagram Service
netbios-dgm 138/udp
netbios-ssn 139/tcp # NETBIOS session service
netbios-ssn 139/udp
[mksarav@feynman mksarav]$
In Windows, NetBIOS Name Service is handled by WINS (Windows Internet Name Ser-
vice). Again don’t confuse this with the DNS. Both are different though the job is similar.
If you sent a query like “Hey, who is the host NEWTON?” – then the WINS server will
send a reply with the corresponding IP address.
Samba is the best known and most popular open source implementation of SMB (CIFS).
Whatever resources like disks, printers etc. . . that you can share with other hosts in the
network are called SMB SHARES. There are four basic things one can do with Samba:
1. Share a GNU/Linux drive with WIN machines.
The whole Samba service is controlled by the settings in the /etc/samba/smb.conf file.
There are too many options that you can use in smb.conf file which can’t be covered in
this tutorial. For this tutorial let us assume, you have WINDOWS in the host ramanujan.
You reboot the host ramanujan into WINDOWS and configure it with the same TCP/IP
settings as it was in GNU/Linux. For simplicity, let us use the same hostname ramanujan
for the WINDOWS computer name. Further you should have installed the Files and
Printer Sharing for Microsoft Networks. You can do this from Control Panel →
Network Connections → Local Area Connections. If you don’t know how to do this,
ask a local WINDOWS Guru.
If there is no file called /etc/smbpasswd initially then touch /etc/smbpasswd will create
a empty file. The command smbadduser mksarav:mksarav tells the mapping between the
username in /etc/passwd and Samba username. Here we want to use the same username in
both. Since we have changed the configuration details, we have to restart the smbd daemon.
5.8 Samba 27
Samba package comes with its own set of utilities like smbclient, smbstatus, smbpasswd,
smbprint, smbmount, smbumount etc. . . to access SMB/CIFS resources on servers. smbclient
is a ftp-like client to access SMB/CIFS resources. Let us first check whether we are able
to access the home directories in the host feynman, using smbclient. i.e. we are essentially
testing Samba from the same host.
Server Comment
--------- -------
FEYNMAN Samba 2.2.1a
Workgroup Master
--------- -------
MKS FEYNMAN
[mksarav@feynman mksarav]$
The -L option allows you to look at what services are available on a server. When it ask for
password just press enter. The output shows there is a SHARE called “homes” available
on this server. Let’s see whether we are able to access this share.
The -U option tells the SMB username. The SMB service name is specified with //NetBIOS
hostname/SMB share name. Here the NetBIOS hostname of the system is feynman and
the SMB share name is homes. The smb: \> interface will exactly look like ftp interface
and you can get/put the files from/to the mksarav home directory. So far we have been
testing everything from the same host.
Let us see what WINDOWS Network Neighbourhood (or from My Network places)
shows. Remember you should have enabled the settings NetBIOS over TCP/IP in the
TCP/IP properties of the host ramanujan (now booted with WINDOWS). The Network
Neighbourhood will now show a workgroup called “Mks”. If you double click it, it will show
something like:
If you double click Feynman, then it will prompt you for a username/password. Here i have
login with my username “mksarav” (smbusername) and my password (smbpassword). Now
you will see something like:
homes
mksarav
Printers and Faxes
Here both the shares homes and mksarav represent the home directory of the user mksarav
in the host feynman. Now you can do anything with this share just like another windows
folder.
Alternatively, you can also access the SMB service directly from the Internet Explorer
browser by typing \\computername\sharename.
Server Comment
--------- -------
RAMANUJAN
Workgroup Master
--------- -------
MKS FEYNMAN
WORKGROUP RAMANUJAN
[mksarav@feynman mksarav]$
[mksarav@feynman mksarav]$ smbclient //ramanujan/mp3 -U Administrator
added interface ip=192.168.1.1 bcast=192.168.1.255 nmask=255.255.255.0
Got a positive name query response from 192.168.1.2 ( 192.168.1.2 )
Password:
Domain=[WORKGROUP] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
smb: \> ls
. D 0 Thu Feb 14 21:44:12 2002
.. D 0 Thu Feb 14 21:44:12 2002
Collections D 0 Thu Feb 14 21:51:40 2002
new D 0 Wed Feb 20 23:24:02 2002
[homes]
guest ok = no
read only = no
6.1 ping
The most commonly used utility to find out whether a host is alive or not is the “ping”.
We saw how to do this in Sec.5 on page 12. Some of the useful option with ping are:
-R This option will set the RECORD ROUTE option in the ECHO REQUEST packet.
When you use this option it will show the IP addresses of the intermediate routers that
the packet is traversing. Since all these extra details are stored in the IP optional
header space, at the maximum it can display only nine such routes. You can use
traceroute instead of this.
-s Specifies the number of data bytes to be sent. The default is 56. Thus the size of the
outgoing IP packet will be 20 (IP header) + 8 (ICMP header) + 56 = 84 data bytes.
-f Flood ping. Outputs packets as fast as they come back or one hundred times per second,
whichever is more. This option will be very much useful for doing some performance
measurements. For every ECHO REQUEST sent a period “.” is printed, while for
every ECHO REPLY received a backspace is printed. This provides a rapid display
of how many packets are being dropped. Only the super-user may use this option.
This will create excessive traffic on a network and should be used with caution.
Go through the man pages for more details and some of the pitfalls of ping.
6.2 tcpdump
If you want to see how the real packets will look like on the network, then tcpdump is your
friend. It prints out the headers of packets on a network interface. You can specify which
packets you want to see. A variety of boolean expression can be mentioned to filter and
6.3 ipgrab 31
see particular types of packets. The most commonly used option is -i to tell tcpdump to
capture the packets from that particular interface. Let us ping ramanujan from feynman
and see the tcpdump output. In one of the console you run the tcpdump -i eth0 icmp
command as root and from other console you do ping -c1 ramanujan.
The icmp option above will tell tcpdump to show only the ICMP packets.
Some of the useful options are:
-s With this option you can specify a particular number of bytes of data to be collected
from each packet rather than the default of 68.
-w You have to mention a file name so that the raw packets will be written to that file
rather than parsing and printing them out on the console. They can be later printed
with the -r option.
Don’t underestimate the use of tcpdump. You can do a variety of troubleshooting using
it. W. Richard Stevens has used this tool extensively for his book TCP/IP Illustrated
- Vol.I.
6.3 ipgrab
ipgrab is similar to tcpdump but much more user friendly. It will print out the packet head-
ers in plain ASCII output if you want. Here is the “ipgrab” output of the ping -c1 feynman:
ipgrab 0.9.8
Listening on device eth0 (ethernet)
**************************************************************************
Ethernet (1014193584.000364)
--------------------------------------------------------------------------
Hardware source: 00:60:97:db:8d:96
Hardware destination: 00:90:27:90:e6:6b
Type / Length: 0x800 (IP)
Media length: 98
--------------------------------------------------------------------------
6.3 ipgrab 32
IP Header
--------------------------------------------------------------------------
Version: 4
Header length: 5 (20 bytes)
TOS: 0x00
Total length: 84
Identification: 0
Fragmentation offset: 0
Unused bit: 0
Don’t fragment bit: 1
More fragments bit: 0
Time to live: 64
Protocol: 1 (ICMP)
Header checksum: 46681
Source address: 192.168.1.2
Destination address: 192.168.1.1
--------------------------------------------------------------------------
ICMP Header
--------------------------------------------------------------------------
Type: 8 (echo request)
Code: 0
Checksum: 51972
Identifier: 23832
Sequence number: 0
**************************************************************************
Ethernet (1014193584.000527)
--------------------------------------------------------------------------
Hardware source: 00:90:27:90:e6:6b
Hardware destination: 00:60:97:db:8d:96
Type / Length: 0x800 (IP)
Media length: 98
--------------------------------------------------------------------------
IP Header
--------------------------------------------------------------------------
Version: 4
Header length: 5 (20 bytes)
TOS: 0x00
Total length: 84
Identification: 24552
Fragmentation offset: 0
Unused bit: 0
Don’t fragment bit: 0
More fragments bit: 0
Time to live: 255
6.4 netstat 33
Protocol: 1 (ICMP)
Header checksum: 55152
Source address: 192.168.1.1
Destination address: 192.168.1.2
--------------------------------------------------------------------------
ICMP Header
--------------------------------------------------------------------------
Type: 0 (echo reply)
Code: 0
Checksum: 54020
Identifier: 23832
Sequence number: 0
6 packets received
0 packets dropped by kernel
ARP: 0
IP: 2
ICMP: 2
IGMP: 0
UDP: 0
TCP: 0
IPX: 0
GRE: 0
IPv6: 0
ICMPv6: 0
OSPF: 0
RSVP: 0
AH: 0
ESP: 0
6.4 netstat
netstat will print network connection details, routing tables, interface statistics, and other
details. You will appreciate the output of netstat if you know how the TCP/IP protocols
work.
6.5 traceroute
Using the ping -R option you can’t see much about the routes that a packet traverse
to reach the destionation host. However traceroute will provide you the details of each
6.6 tracepath 34
intermediate router that the packet traverse. However the packet need not has to go through
the same route each time.
[mksarav@hanuman mksarav]$ /usr/sbin/traceroute mksarav.tripod.com
traceroute to mksarav.tripod.com (209.202.196.70), 30 hops max, 38 byte packets
1 gw6509a-81a.comp.nus.edu.sg (137.132.81.6) 0.571 ms 0.474 ms 0.435 ms
2 115-19.priv.nus.edu.sg (172.18.115.19) 0.668 ms 0.696 ms 0.640 ms
3 core-pgp-vlan143.priv.nus.edu.sg (172.18.20.129) 0.711 ms 0.739 ms 0.703 ms
4 core-cc-vlan21.priv.nus.edu.sg (172.18.20.5) 0.735 ms 0.685 ms 0.651 ms
5 svrfrm1-cc-vlan165.priv.nus.edu.sg (172.18.20.90) 0.993 ms 0.786 ms 0.808 ms
6 gk-pix-f1-821.nus.edu.sg (137.132.3.130) 2.383 ms 3.507 ms 5.626 ms
7 165.21.48.101 (165.21.48.101) 178.774 ms 175.404 ms 184.515 ms
8 GE-1-1-0.bedok.singnet.com.sg (165.21.12.1) 183.482 ms 185.186 ms 185.768 ms
9 POS2-0.tp-core1.ix.singtel.com (202.160.250.53) 176.590 ms 178.955 ms 184.295 ms
10 POS0-1.above-core1.ix.singtel.com (202.160.250.34) 368.292 ms 363.799 ms 385.227 ms
11 POS2-0.paix-core1.ix.singtel.com (202.160.250.46) 379.003 ms 375.040 ms 377.120 ms
12 paix.exodus.net (198.32.176.15) 364.584 ms 374.864 ms 370.863 ms
13 bbr02-p3-0.sntc08.exodus.net (209.185.9.233) 383.027 ms 378.060 ms 376.887 ms
14 bbr01-p8-0.sntc04.exodus.net (206.79.9.186) 374.507 ms 369.439 ms 372.050 ms
15 bbr01-p1-0.ftwo01.exodus.net (209.185.9.110) 421.193 ms 417.206 ms 416.456 ms
16 bbr02-p3-0.ekgv01.exodus.net (206.79.9.54) 447.018 ms 437.996 ms 436.417 ms
17 bbr01-p2-0.okbr01.exodus.net (206.79.9.129) 433.585 ms 421.279 ms 436.054 ms
18 bbr02-p6-0.wlhm01.exodus.net (209.185.9.118) 448.084 ms 443.928 ms 442.889 ms
19 dcr03-g1-0.wlhm01.exodus.net (64.14.70.49) 451.590 ms 450.102 ms *
20 csr02-ve243.wlhm01.exodus.net (64.14.70.26) 447.934 ms * 455.011 ms
21 209.67.242.86 (209.67.242.86) 451.882 ms !X 447.694 ms !X 446.326 ms !X
[mksarav@hanuman mksarav]$
Find out from the man traceroute what the !X in the output means.
6.6 tracepath
tracepath traces path to a destination host discovering MTU (Maximum Transmission
Unit) along the path. This will help you to identify the bottleneck link in the path to a
destination.
[mksarav@hanuman mksarav]$ /usr/sbin/tracepath www.bbc.co.uk
1?: [LOCALHOST] pmtu 1500
1: gw6509a-81a.comp.nus.edu.sg (137.132.81.6) 2.072ms
2: 115-19.priv.nus.edu.sg (172.18.115.19) 2.282ms
3: core-pgp-vlan143.priv.nus.edu.sg (172.18.20.129) 2.384ms
4: core-cc-vlan21.priv.nus.edu.sg (172.18.20.5) 2.392ms
5: svrfrm1-cc-vlan165.priv.nus.edu.sg (172.18.20.90) 2.394ms
6: gk-pix-f1-821.nus.edu.sg (137.132.3.130) 5.078ms
7: 165.21.48.101 (165.21.48.101) 181.171ms
8: GE-1-1-0.bedok.singnet.com.sg (165.21.12.1) asymm 9 173.820ms
9: POS2-0.tp-core1.ix.singtel.com (202.160.250.53) 174.541ms
10: POS1-0.tp-core2.ix.singtel.com (202.160.250.150) 384.624ms
11: POS2-0.paix-core1.ix.singtel.com (202.160.250.46) 393.607ms
12: 198.32.176.151 (198.32.176.151) 392.192ms
7 Before THE END 35
The above output shows that you can’t send a packet with size > 1500 to reach the desti-
nation. If you exceed this limit, the IP packet will get fragmented into smaller packet
size (< 1500). Let us see the effect with an example. Using ping -s option let us
first ping the host www.bbc.co.uk with 1472 data bytes (so that the packet size will be
1472+8+20=1500):
[mksarav@hanuman mksarav]$ ping -c2 -s1472 www.bbc.co.uk
PING www.bbc.net.uk (212.58.240.31) from 137.132.81.78 : 1472(1500) bytes of data.
1480 bytes from www1.thny.bbc.co.uk (212.58.240.31): icmp_seq=0 ttl=238 time=457.837 msec
1480 bytes from www1.thny.bbc.co.uk (212.58.240.31): icmp_seq=1 ttl=238 time=456.507 msec
Now let us repeat the experiment with 1473 data bytes (packet size now will be 1473+8+20=1501):
[mksarav@hanuman mksarav]$ ping -c2 -s1473 www.bbc.co.uk
PING www.bbc.net.uk (212.58.240.31) from 137.132.81.78 : 1473(1501) bytes of data.
Why it shows 100% packet loss? In the IP header there is a bit called “Don’t fragment
bit” to tell the intermediate routers not to fragment the packet. ping sends all the packets
with the “Don’t fragment” bit set in the IP header but unfortunately the first host MTU
is 1500 and it needs to fragment the packet. But ping told not to fragment it. So it will
simply discard the packet.