03-networking
03-networking
Fall 2024
Networking Overview
Tyler Bletsch
Duke University
2
Network organization
3
Connectivity on the Internet
• A point-to-point mesh?
• Clearly not sustainable for large networks
▪ N2 links required
▪ Add new endpoint: new link added to all existing endpoints
4
Network Structure
• Need to share infrastructure!
• Routers and switches (intermediate nodes) allow sharing
Home
network
Mobile
network
Regional ISP
e.g., corporate
network Global ISP
5
Internet Backbone
• From Wikipedia:
6
Usage Models
• Network endpoints run application programs
▪ Web browser, email client, ssh, etc.
• Client / Server model
▪ Client endpoints requests a service from a server
▪ E.g. client / server web page service
• Peer-to-peer (P2P)
▪ Direct client communication (e.g. Skype, BitTorrent)
7
Packet Switched Routers
Router
8
Managing Complexity
• Very large number of computers
• Incredible variety of technologies
▪ Each with very different constraints
• No single administrative entity
• Evolving demands, protocols, applications
▪ Each with very different requirements!
• How do we make sense of all this?
9
Networking layers
10
Layering
• We see layers of abstraction
• Separation of concerns
▪ Break problem into separate parts
▪ Solve each one independently
▪ Tie together through common interfaces: abstraction
▪ Encapsulate data from layer above inside data from layer below
▪ Allow independent evolution
11
Layering
• We see layers of abstraction
• Separation of concerns
▪ Break problem into separate parts
▪ Solve each one independently
▪ Tie together through common interfaces: abstraction
▪ Encapsulate data from layer above inside data from layer below
▪ Allow independent evolution
12
Layering done wrong invites
security vulnerabilities!
• Layering is a form of modularity; modularity is good
IF and ONLY IF
you don’t make any dangerous assumptions!
• Rule of thumb:
Be strict in what you send and check carefully what you receive
13
OSI Reference Model
14
TCP/IP Model
15
Layer 1 & 2
• Layer 1: Physical Layer Examples: Ethernet, 802.11 WiFi
▪ Encoding of bits to send over a single physical link (the part of the spec that says how to send bits)
16
Ethernet/WiFi and MAC addresses
• Each network interface has a MAC address (“Media Access
Control”): a 48-bit value burned into network card; globally unique
▪ First 3 bytes tell the manufacturer (OUI: Organizationally Unique Identifier)
▪ Last 3 bytes are made to be unique by that manufacturer
• Usually written as colon-delimited hex: BC:5F:F4:2B:E9:68
• Only meaningful on a single local area network (wired or wireless)
• Not transmitted across internet
Windows
Linux
17
Layer 1/2 demo: ARP
• Address Resolution Protocol (ARP): how we figure out the layer 2
address (MAC address) for a given layer 3 address (IP address)
▪ Can inquire to see known MAC addresses
▪ Can use OUI (first 3 bytes) to check manufacturer of devices!
http://www.whatsmyip.org/mac-address-lookup/ 18
Layer 3 Example: Internet Protocol (IP)
(how to send packets between networks)
19
IPv4 addresses
• IPv4 address is 32-bit address that is (theroetically) globally unique;
identifies interface on the internet.
• Written as “dotted decimal” of the four bytes, e.g. “141.9.68.24”.
▪ So each number (“octet”) can be 0-255.
• Subnets
▪ An address can have its bits divided into network and host.
▪ We describe a network in dotted decimal with a suffix saying how many bits
are in the network part, e.g.: 181.41.0.0/18 – this is a subnet.
▪ A mask of one bits covering the network portion is called the netmask;
for 181.41.0.0/18, the netmask would be 255.255.192.0
▪ The number of hosts that fit in a subnet is 232-n – 2
(Minus two is because the all-zeroes host and all-ones host are special)
▪ IP address assignment is hierarchical: Countries get IP ranges and assign to
registrars who then divide them among customers (ISPs, companies, etc.).
▪ The country of Aruba has 181.41.0.0/18 and a few others.
For a long time, IBM had 9.0.0.0/8.
20
Modern caveats (1)
• Some IP addresses are special:
▪ Loopback: 127.0.0.1 always refers the machine you’re on
(actually, it’s all of 127.0.0.0/8)
▪ Private: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 – not allowed on internet
▪ Link-local: 169.254.0.0/16 – auto-assigned when no network services are up
▪ Others (see IANA IPv4 Special-Purpose Address Registry)
▪ Have just one “real” public IP address at network boundary, NAT router
192.168.0.1
assign private IP addresses internally and translate at border
192.168.0.10 192.168.0.12
▪ Extremely common – real direct internet connections are rare Host Host
(this is good, as NAT doubles as a firewall) 192.168.0.11
Host
21
Modern caveats (2)
• IP-to-interface mapping is actually more flexible:
▪ For performance/reliability, an IP may be span multiple interfaces
▪ For manageability reasons, an interface may have >1 IP address
22
Figure from Wikipedia “IPv6”
Looking at real configs: Windows
• MAC address
• IPv6 address (link local – not routed to
internet in this config)
• IPv4 address (NAT routed private IP)
• Subnet mask (shows this is a /24 network)
• DHCP lease info
• Gateway: IP address we sent stuff to go
get to the internet (NAT router in this
case)
• DNS server: IP address we look up names
with (my router does this too in this case)
23
Looking at real configs: Linux
• MAC address
• Subnet mask (show this is a /24 network)
• IPv4 address (NAT routed private IP)
• IPv6 address (link local – not routed to
internet in this config)
• DNS server: IP address we look up names
with (my router does this too in this case)
• Gateway: IP address we sent stuff to go
get to the internet (NAT router in this
case)
24
Layer 4 Example: TCP/UDP
(how to establish a logical channel, maybe even a reliable channel)
Below: Sending data between two computers via a raw TCP socket using the ‘netcat’ (nc) tool.
25
Connectionless vs. Connection
• Connectionless transport layer
– Very similar to plain layer 4 (IP)
– Not much additional service provided on top
– But less networking stack software overheads as a result
– Standard example: User Datagram Protocol (UDP)
• Connection-oriented transport layer
– Provides error-free, reliable communication
– Like having a UNIX pipe between processes on two different machines
– Standard example: Transmission Control Protocol (TCP)
26
UDP – Connectionless service
• User Datagram Protocol
– Essentially allows applications to send IP datagrams
– With just slightly more encapsulation
• UDP transmits segments
– Simply 8 byte header followed by payload
27
Ports
• Allows application-level multiplexing of network services
• Processes attach to ports to use network services
– Port attachment is done with “BIND” operation
• Destination port
– When a UDP packet arrives, its payload is handed to process attached to the
destination port specified
• Source port
– Mainly used when some reply is needed
– Receiver can use the source port as the dest port in reply msg
28
UDP – What it does NOT do
• NO Flow control
• NO Error control
• NO Retransmission on receipt of bad segment
29
TCP – Connection-oriented Service
• Transmission Control Protocol
▪ Designed for end-to-end byte stream over unreliable network
▪ Robust against failures and changing network properties
• TCP interface to user programs
▪ Manages TCP streams and interfaces to the IP layer
▪ Accepts user data streams from processes
▪ Breaks up into pieces not larger than 64 KB
• Often 1460 data bytes to fit in 1 Ethernet frame w/ IP + TCP headers
▪ Sends each piece separately as IP datagram
▪ Destination machine reconstructs original byte stream
▪ Handles retransmissions & re-ordering
▪ Provides error-free, reliable communication
• Result:
▪ Can think of link like a pipe: Put data in one end, other side takes it out
30
TCP Service Model
• TCP service setup as follows:
– Two endpoint processes create endpoints called sockets
– Each socket has an address: IP address of host + 16-bit port
– API functions used to create & communicate on sockets
• Ports
– Numbers below 1024 called “well-known ports”
• Reserved for standard services, like FTP, HTTP, SMTP
http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml
31
TCP Service Model (2)
• TCP connections are full-duplex & point-to-point
– Simultaneous traffic in both directions
– Exactly 2 endpoints (no multicast or broadcast)
• TCP connection is a byte stream, not message stream
– Receiver has no way to know what granularity bytes were sent
– E.g. 4 x 512 byte writes vs. 1 x 2048 byte write
– It can just receive some # of bytes at a time
– Just like UNIX files!
• TCP may buffer data or send it immediately
– PUSH flag indicates to TCP not to delay transmission
– TCP tries to make a latency vs. bandwidth tradeoff
32
TCP Protocol
• TCP sequence number underlies much of the protocol
– Every byte sent has its own 32-bit sequence number
• TCP exchanges data in segments
– 20-byte fixed header (w/ optional part)
– Followed by 0 or more data bytes
– TCP can merge writes into one segment or split a write up
– Segment size limitations:
• Must fit (including header) inside 65,515 byte IP payload
• Networks have a MTU (max transfer unit)
– e.g. 1500 bytes for Ethernet payload size
35
Demo: Wireshark
• Can observe packets in transit with network sniffer, e.g. Wireshark
Below: Trace of a Firefox request for http://www.gnu.org/
36
Network layer summary
Get http://pics.com/dog.jpg
(overall goal)
37
One more thing...
VLANs
• Everyone on the same layer 2 network is in one “broadcast domain”
▪ Equals one IP subnet (e.g. 192.168.0.0/24 would be one network)
▪ No IP routing to go point-to-point; a network switch delivers directly
Host Host Host Host Host Host Host Host Host Host
• But we don’t want to buy a different physical switch for each one!!
38
One more thing...
VLANs
• Logically separate layer 2 networks
• Switch ports can be:
▪ Access ports: can only see one VLAN, aren’t aware of VLAN concept
▪ Trunk ports: end point includes a VLAN tag in packet header to indicate which
VLAN it wants to talk to; interprets such headers on incoming packets
http://www.examcollection.com/certification-training/ccnp-configure-and-verify-vlans-and-trunking.html
39
Dynamic Host Configuration Protocol
(DHCP)
(It’s just one slide)
40
Dynamic Host Configuration Protocol (DHCP)
• DHCP: Allow hosts to enter a network and ask “what IP should I use
for myself?”
• How it works:
1. Client sends an IP broadcast “DISCOVERY” request
(destination 255.255.255.255 UDP port 67)
2. DHCP server on network sends an “OFFER” with
IP address and other config (gateway router,
DNS servers, maybe other stuff)
• Note: multiple offers might be provided by multiple
DHCP servers (but usually it’s just one)
3. Client sends a broadcast REQUEST for one of the offers
4. DHCP server sends ACKNOWLEDGE back
5. Client now has an IP address and basic config info
• DHCP can also be used to start network-boot (PXE), commonly used
for diskless clusters, OS auto-install, etc.
41
Domain Name System (DNS)
(Many slides)
42
Purpose of DNS
• Map an easy-to-remember name to an IP address
• Implications
▪ Without DNS, to send IP packet, must remember IP addresses manually!
...and they could change!
▪ With DNS, we can use the name directly:
• www.google.com or www.cnn.com
• DNS also provides inverse look-up that maps IP address to name
43
Before there was DNS...
• There was the HOSTS.TXT file (on Linux today as /etc/hosts)
• Maintained at SRI Network Information Center (NIC)
• Before DNS (1985), the name-to-IP address was done by
downloading this single file from a central server with FTP
▪ No hierarchical structure to the file
▪ Still works on most OSes; can be used to define local names
Security implications...
(Do the hosts + netcat demo)
44
Domain Namespace
.(root)
Top-level domains
org edu com gov
duke mit
ece cs
www smtp
45
Domain Namespace
.(root)
Top-level domains
org edu com gov
duke mit
ece cs
www smtp
46
Fully Qualified Domain Names
.(root)
Top-level domains
org edu com gov
duke mit
ece cs
www smtp
47
Top-Level Domains
• Three types of top-level domains:
▪ Generic Top Level Domains (gTLD)
• 3 char code indicates the function of the organization
• Use primarily within the US (e.g. gov, mil, edu, org, com, net)
▪ Country Code Top Level Domain (ccTLD)
• 2 char country or region code (e.g. us, jp, uk)
▪ Reverse Domain
• Special domain used for IP address-to-name mapping
• in-addr.arpa
• More than 200 top-level domains
48
DNS Architecture
• Domain name space
▪ Domain namespace is a hierarchical tree structure, a domain can be
delegated to an organization
• Name servers
▪ Domain name hierarchy exists only in the abstract
▪ A host's name servers are specified in /etc/resolv.conf
• Resource records: (Name, Value, Type, Class, TTL)
▪ Name (“duke.edu”) and Value (“152.3.72.104”)
▪ Type specifies how the “Value” should be interpreted. Examples:
• “NS” = Name Server: name is a domain and value is name of authoritative
name server for this domain
• “A” = Address: machine name and IP address
▪ Class: record type (usually “IN” for Internet)
▪ TTL: how long should the record be cached
49
Resource Records
cs.virginia.edu
server
51
Name Servers
• Each zone has a primary and secondary name server
▪ For reliability
▪ Primary server maintains a zone file with zone info
• Updates made to the primary server
▪ Secondary server copies data stored at the primary server
• Adding a new host:
▪ When new host is added (e.g. “newmachine.ece.duke.edu”)
▪ Administrator adds the IP info on the host (IP address, name) to a
configuration file on the primary server
52
Root Name Servers
• Root name servers know how to find authoritative name servers for
all top-level zones
• There are 13 (virtual) root name servers
• Root servers are critical for proper functioning of name resolution
53
Domain Name Resolution
1. User program issues a request for
the IP address of a hostname
gethostbyname()
query to the name server of the host HTTP IP address (128.143.71.21) Resolver
IP address (128.143.71.21)
authorized to answer the query.
(neon.tcpip-lab.edu)
Hostname
▪ If yes, it responds.
▪ Otherwise, it will query other name
servers, starting at the root tree
54
Inverse Query
.(root)
duke mit
in-addr
ece cs
www smtp
150.45.38.128
55
Caching
• To reduce DNS traffic, name servers cache info
▪ e.g. Domain name / IP address mappings
• When entry for a query is cached, the server does not contact other
servers
• Note: if an entry is sent from a cache, the reply from the server is
marked as “unauthoritative”
• Caching-only servers
▪ Only purpose is to cache results
▪ Do not contain zone info or a zone database file
56
Modern follow-ons
• DNS with DHCP integration
▪ When a new host uses DHCP to get on the network, the DHCP server can tell
the DNS server about it, then the DNS server can answer requests for that
host by name
• Multicast DNS (mDNS) and Link-Local Multicast Name Resolution
(LLMNR)
▪ Resolve hostnames when there’s no local DNS server
▪ Allows “automagic” host discovery on individual networks
▪ Zero configuration – they’re self-organizing protocols
• DNSSEC: DNS security (next slides)
▪ Provides integrity, not confidentiality
• DNS over HTTPS (DoH): Very new standard, also provides encryption
▪ Provides integrity and confidentiality
57
DNSSEC
• Problem: how do I know this DNS record I got is authentic?
• DNSSEC: A commonly deployed protocol to provide DNS integrity
▪ “Sign” the record with asymmetric cryptography,
use a “chain of trust” to show that the signature is valid.
▪ (We haven’t covered these concepts yet – we’ll see it when we cover crypto)
Adapted from “High-Level Awareness of DNSSEC” by Phil Regnauld and Joe Abley, KENIC/NSRC Workshop, 2011 58
DNS security issues covered by DNSSEC
Adapted from “High-Level Awareness of DNSSEC” by Phil Regnauld and Joe Abley, KENIC/NSRC Workshop, 2011 59
Quick intro to socket programming
60
Sockets
• How do user programs request to interact with networks?
• We can program using network sockets
▪ For creating connections and sending / receiving messages
▪ Often follows a client / server pattern
61
Client-Server Model
• Common communication model in networked systems
▪ Client typically communicates with a server
▪ Server may connect to multiple clients at a time
• Client needs to know:
▪ Existence of a server providing the desired service
▪ Address (commonly IP address) of the server
• Server does not need to know either about the client
62
Client-Server Overview
Client side Server side
Kernel
TCP TCP Transport Layer
IP IP Network Layer
Ethernet Network
64
TCP Socket API
TCP Server
socket()
bind()
TCP Client
listen()
socket()
accept()
connect() Establish TCP connection
Blocks until
connection from client
write() Data (request)
read()
Do work
Data (response)
write()
read()
close() 65
Example – UNIX TCP sockets
Primitive Meaning
socket() Create a new communication end point
bind() Attach a local address to a socket
listen() Announce willingness to accept connections; give queue size
accept() Block the caller until a connection attempt arrives
connect() Actively attempt to establish a connection
send() Send some data over the connection
recv() Receive some data from the connection
close() Release the connection
66
Server-Side Structure
• Often follows a common pattern to serve incoming requests
pid_t pid;
int listenfd, connfd;
listenfd = socket(...);
bind(listenfd, ...);
listen(listenfd, ...);
for ( ; ; ) {
connfd = accept(listenfd, ...); // blocking call
close(connfd);
exit(0); // child terminates
}
close(connfd); // parent closes connected socket
} 67