Copyright © University of Illinois CS 241 Staff1 Network programming, DNS, and NAT.

Slides:



Advertisements
Similar presentations
Copyright © University of Illinois CS 241 Staff
Advertisements

Domain Name System (or Service) (DNS) Computer Networks Computer Networks Term B10.
1 EEC-484/584 Computer Networks Lecture 5 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
EEC-484/584 Computer Networks Lecture 5 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
EEC-484/584 Computer Networks Lecture 5 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
1 Network Address Translation (NAT) Relates to Lab 7. Module about private networks and NAT.
Domain Name System (or Service) (DNS) Computer Networks Computer Networks Spring 2012 Spring 2012.
NAT: Network Address Translation local network (e.g., home network) /24 rest of Internet Datagrams.
EEC-484/584 Computer Networks Lecture 5 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
2: Application Layer1 FTP, SMTP and DNS. 2: Application Layer2 FTP: separate control, data connections r FTP client contacts FTP server at port 21, specifying.
1 Domain Name System (DNS) Reading: Section 9.1 COS 461: Computer Networks Spring 2006 (MW 1:30-2:50 in Friend 109) Jennifer Rexford Teaching Assistant:
EEC-484/584 Computer Networks Lecture 5 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
1 Domain Name System (DNS). 2 DNS: Domain Name System Internet hosts, routers: –IP address (32 bit) - used for addressing datagrams –“name”, e.g., gaia.cs.umass.edu.
EEC-484/584 Computer Networks Lecture 5 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach, 4 th edition. Jim Kurose, Keith Ross Addison-Wesley, July 2007.
Application Layer session 1 TELE3118: Network Technologies Week 12: DNS Some slides have been taken from: r Computer Networking: A Top Down Approach.
CPSC 441: DNS1 Instructor: Anirban Mahanti Office: ICT Class Location: ICT 121 Lectures: MWF 12:00 – 12:50 Notes derived.
Jennifer Rexford Fall 2014 (TTh 3:00-4:20 in CS 105) COS 561: Advanced Computer Networks Domain.
Name Resolution and DNS. Domain names and IP addresses r People prefer to use easy-to-remember names instead of IP addresses r Domain names are alphanumeric.
2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012.
NET0183 Networks and Communications Lecture 25 DNS Domain Name System 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks.
CS 4396 Computer Networks Lab
1 Domain Name System (DNS). 2 DNS: Domain Name System Internet hosts: – IP address (32 bit) - used for addressing datagrams – “name”, e.g.,
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 10 Omar Meqdadi Department of Computer Science and Software Engineering University.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
1 Today’s Topics* r ICMP r DHCP r Domain Naming  DNS r Byte ordering * Based in part on slides by Paul D. Paulson.
2: Application Layer1 Some network apps r r Web r Instant messaging r Remote login r P2P file sharing r Multi-user network games r Streaming stored.
CS 471/571 Domain Name Server Slides from Kurose and Ross.
IT 424 Networks2 IT 424 Networks2 Ack.: Slides are adapted from the slides of the book: “Computer Networking” – J. Kurose, K. Ross Chapter 2: Application.
DNS: Domain Name System
Review: –Which protocol is used to move messages around in the Internet? –Describe how a message is moved from the sender’s UA to the receiver’s.
Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April A note on the use.
DNS: Domain Name System People: many identifiers: – SSN, name, Passport # Internet hosts, routers: – IP address (32 bit) - used for addressing datagrams.
25.1 Chapter 25 Domain Name System Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
CPSC 441: DNS 1. DNS: Domain Name System Internet hosts: m IP address (32 bit) - used for addressing datagrams m “name”, e.g., - used by.
CS 3830 Day 10 Introduction 1-1. Announcements r Quiz #2 this Friday r Program 2 posted yesterday 2: Application Layer 2.
Lectu re 1 Recap: “Operational” view of Internet r Internet: “network of networks” m Requires sending, receiving of messages r protocols control sending,
Lecture 5: Web Continued 2-1. Outline  Network basics:  HTTP protocols  Studies on HTTP performance from different views:  Browser types [NSDI 2014]
Lecture 7: Domain Name Service (DNS) Reading: Section 9.1 ? CMSC 23300/33300 Computer Networks
Spring 2015© CS 438 Staff1 DNS. Host Names vs. IP addresses Host names  Mnemonic name appreciated by humans  Variable length, full alphabet of characters.
1 EEC-484/584 Computer Networks Lecture 5 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer Networking book.
Chapter 2 Application Layer Computer Networking: A Top Down Approach, 4 th edition. Jim Kurose, Keith Ross Addison-Wesley, July 2007.
1 Kyung Hee University Chapter 19 DNS (Domain Name System)
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
1. Internet hosts:  IP address (32 bit) - used for addressing datagrams  “name”, e.g., ww.yahoo.com - used by humans DNS: provides translation between.
Data Communications and Computer Networks Chapter 4 CS 3830 Lecture 19 Omar Meqdadi Department of Computer Science and Software Engineering University.
Application Layer, 2.5 DNS 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley.
CSEN 404 Application Layer II Amr El Mougy Lamia Al Badrawy.
Spring 2006 CPE : Application Layer_DNS 1 Special Topics in Computer Engineering Application layer: Domain Name System Some of these Slides are.
@Yuan Xue A special acknowledge goes to J.F Kurose and K.W. Ross Some of the slides used in this lecture are adapted from their.
@Yuan Xue A special acknowledge goes to J.F Kurose and K.W. Ross Some of the slides used in this lecture are adapted from their.
2: Application Layer 1 Some network apps r r Web r Instant messaging r Remote login r P2P file sharing r Multi-user network games r Streaming stored.
Chapter 17 DNS (Domain Name System)
Introduction to Networks
Chapter 19 DNS (Domain Name System)
Session 6 INST 346 Technologies, Infrastructure and Architecture
Chapter 9: Domain Name Servers
Network Address Translation (NAT)
Introduction to Communication Networks
Domain Name System (DNS)
Network Address Translation (NAT)
Chapter 7: Application layer
Domain Name System (DNS)
Chapter 19 DNS (Domain Name System)
EEC-484/584 Computer Networks
Domain Name System (DNS)
FTP, SMTP and DNS 2: Application Layer.
Network Address Translation (NAT)
Naming in Networking Jennifer Rexford COS 316 Guest Lecture.
Presentation transcript:

Copyright © University of Illinois CS 241 Staff1 Network programming, DNS, and NAT

Today Network programming tips Domain name system Network Address Translation Bonus slides (for your reference)  Timers with select()  select() vs. poll() Copyright © University of Illinois CS 241 Staff2

Tip #1: Can’t bind? Problem: How come I get "address already in use" from bind() ?  You have stopped your server, and then re- started it right away  The sockets that were used by the first incarnation of the server are still active CS 241Copyright ©: University of Illinois CS 241 Staff3

CS 241Copyright ©: University of Illinois CS 241 Staff4 setsockopt int yes = 1; setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *) &yes, sizeof (yes));  Call just before bind()  Allows bind to succeed despite the existence of existing connections in the requested TCP port  Connections in limbo (e.g. lost final ACK) will cause bind to fail

Tip #2: Dealing with abruptly closed connection Copyright © University of Illinois CS 241 Staff5 [demo: server.c]

CS 241Copyright ©: University of Illinois CS 241 Staff6 signal Problem: Socket at other end is closed  Write to your end generates SIGPIPE  This signal kills the program by default! signal (SIGPIPE, SIG_IGN);  Call at start of main in server  Allows you to ignore broken pipe signals  Can ignore or install a proper signal handler  Default handler exits (terminates process)

Tip #3: Beej’s guide Beej's Guide to Network Programming Copyright © University of Illinois CS 241 Staff7

8 The Domain Name System Slides thanks in part to Jennifer Rexford, Ion Stoica, Vern Paxson, and Scott Shenker

9 Host Names vs. IP addresses Host names  Mnemonic name appreciated by humans  Variable length, full alphabet of characters  Provide little (if any) information about physical location  Examples: and bbc.co.uk IP addresses  Numerical address appreciated by routers  Fixed length, binary number  Hierarchical, related to host location  Examples: and

10 Separating Naming and Addressing Names are easier to remember  cnn.com vs (but not shortened urls) Addresses can change underneath  Move to  E.g., renumbering when changing providers Name could map to multiple IP addresses  to multiple (8) replicas of the Web site  Enables Load-balancing Reducing latency by picking nearby servers Tailoring content based on requester’s location/identity Multiple names for the same address  E.g., aliases like and cnn.com

11 Domain Name System (DNS) Properties of DNS  Hierarchical name space divided into zones  Zones distributed over collection of DNS servers Hierarchy of DNS servers  Root (hardwired into other servers)  Top-level domain (TLD) servers  Authoritative DNS servers Performing the translations  Local DNS servers  Resolver software

Distributed, Hierarchical Database Client wants IP for  Client queries a root server to find com DNS server  Client queries com DNS server to get amazon.com DNS server  Client queries amazon.com DNS server to get IP address for 12 Root DNS Servers com DNS servers org DNS servers edu DNS servers uiuc.edu DNS servers umass.edu DNS servers yahoo.com DNS servers amazon.com DNS servers pbs.org DNS servers CS 241Copyright ©: University of Illinois CS 241 Staff

13 DNS Root Located in Virginia, USA How do we make the root scale? Verisign, Dulles, VA

