Hostnames IP Addresses are great for computers CSCE 515: IP - - PDF document

hostnames
SMART_READER_LITE
LIVE PREVIEW

Hostnames IP Addresses are great for computers CSCE 515: IP - - PDF document

Hostnames IP Addresses are great for computers CSCE 515: IP address includes information used for routing. Computer Network IP addresses are tough for humans to remember. Programming IP addresses are impossible to guess. ------


slide-1
SLIDE 1

CSCE 515:

Computer Network Programming

  • ----- Address Conversion Function and DNS

RFC 1034, RFC 1035 Wenyuan Xu http://www.cse.sc.edu/~wyxu/csce515f07.html Department of Computer Science and Engineering University of South Carolina

CSCE515 – Computer Network Programming 2007

Hostnames

IP Addresses are great for computers

IP address includes information used for routing.

IP addresses are tough for humans to remember. IP addresses are impossible to guess.

ever guessed at the name of a WWW site?

What if the server is moved to a different machine with a

different address

wyxu@cse.sc.edu wyxu@129.252.138.9

CSCE515 – Computer Network Programming 2007

Once there was HOSTS.TXT

Centralized for all the host in ARPAnet /etc/hosts were derived from HOSTS.TXT It was maintained by NIC and distributed by a

single host

The changes were e-mailed to NIC in one way

and ftped on the other way once or twice a week

Internet started to grow up exponentially…….

CSCE515 – Computer Network Programming 2007

HOSTS.TXT was a bottleneck

… too much traffic generated by the

updates in both directions.

Main problems:

traffic and load name collision consistency

CSCE515 – Computer Network Programming 2007

Domain Name System (DNS)

A distributed database used by TCP/IP applications to

map between hostnames and IP addresses

No single site on Internet knows all information; each site

maintains its own database and let other sites query it

Domain names comprise a hierarchy so that names are

unique, yet easy to remember.

Can you explain this in CS terms?

Postal system:

David on Main St. in White Plain, NY David on Main St. in Columbia, SC

CSCE515 – Computer Network Programming 2007

Hierarchical Organization of DNS

arpa com edu gov int mil net

  • rg

ae us zw … … sc cse sc state www vega

in-addr

118 130 252 129 United Arab Emirates Zimbabwe Unnamed root vega.cse.sc.edu www.state.sc.us

Generic domains Country domains

slide-2
SLIDE 2

CSCE515 – Computer Network Programming 2007

Host name structure

Each host name is made up of a

sequence of labels separated by periods.

Each label can be up to 63 characters Do you know the char length limits of a

total name?

Examples:

whitehouse.gov barney.the.purple.dinosaur.com vega.cse.sc.edu

CSCE515 – Computer Network Programming 2007

Domain Name

The domain name for a host is the

sequence of labels that lead from the host (leaf node in the naming tree) to the top of the worldwide naming tree.

A domain is a subtree of the worldwide

naming tree.

CSCE515 – Computer Network Programming 2007

Top level domains

Generic:

edu, gov, com, net, org, mil, …

Countries each have a top level domain (2 letter

domain name).

cn, uk, it, zl, jp…

New top level domains include:

.aero .biz .coop .info .name .pro

arpa, a special domain used for address-to-

name mappings

CSCE515 – Computer Network Programming 2007

More on domain names

Domain names can be either:

absolute (ends with a period)

engr.sc.edu.

relative does not ends with a period. Relative

names have to be interpreted in some context to uniquely determine their true meaning.

Domain names are case insensitive

edu, Edu, EDU are the same

CSCE515 – Computer Network Programming 2007

To get a new domain

To create a new domain, permission is required

  • f the domain in which it will be included.

company.com, get permission from whoever manage

com

cse.sc.edu, get permission from sc.edu

Can a machine inside computer science building

have a different domain?

Yes, Naming follows organizational boundaries, not

physical networks

CSCE515 – Computer Network Programming 2007

What do the hosts within the same domain have in common?

Do they must have the same OS? Do they must belong to the same

network?

Do they must be administrated by the

same person?

They usually are logically related:

geographically close same organization ….

slide-3
SLIDE 3

CSCE515 – Computer Network Programming 2007

DNS Organization

Distributed Database

The organization that owns a domain name

is responsible for running a DNS server that can provide the mapping between hostnames within the domain to IP addresses.

So - some machine run by SC is

responsible for everything within the sc.edu domain.

CSCE515 – Computer Network Programming 2007

DNS Zone

A subtree of DNS tree that is administered

separately

Each zone contains name servers holding the

information about that zone.

arpa com edu gov int mil net

  • rg

ae us zw … … sc cse sc state www vega

in-addr

118 130 United Arab Emirates Zimbabwe Unnamed root CSCE515 – Computer Network Programming 2007

rpi.edu DNS DB rpi.edu DNS DB

DNS Distributed Database

Each zone has a primary name server and

  • ne or more secondary name server

