Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 DNS: Domain Name System People: many identifiers: m SSN, name, Passport # Internet hosts, routers: m IP address (32 bit) - used for addressing datagrams.

Similar presentations


Presentation on theme: "1 DNS: Domain Name System People: many identifiers: m SSN, name, Passport # Internet hosts, routers: m IP address (32 bit) - used for addressing datagrams."— Presentation transcript:

1 1 DNS: Domain Name System People: many identifiers: m SSN, name, Passport # Internet hosts, routers: m IP address (32 bit) - used for addressing datagrams m “name”, e.g., gaia.cs.umass.edu - used by humans Q: map between IP addresses and name ? Domain Name System: r distributed database implemented in hierarchy of many name servers r application-layer protocol host, routers, name servers to communicate to resolve names (address/name translation) m note: core Internet function implemented as application-layer protocol m complexity at network’s “edge”

2 2 DNS name servers r no server has all name- to-IP address mappings local name servers: m each ISP, company has local (default) name server m host DNS query first goes to local name server authoritative name server: m for a host: stores that host’s IP address, name m can perform name/address translation for that host’s name Why not centralize DNS? r single point of failure r traffic volume r distant centralized database r Maintenance r DoS attacks? doesn’t scale!

3 3 DNS: Root name servers r contacted by local name server that can not resolve name r root name server: m contacts authoritative name server if name mapping not known m gets mapping m returns mapping to local name server r ~ dozen root name servers worldwide r 13 root DNS servers: replication for security and reliability r Top-level DNS server: org, edu, com, jp,cn, fr, uk

4 4 Simple DNS example host surf.eurecom.fr wants IP address of gaia.cs.umass.edu 1. Contacts its local DNS server, dns.eurecom.fr 2. dns.eurecom.fr contacts root name server, if necessary 3. root name server contacts authoritative name server, dns.umass.edu, if necessary requesting host surf.eurecom.fr gaia.cs.umass.edu root name server authorititive name server dns.umass.edu local name server dns.eurecom.fr 1 2 3 4 5 6

5 5 DNS example Root name server: r may not know authoratiative name server r may know intermediate name server: who to contact to find authoritative name server requesting host surf.eurecom.fr gaia.cs.umass.edu root name server local name server dns.eurecom.fr 1 2 3 4 5 6 authoritative name server dns.cs.umass.edu intermediate name server dns.umass.edu 7 8

6 6 DNS: iterated queries recursive query: r puts burden of name resolution on contacted name server r heavy load? iterated query: r contacted server replies with name of server to contact r “I don’t know this name, but ask this server” requesting host surf.eurecom.fr gaia.cs.umass.edu root name server local name server dns.eurecom.fr 1 2 3 4 5 6 authoritative name server dns.cs.umass.edu intermediate name server dns.umass.edu 7 8 iterated query

7 7 DNS: caching and updating records r once (any) name server learns mapping, it caches mapping m cache entries timeout (disappear) after some time r update/notify mechanisms under design by IETF m RFC 2136 m http://www.ietf.org/html.charters/dnsind-charter.html

8 8 DNS records DNS: distributed db storing resource records (RR) r Type=NS  name is domain (e.g. foo.com)  value is IP address of authoritative name server for this domain RR format: (name, value, type,ttl) r Type=A  name is hostname  value is IP address r Type=CNAME  name is an alias name for some “cannonical” (the real) name  value is cannonical name r Type=MX  value is hostname of mailserver associated with name

9 9 DNS records For a particular hostname r If a DNS server is authoritative, it contains m a Type A record for the hostname r Otherwise m Maybe a Type A record for the hostname in cache m a Type NS record for the domain of the hostname m a Type A record for the DNS server for that domain m Host: gaia.cs.umass.edu m (umass.edu, dns.umass.edu, NS) m (dns.umass.edu, 128.119.40.111, A)

10 10 DNS protocol, messages DNS protocol : query and repy messages, both with same message format msg header r identification: 16 bit # for query, repy to query uses same # r flags: m query or reply m recursion desired m recursion available m reply is authoritative

11 11 DNS protocol, messages Name, type fields for a query RRs in reponse to query records for authoritative servers additional “helpful” info that may be used Try nslookup?

12 12 Mystery: How to set up your DNS server? r You setup a company: mynet.com r Step 1: register your domain name with a registrar m Provide name and IP address mapping m Primary authoritative DNS server: dns1.mynet.com, 212.212.212.1 m Optional: secondary DNS server: dns.mynet.com, 212.212.212.2 m Registrar will insert type NS and A records for you m (mynet.com, dns1.mynet.com, NS) m (dn1.mynet.com, 212.212.212.1, A) r Step 2: insert records into your DNS server m For web server (www.mynet.com, 212.212.212.3,A)www.mynet.com m For mail sever (mail.mynet.com, 212.212.212.4, MX) m Then, others can access your web server and send emails

13 13 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of transport service via socket API: m unreliable datagram m reliable, byte stream- oriented a host-local, application- created/owned, OS-controlled interface (a “door”) into which application process can both send and receive messages to/from another (remote or local) application process socket Goal: learn how to build client/server application that communicate using sockets

