Linux/UNIX networking

TCP/IP overview

Yovko Lambrev

Free Software Association - Bulgaria

yovko@yovko.net

www.yovko.net

TCP/IP is the language of the Internet.

TCP/IP is the protocol for communication
between computers connected to the Internet.

A computer communication protocol is a description of
the rules computers must follow to communicate with
each other.

You need to understand ranges and protocols as a basic
knowledge.

The OSI, or Open System Interconnection, model defines a

networking framework for implementing protocols in seven

layers. Control is passed from one layer to the next, starting

at the application layer in one station, proceeding to the

bottom layer, over the channel to the next station and
back up the hierarchy.

OSI is an ISO standard. (ICS field 35.100)

Physical

Data Link

Network

Transport

Session

Presentation

Application

Bits

Frame

Packet

Segment

Protocol Data Unit (PDU)

Protocol Data Units (PDU)

Protocol Data Units (PDU)

IP overview

IP (defined in RFC 791) is an unreliable
protocol. It is for communication between
computers. Other protocols like TCP, UDP,
ICMP and IGMP are all sent as IP datagrams.

With IP, messages (or other data) are broken up into small
independent "packets" and sent between computers via
the Internet out of order and over different Routes. IP is
responsible for "routing" each packet to its destination.

IP is a "connection-less" communication protocol. It does
not occupy the communication line between two
communicating computers. This way IP reduces the need
for network lines. Each line can be used for communication
between many different computers at the same time.

IP Routers

When an IP packet is sent from a computer, it arrives at an IP router.

The IP router is responsible for "routing" the packet to its destination,
directly or via another router.

The path the packet will follow might be different from other packets of
the same communication. The router is responsible for the right
addressing depending on traffic volume, errors in the network, or other
parameters.

Connection-Less Analogy

Communicating via IP is like sending a long letter as a large number of
small postcards, each finding its own (often different) way to the
receiver.

A simple routing game...

Not only Cisco can route data... ;)

TCP/IP is TCP and IP working together and stands for:
Transmission Control Protocol / Internet Protocol.

Syn

Syn-Ack

Ack

TCP (RFC 793) takes care of the communication between your application
software (i.e. your mail client or browser) and your network software. IP
takes care of the communication with other computers. TCP is responsible
for breaking data down into IP packets before they are sent, and for
assembling the packets when they arrive. IP is responsible for sending the
packets to the receiver.

TCP Uses a Fixed Connection

When an application wants to communicate with another application via
TCP, it sends a communication request. This request must be sent to an
exact address. After a "handshake" between the two applications, TCP will
setup a "full-duplex" communication between the two applications.

IP Addresses

Each computer must have an IP address before it can connect to the
Internet as an IP network.

Each IP packet must have a destination address before it can be sent to
another computer.

Addresses are normally written as four numbers separated by a period
like this: 192.68.20.50

TCP/IP uses 32 bits, or 4 numbers between 0 and 255 to address a
computer.

Number (numeral) systems

This is a framework where a set of numbers are represented by
numerals in a consistent manner. It can be seen as the context that allows the numeral "II" to be interpreted as the Roman numeral for two, the binary numeral for three or the decimal numeral for eleven. The unary number system is the simplest one.

Decimal: 0,1,2,3,4,5,6,7,8,9 (7+6=13)

Octal: 0,1,2,3,4,5,6,7 (7+1=10; 7+6=15)

Hexadecimal: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F (7+6=D; 9+E=17)

Binary: 0,1 (0+1=1; 1+1=10; 10+1=11; 110+11=1001)

In general, if b is the base, we write a number in the numeral system of base b by expressing it in the form a1bk + a2bk-1 + a3bk-2 + ... + ak+1b0 and writing the digits a1a2a3...ak+1 in order. The digits are natural numbers between 0 and b-1, inclusive.

TCP/IP uses 32 bit addressing. One computer byte is 8 bits.
So TCP/IP uses 4 bytes for addressing. One byte can

represent 256 different values:

0000 0000 = 0

0000 0001 = 1 = 1*20 = 1

0000 0010 = 2 = 1*21 + 0*20 = 2+0

0000 0011 = 3 = 1*21 + 1*20 = 2+1

0000 0100 = 4 = 1*22 + 0*21+ 0*20 = 4+0+0

0000 0101 = 5 = 1*22 + 0*21+ 1*20 = 4+0+1

0000 0110 = 6 = 1*22 + 1*21+ 0*20 = 4+2+0

0000 0111 = 7 = 1*22 + 1*21+ 1*20 = 4+2+1

0000 1000 = 8 = 1*23 + 0*22 + 0*21+ 0*20 = 8+0+0+0

...

1111 1111 = 255 =

= 1*27 + 1*26 + 1*25+ 1*24 + 1*23 + 1*22 + 1*21+ 1*20

e.g. 127.0.0.1 = 01111111 00000000 00000000 00000001

Each 32-bit address is divided into 4, 8-bit octets providing for a
possible address range of:

0.0.0.0 – 255.255.255.255

IP networks are often identified by classes:

Class A: defined as networks 0 - 127

Class B: defined as networks 128 - 191

Class C: defined as networks 192 - 223

Class D: defined as networks 224 - 239 (for multicasting)

Class E: defined as networks 240 - 255 (reserved)

Class A has a 7-bit network number and a 24-bit local address. The
highest order bit is always set to zero. This allows 128 (27) class A

networks with 16777214 hosts each.

Class B network addresses have a 14-bit network number, a 16-bit local

address, and they begin with "10" binary. This allows 16,384 class B

networks with 65534 hosts each.

Class C network addresses have a 21-bit network number, an 8-bit local

address, and they begin with "110" binary. This allows 2,097,152 class C

networks with 254 hosts each.

IP networks are often subnetted for easier management

ISPs will subnet portions of their address space to lease to large customers

Companies with large address spaces may subnet portions and assign them to different departments, organizations, etc.

Subnets are typically defined by a network number followed by a subnet mask and are typically written in one of two formats:

Dotted-decimal

e.g.	network: 172.16.0.0

subnet mask: 255.255.255.0

CIDR (Classless Inter-Domain Routing) notation

e.g. 172.16.0.0/24

Both of these examples depict a class C-sized chunk of class B address space.

Both notations simply define the number of leftmost contiguous, significant bits in the corresponding IP network address. For example:

network: 10.220.0.0

subnet mask: 255.255.0.0 (/16 in CIDR notation)

The mask here defines the first 16 bits of the network address as

significant, i.e. the last 16 bits will define the address range.

network	00001010.11011100.00000000.00000000

subnet mask	11111111.11111111.00000000.00000000

max range	00001010.11011100.11111111.11111111

Therefore the corresponding range of addresses for this subnet is:

10.220.0.0 – 10.220.255.255 (which is equivalent to 256 class B networks)

Private Address Space

RFC 1918 defines blocks of IP addresses that are reserved for private networks

that is to say they are non-routable over the public Internet

These three blocks are:

10.0.0.0 - 10.255.255.255 (10/8 prefix)

172.16.0.0 - 172.31.255.255 (172.16/12 prefix)

192.168.0.0 - 192.168.255.255 (192.168/16 prefix)

An Exercise:

192.168.0.128/27

What range of addresses do you see here?

11000000.10101000.00000000.10000000	(192.168.0.128)

11111111.11111111.11111111.11100000	(255.255.255.224)

^^^^^

11000000.10101000.00000000.10011111	(192.168.0.159)

so the range is 192.168.0.128 – 192.168.0.159

(technically speaking the range is .129 - .158 because .128 is reserved
for the network address and .159 is the reserved for the broadcast address)

FIN

SYN

RST

PSH

ACK

URG

reserved (6 bits)

data (if any)

options (if any)

16-bit urgent pointer

16-bit TCP checksum

16-bit window size

4-bit header length

32-bit acknowledgment number

32-bit sequence number