To avoid single point of failure secondary servers containing replicated

databases. sc.edu DNS DB Authoritative sc.edu DNS DB Replicas

sc.edu DNS server

Can a name server for a zone located outside the zone?

CSCE515 – Computer Network Programming 2007

DNS Clients

A DNS client is called a resolver. A call to gethostbyname()is handled by

a resolver (typically part of the client).

Most Unix workstations have the file

/etc/resolv.conf that contains the local domain and the addresses of DNS servers for that domain.

CSCE515 – Computer Network Programming 2007

/etc/resolv.conf

domain cse.sc.edu 129.252.131.9 129.252.11.9

CSCE515 – Computer Network Programming 2007

nslookup

nslookup is an interactive resolver that

allows the user to communicate directly with a DNS server.

nslookup is usually available on Unix

  • workstations. (dig and host are also

DNS clients).

slide-4
SLIDE 4

CSCE515 – Computer Network Programming 2007

DNS Servers

When a new system is added to a zone,

DNS administrator for the zone assigns a name and an IP address and stores information in name server

To resolve a name or address, client can

send DNS query message to a name server of its zone

CSCE515 – Computer Network Programming 2007

DNS Servers (cont’d)

Servers handle requests for their domain directly. Servers handle requests for other domains by contacting

remote DNS server(s).

When a name server is queried, it first searches its

database

If found, reply with a DNS response message If not found, contact external DNS servers

A name server caches external mappings received to

reduce DNS traffic

Authoritative record Cache record

CSCE515 – Computer Network Programming 2007

Server - Server Communication

If a server is asked to provide the

mapping for a host outside it’s domain (and the mapping is not in the server cache):

The server finds a nameserver for the

target domain.

The server asks the nameserver to provide

the host name to IP translation.

To find the right nameserver, use DNS!

CSCE515 – Computer Network Programming 2007

The Root DNS Server

The root server needs to know the

address of 1st (and many 2nd) level domain nameservers. edu com

  • rg

jp yale sc

CSCE515 – Computer Network Programming 2007

Server Operation

If a server has no clue about where to find

the address for a hostname, ask the root server.

The root server will tell you what

nameserver to contact.

A request may get forwarded a few times.

CSCE515 – Computer Network Programming 2007

DNS Data

DNS databases contain more than just hostname-to-address

records -- a set of resource records (five-tuple)

Domain Name:

Series of labels of alphanumeric characters or hyphens Each pair separated by period

Time_to_live

How long to hold the result in local cache

Class

  • For internet information it is always IN

Type

  • what kind of record this is

Value

Description of resource For A type, Rdata is 32-bit IP address

Main function of DNS is to map domain names onto resource records!

slide-5
SLIDE 5

CSCE515 – Computer Network Programming 2007

Resource Record Type - 1

A

Address type. Value of A type RRs is an IP address

SOA

Start of Authority Parameters (mostly to sync with other servers) and

info about this zone

MX

Mail Exchange name of the receiving SMTP agent for the zone may be more than one MX RRs for one zone

priorities are used CSCE515 – Computer Network Programming 2007

Resource Record Type - 2

CNAME

Canonical Name used to create aliases value is the canonical host name

NS

Name Server Value field is the name of the server who knows the

IP addresses of the hosts that belongs to the domain given in the Domain_Name field.

can be used to specify the names of the name

servers in both current domain or in subordinate domains (for delegation purposes)

There might be several DNS servers for each domain for

fault tolerance

CSCE515 – Computer Network Programming 2007

Resource Record Type - 3

PTR

Pointer type mostly used for reverse lookups Domain_Name field is an IP address; Value is the

hostname

HINFO

Host Info. OS and processor type of information about the

zone’s server

TXT

Textual comments

CSCE515 – Computer Network Programming 2007

Portion of a possible DNS database

cs.vu.nl. 86400 IN NS flits.cs.vu.nl. cs.vu.nl. 86400 IN NS star.cs.vu.nl. zephyr.cs.vu.nl. 86400 IN A 130.37.20.10 zephyr.cs.vu.nl. 86400 IN HINFO Sun Unix star.cs.vu.nl. 86400 IN A 130.37.24.6 star.cs.vu.nl. 86400 IN A 192.31.231.42 star.cs.vu.nl. 86400 IN HINFO Sun Unix

CSCE515 – Computer Network Programming 2007

Example for PTR record for Reverse Lookup

Useful when you know the IP address and want to know

the corresponding host name

Suppose you would like to know the host name for IP

address 193.140.192.24

you have to query the DNS servers for the PTR entry

24.192.140.193.in-addr.arpa.

Be careful! numbers are in reverse order In order to find the host name, the host’s name server should have

an entry 24.192.140.193.in-addr.arpa. PTR domain_name

for this particular case domain_name is kennedy.cc.boun.edu.tr

CSCE515 – Computer Network Programming 2007