14 14 Socket-programming using TCP Socket: a door between application process and end- end-transport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server internet

15 15 Socket programming with TCP Client must contact server r server process must first be running r server must have created socket (door) that welcomes client’s contact Client contacts server by: r creating client-local TCP socket r specifying IP address, port number of server process r When client creates socket: client TCP establishes connection to server TCP r When contacted by client, server TCP creates new socket for server process to communicate with client m allows server to talk with multiple clients TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint

16 16 Socket programming with TCP Example client-server app: r client reads line from standard input, sends to server via socket server reads line from socket r server converts line to uppercase, sends back to client r client reads, prints modified line from socket Input stream: sequence of bytes into process Output stream: sequence of bytes out of process client socket inFromUser outToServer iinFromServer

17 17 Client/server socket interaction: TCP wait for incoming connection request int cs = accept(s,….) create socket, port= x, for incoming request: int s = socket(…); bind(s,…) listen(s,5); create socket, connect to hostid, port= x int cli_socket = socket(..); connect(s,…); close cs read reply from cli_socket close cli_socket Server (running on hostid ) Client send request using cli_socket read request from cs write reply to cs TCP connection setup

18 18 Example: C++ client (TCP) #include /* Basic I/O routines */ #include /* standard system types */ #include /* Internet address structures */ #include /* socket interface functions */ #include /* host to IP resolution */ int main(int argc, char *argv[]) { /* Address resolution stage */ struct hostent* hen = gethostbyname(argv[1]); if (!hen) { perror("couldn't resolve host name"); } struct sockaddr_in sa; memset(&sa, 0, sizeof(sa); sa.sin_family = AF_INET; sa.sin_port = htons(PORT); //server port number memcpy(&sa.sin_addr.s_addr, hen->h_addr_list[0], hen->h_length); int cli_socket = socket(AF_INET, SOCK_STREAM, 0); assert(cli_socket >= 0); //I am just lazy here!! connect(s, (struct sockaddr *)&sa, sizeof(sa)); write(s, argv[2], strlen(argv[2])); //send it to server char buf[BUFLEN]; int rc; memset(buf, 0, BUFLEN); char* pc = buf; while(rc = read(cli_socket, pc, BUFLEN – (pc - buf))) pc += rc; write(1, buf, strlen(buf)); close(cli_socket); } Create client socket, connect to server

19 19 Example: C++ server (TCP) //include header files #define PORT 6789 int main(int argc, char* argv[]) { struct sockaddr_in sa, csa; memset(&sa, 0, sizeof(sa); sa.sin_family = AF_INET; sa.sin_port = htons(PORT); sa.sin_addr.s_addr = INADDR_ANY; //any IP addr. Is accepted int s = socket(AF_INET,SOCK_STREAM, 0); assert( s>=0); int rc = bind(s, (struct sockaddr *)& sa, sizeof(sa)); //hook s with port rc = listen(s, 5); int cs_socket = accept(s, (struct sockaddr*)&csa, sizeof(csa)); char buf[BUFLEN]; memset(buf, 0, BUFLEN); char* pc = buf; while(rc = read(cs_socket, pc, BUFLEN – (pc - buf))) pc += rc; upper_case(buf); // covert it into upper case write(cs_socket, buf, strlen(buf)); close(cs_socket); close(s); }

20 20 Multi-Clients Servers r Two main approaches to designing such servers. r Approach 1. r The first approach is using one process that awaits new connections, and one more process (or thread) for each Client already connected. This approach makes design quite easy, cause then the main process does not need to differ between servers, and the sub-processes are each a single- Client server process, hence, easier to implement. r However, this approach wastes too many system resources (if child processes are used), and complicates inter-Client communication: If one Client wants to send a message to another through the server, this will require communication between two processes on the server, or locking mechanisms, if using multiple threads. r See tutor for details!

21 21 Socket programming with UDP UDP: no “connection” between client and server r no handshaking r sender explicitly attaches IP address and port of destination r server must extract IP address, port of sender from received datagram UDP: transmitted data may be received out of order, or lost application viewpoint UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server

22 22 Summary r application service requirements: m reliability, bandwidth, delay r client-server paradigm r Internet transport service model m connection-oriented, reliable: TCP m unreliable, datagrams: UDP Our study of network apps now complete! r specific protocols: m http m ftp m smtp, pop3 m dns r socket programming m client/server implementation m using tcp, udp sockets

23 23 Summary r typical request/reply message exchange: m client requests info or service m server responds with data, status code r message formats: m headers: fields giving info about data m data: info being communicated Most importantly: learned about protocols r control vs. data msgs m in-based, out-of-band r centralized vs. decentralized r stateless vs. stateful r reliable vs. unreliable msg transfer r “complexity at network edge” r security: authentication


Download ppt "1 DNS: Domain Name System People: many identifiers: m SSN, name, Passport # Internet hosts, routers: m IP address (32 bit) - used for addressing datagrams."

Similar presentations


Ads by Google