14 DNS Root Servers 13 root servers (see  Labeled A through M Does this scale? B USC-ISI Marina del Rey, CA L ICANN Los Angeles, CA E NASA Mt View, CA F Internet Software Consortium Palo Alto, CA I Autonomica, Stockholm K RIPE London M WIDE Tokyo A Verisign, Dulles, VA C Cogent, Herndon, VA D U Maryland College Park, MD G US DoD Vienna, VA H ARL Aberdeen, MD J Verisign

15 DNS Root Servers 13 root servers each replicated via any-casting (localized routing for addresses) B USC-ISI Marina del Rey, CA L ICANN Los Angeles, CA E NASA Mt View, CA F Internet Software Consortium, Palo Alto, CA (and 37 other locations) I Autonomica, Stockholm (plus 29 other locations) K RIPE London (plus 16 other locations) M WIDE Tokyo plus Seoul, Paris, San Francisco A Verisign, Dulles, VA C Cogent, Herndon, VA (also Los Angeles, NY, Chicago) D U Maryland College Park, MD G US DoD Vienna, VA H ARL Aberdeen, MD J Verisign (21 locations)

TLD and Authoritative Servers Top-level domain (TLD) servers  Responsible for com, org, net, edu, etc, and all top-level country domains uk, fr, ca, jp. Network Solutions maintains servers for com TLD Educause for edu TLD Authoritative DNS servers  Organization’s DNS servers  Provide authoritative hostname to IP mappings for organization’s servers (e.g., Web, mail).  Can be maintained by organization or service provider 16CS 241Copyright ©: University of Illinois CS 241 Staff

17 Local Name Server One per ISP (residential ISP, company, university)  Also called “default name server” When host makes DNS query, query is sent to its local DNS server  Acts as proxy, forwards query into hierarchy  Reduces lookup latency for commonly searched hostnames Hosts learn local name server via...  DHCP (same protocol that tells host its IP address)  Static configuration (e.g., can use Google’s “local” name service at or ) CS 241Copyright ©: University of Illinois CS 241 Staff

18 Applications’ use of DNS Client application (e.g., web browser)  Extract server name (e.g., from the URL)  Do gethostbyname() to trigger resolver code, sending message to local name server Server application (e.g. web server)  Extract client IP address from socket  Optional gethostbyaddr() to translate into name

DNS name resolution example Host at cs.uiuc.edu wants IP address for gaia.cs.umass.edu Iterated query  Contacted server replies with name of server to contact  “I don’t know this name, but ask this server” 19 requesting host cs.uiuc.edu gaia.cs.umass.edu root DNS server local DNS server dns.uiuc.edu authoritative DNS server 7 8 TLD DNS server CS 241Copyright ©: University of Illinois CS 241 Staff dns.cs.umass.edu

DNS: Caching Once (any) name server learns mapping, it caches mapping  Cache entries timeout (disappear) after some time  TLD servers typically cached in local name servers Thus root name servers not often visited 20CS 241Copyright ©: University of Illinois CS 241 Staff

Network Address Translation Copyright © University of Illinois CS 241 Staff21

NAT: Network Address Translation Approach  Assign one router a global IP address  Assign internal hosts local IP addresses Change IP Headers  IP addresses (and possibly port numbers) of IP datagrams are replaced at the boundary of a private network  Enables hosts on private networks to communicate with hosts on the Internet  Run on routers that connect private networks to the public Internet CS 241Copyright ©: University of Illinois CS 241 Staff22

NAT: Network Address Translation Outgoing packet  Source IP address (private IP) replaced by global IP address maintained by NAT router Incoming packet  Destination IP address (global IP of NAT router) replaced by appropriate private IP address CS 241Copyright ©: University of Illinois CS 241 Staff23 What address do the remote hosts respond to? NAT router caches translation table: (source IP address, port #)  (NAT IP address, new port #)

NAT: Network Address Translation S: , 3345 D: , : host sends datagram to , 80 NAT translation table WAN side addr LAN side addr , , 3345 …… S: , 80 D: , S: , 5001 D: , : NAT router changes datagram source addr from , 3345 to , 5001, updates table S: , 80 D: , : Reply arrives dest. address: , : NAT router changes datagram dest addr from , 5001 to , 3345 CS 24124Copyright ©: University of Illinois CS 241 Staff

NAT: Benefits Local network uses just one (or a few) IP address as far as outside world is concerned  No need to be allocated range of addresses from ISP Just one IP address is used for all devices Or a few, in a large private enterprise network 16-bit port-number field: 60,000 simultaneous connections with a single LAN-side address!  Can change addresses of devices in local network without notifying outside world  Can change ISP without changing addresses of devices in local network  Devices inside local net not explicitly addressable, visible by outside world (a security plus) CS 24125Copyright ©: University of Illinois CS 241 Staff

NAT: Benefits Load balancing  Balance the load on a set of identical servers, which are accessible from a single IP address NAT solution  Servers are assigned private addresses  NAT acts as a proxy for requests to the server from the public network  NAT changes the destination IP address of arriving packets to one of the private addresses for a server  Balances load on the servers by assigning addresses in a round-robin fashion CS 241Copyright ©: University of Illinois CS 241 Staff26

NAT: Consequences End-to-end connectivity broken  NAT destroys universal end-to-end reachability of hosts on the Internet  A host in the public Internet often cannot initiate communication to a host in a private network  Even worse when two hosts that are in different private networks need to communicate with each other CS 24127Copyright ©: University of Illinois CS 241 Staff

NAT: Consequences Performance worsens  Modifying the IP header by changing the IP address requires that NAT boxes recalculate the IP header checksum  Modifying port number requires that NAT boxes recalculate TCP checksum Fragmentation issues  Datagrams fragmented before NAT device must not be assigned different IP addresses or different port numbers CS 24128Copyright ©: University of Illinois CS 241 Staff

NAT: Consequences Broken if IP address in application data  Applications often carry IP addresses in the payload of the application data  No longer work across a private-public network boundary  Hack: Some NAT devices inspect the payload of widely used application layer protocols and, if an IP address is detected in the application-layer header or the application payload, translate the address according to the address translation table CS 24129Copyright ©: University of Illinois CS 241 Staff

NAT: Consequences Ossification of Internet protocols  NAT must be aware of port numbers which are inside transport header  Existing NATs don’t support your fancy new transport protocol and might even block standard protocols like UDP  Result: Difficult to invent new transport protocols...unless they just pretend to be TCP CS 24130Copyright ©: University of Illinois CS 241 Staff

CS 241Copyright ©: University of Illinois CS 241 Staff31 Bonus slides

A UDP Server How can a UDP server service multiple ports simultaneously? CS 241Copyright ©: University of Illinois CS 241 Staff32 UDP IP Ethernet Adapter UDP Server Port 2000Port 3000

UDP Server: Servicing Two Ports int s1;/* socket descriptor 1 */ int s2;/* socket descriptor 2 */ /* 1) create socket s1 */ /* 2) create socket s2 */ /* 3) bind s1 to port 2000 */ /* 4) bind s2 to port 3000 */ while(1) { recvfrom(s1, buf, sizeof(buf),...); /* process buf */ recvfrom(s2, buf, sizeof(buf),...); /* process buf */ } CS 241Copyright ©: University of Illinois CS 241 Staff33 What problems does this code have?

CS 241Copyright ©: University of Illinois CS 241 Staff34 Building Timeouts with Select and Poll Time structure struct timeval { long tv_sec;/* seconds */ long tv_usec;/* microseconds */ }; unix will have its own "Y2K" problem one second after 10:14:07pm, Monday January 18, 2038 (will appear to be 3:45:52pm, Friday December 13, 1901) Number of seconds since midnight, January 1, 1970 GMT

CS 241Copyright ©: University of Illinois CS 241 Staff35 Select High-resolution sleep function  All descriptor sets NULL  Positive timeout Wait until descriptor(s) become ready  At least one descriptor in set  timeout NULL Wait until descriptor(s) become ready or timeout occurs  At least one descriptor in set  Positive timeout Check descriptors immediately (poll)  At least one descriptor in set  0 timeout Which file descriptors are set and what should the timeout value be?

CS 241Copyright ©: University of Illinois CS 241 Staff36 Select: Example fd_set my_read; FD_ZERO(&my_read); FD_SET(0, &my_read); if (select(1, &my_read, NULL, NULL) == 1) { ASSERT(FD_ISSET(0, &my_read); /* data ready on stdin */ What went wrong: after select indicates data available on a connection, read returns no data?

Select: Timeout Example int main(void) { struct timeval tv; fd_set readfds; tv.tv_sec = 2; tv.tv_usec = ; FD_ZERO(&readfds); FD_SET(STDIN, &readfds); // don't care about writefds and exceptfds: select(1, &readfds, NULL, NULL, &tv); if (FD_ISSET(STDIN, &readfds)) printf("A key was pressed!\n"); else printf("Timed out.\n"); return 0; } CS 241Copyright ©: University of Illinois CS 241 Staff37 Wait 2.5 seconds for something to appear on standard input

CS 241Copyright ©: University of Illinois CS 241 Staff38 Poll High-resolution sleep function  0 nfds  Positive timeout Wait until descriptor(s) become ready  nfds > 0  timeout INFTIM or -1 Wait until descriptor(s) become ready or timeout occurs  nfds > 0  Positive timeout Check descriptors immediately (poll)  nfds > 0  0 timeout

select() vs. poll() Which to use? BSD-family (e.g., FreeBSD, MacOS)  poll() just calls select() internally System V family (e.g., AT&T Unix)  select() just calls poll() internally CS 241Copyright ©: University of Illinois CS 241 Staff39