DNS Message Format

HEADER QUERIES Response RESOURCE RECORDS Response AUTHORITY RECORDS

Response ADDITIONAL INFORMATION

HEADER QUERIES Response RESOURCE RECORDS Response AUTHORITY RECORDS

Response ADDITIONAL INFORMATION

slide-6
SLIDE 6

CSCE515 – Computer Network Programming 2007

DNS Message Header

query identifier flags # of questions # of RRs # of authority RRs # of additional RRs

16 bit fields Response

CSCE515 – Computer Network Programming 2007

Message Flags

QR: Query=0, Response=1 AA: Authoritative Answer TC: response truncated (> 512 bytes) RD: recursion desired RA: recursion available rcode: return code

CSCE515 – Computer Network Programming 2007

Recursion

A request can indicate that recursion is

desired - this tells the server to find out the answer (possibly by contacting other servers).

If recursion is not requested - the

response may be a list of other name servers to contact.

CSCE515 – Computer Network Programming 2007

Question Format

Name: domain name (or IP address) Query type (A, NS, MX, …) Query class (1 for IP)

query class

15 16 31

query name query type

CSCE515 – Computer Network Programming 2007

Response Resource Record

Domain Name Response type Class (IP) Time to live (in

seconds)

Length of resource

data

Resource data

class resource data

1 5 1 6 3 1

time-to-live domain name type

resource data length

CSCE515 – Computer Network Programming 2007

UDP & TCP

Both UDP and TCP are used:

TCP for transfers of entire database to

secondary servers (replication).

UDP for lookups If more than 512 bytes in response -

requestor resubmits request using TCP.

slide-7
SLIDE 7

CSCE515 – Computer Network Programming 2007

Lots more

This is not a complete description ! If interested - look at:

RFC 1034: DNS concepts and facilities. RFC 1035: DNS implementation and protocol

specification.

play with nslookup. Look at code for BIND (DNS server code).

CSCE515 – Computer Network Programming 2007

Name to Address Conversion

There is a library of functions that act as

DNS client (resolver).

you don’t need to write DNS client code to

use DNS!

With some OSs you need to explicitly link

with the DNS resolver library:

  • lnsl

(nsl is “Name Server Library”)

Suns (Solaris) need this!

CSCE515 – Computer Network Programming 2007

DNS library functions

gethostbyname gethostbyaddr gethostbyname2

IPV6!

CSCE515 – Computer Network Programming 2007

gethostbyname

struct hostent *gethostbyname( const char *hostname); struct hostent is defined in netdb.h: #include <netdb.h>

CSCE515 – Computer Network Programming 2007

struct hostent

struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; };

  • fficial name (canonical)
  • ther names

AF_INET or AF_INET6 address length (4 or 16) array of ptrs to addresses

CSCE515 – Computer Network Programming 2007

hostent picture

h_name h_aliases h_addrtype h_length h_addr_list Official Name alias 1 alias 2

null

IP address 1 IP address 2

null

slide-8
SLIDE 8

CSCE515 – Computer Network Programming 2007

Which Address?

On success, gethostbyname returns the address of a hostent that has been created.

has an array of ptrs to IP addresses Usually use the first one:

#define h_addr h_addr_list[0]

CSCE515 – Computer Network Programming 2007

gethostbyname and errors

On error gethostbyname return null. Gethostbyname sets the global variable

h_errno to indicate the exact error:

HOST_NOT_FOUND TRY_AGAIN NO_RECOVERY NO_DATA NO_ADDRESS

All defined in netdb.h

CSCE515 – Computer Network Programming 2007

Getting at the address: char **h_addr_list;

h = gethostbyname("joe.com"); sockaddr.sin_addr.s_addr = *(h->h_addr_list[0]); This won't work!!!!

h_addr_list[0] is a char* ! struct in_addr {

in_addr_t s_addr; };// IPV4 address struct sockaddr_in { uint8_t sin_len; sa_family_t sin_family; in_port_t sin_port; struct in_addr sin_addr; char sin_zero[8]; };

CSCE515 – Computer Network Programming 2007

Using memcpy

You can copy the 4 bytes (IPv4) directly:

h = gethostbyname("joe.com"); memcpy(&sockaddr.sin_addr, h->h_addr_list[0], sizeof(struct in_addr));

CSCE515 – Computer Network Programming 2007

Network Byte Order

All the IP addresses returned via the

hostent are in network byte order!

CSCE515 – Computer Network Programming 2007

gethostbyaddr

struct hostent *gethostbyaddr( const char *addr size_t len, int family);

A F _ I N E T ( c

  • u

l d b e A F _ I N E T 6 ) s i z e

  • f

( s t r u c t i n _ a d d r )

slide-9
SLIDE 9

CSCE515 – Computer Network Programming 2007

Some other functions

uname: get hostname of local host getservbyname : get port number for a named service getservbyaddr : get name for service associated with a port number