16-bit destination port number

16-bit source port number

TCP datagram

0

31

20 bytes

15 16

Domain Names

12 digit numbers are hard to remember. Using a name is easier.

Names used for TCP/IP addresses are called domain names. For example redhat.com is a domain name, or fsa-bg.org

When you address a web site like http://www.linux.com, the name is translated to a number by a DNS process (Domain Name Server).

All over the world, a large number of DNS servers are connected to the Internet. DNS servers are responsible for translating domain names into TCP/IP addresses and update each other with new domain names.

When a new domain name is registered together with a TCP/IP address, DNS servers all over the world are updated with this information.

Application level protocols (TCP/IP-based)

The HTTP protocol takes care of the communication between a web server and a web browser. The HTTP protocol is used for sending requests from a web client (a browser) to a web server returning web content (web pages) from the server back to the client.

The SSL protocol is used for encryption of data for secure data transmission.

The SMTP protocol is used for the transmission of e-mails.

The IMAP protocol is used for storing and retrieving e-mails.

The POP protocol is used for downloading e-mails from an e-mail server to a personal computer.

The FTP protocol takes care of the transmission of files between computers.

The NTP protocol is used for synchronizing the time (the clock) between computers.

127.0.0.1 ?

That is the localhost - it's a loopback IP address.

127.0.0.1 means - "this machine".

This is a virtual (not real) network interface but should exist

in every TCP/IP implementation. The operating system (OS)
will route information destined for localhost to the port on
the same machine and will never even reach a NIC (network

adapter). In fact, a NIC is not required to have a localhost.

Localhost is very important for interconnection between
daemons, applications, etc. on every Linux/UNIX machine.

What is a daemon?

A program that runs without human intervention. A daemon
(pronounced DEE-man) waits silently, springing into action
when some condition occurs (for example, when a file lands
in a particular directory, or when a Web request is made
through a particular communication line). Most server and network
software runs as a daemon.

Daemons are usually spawned automatically by the system, and
may either live forever or be regenerated at intervals. Linux/UNIX
systems run many daemons, chiefly to handle requests for
services from other hosts on a network. Most of these are now
started as required by a single real daemon, inetd, rather than
running continuously. Examples are cron (local timed command
execution), rshd (remote command execution), rlogind and
telnetd (remote login), sshd, ftpd, nfsd (file transfer), lpd

(printing).

How to configure your network under Linux?

Fedora:

# system-config-network

Red Hat:

# redhat-config-network

SuSE:

YaST # sysconfig

Debian:

# debconf # network-console-config

Mandrake:

Mandrake Control Center

Demo

The real way...

# ifconfig eth0 IP_ADDRESS [NETMASK] [up]

# ifconfig eth0 192.168.10.13 255.255.255.0 up

Edit your /etc/resolv.conf file:

nameserver 192.168.10.1

nameserver 192.168.10.2

Setting default gateway:

# route add default gw 192.168.10.1

Third way – try edit some configuration files:

/etc/sysconfig/network

NETWORKING=yes

HOSTNAME=selene

/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

TYPE=Ethernet

or

DEVICE=eth0

BOOTPROTO=static

IPADDR=192.168.10.13

BROADCAST=192.168.10.255

ONBOOT=yes

TYPE=Ethernet

How to check if everything is OK?

# ping 127.0.0.1

# ping 192.168.10.12 ; Your IP address

# ping 192.168.10.1 ; Your default gateway

# ping 192.168.11.2 ; Some other network

# ping www.dir.bg ; Check name resolving

An old story about love! But

a very new story about
Romeo and Juliet!
Today only! Here! Now!

Have you bought tickets? Let's see the movie ;)

And you'll never forget how the routers and TCP/IP work.

This presentation has been made exclusively with 100%

free and open source software.

The content can be freely distributed, displayed and modified

because of it's Creative Commons Attribution License.

No rights reserved.

Thank you for your time and attention!

Questions & Answers...

yovko @ yovko.net

2005-03-26T11:47:53