NETWORK SOFTWARE Two Categories CLIENT Network program/app that connects to other apps; to services/servers SERVER (SERVICE/HOST/ORIGIN) Network program/app that other apps connect to; a SERVER of a service Browsers are clients; - Client uses TCP/IP protocol to connect to server. - Client sends HTTP request packages to server. - Server returns HTTP response packages to client. If requested resources include dynamic scripts, then server calls script engine first. - Client DISCONNECTS from server, starts rendering HTML. - Server CLOSES the CONNECTION after sending response to client, then listens/waits for next request. STANDARD MODELs There are TWO (2) starndard models of Computer Networking 1. OSI 2. Internet Protocol Suite a.k.a. "TCP/IP Stack" Layer Names and Numbers https://en.wikipedia.org/wiki/Internet_protocol_suite#Layer_names_and_number_of_layers_in_the_literature OSI MODEL Open Systems Interconnection (OSI) Model; SEVEN (7) Layer OSI Model; a "Layered Network Model"; ORTHOGONAL LAYERS; CONTENT of each LAYER is MEANINGLESS to all other LAYERS; E.g., a sockets app is independent of the data that is physically transmitted (serial, thin Ethernet, AUI, whatever) because that's handled at lower layers; network hardware and topology is transparent to socket app (and its programmer). https://en.wikipedia.org/wiki/OSI_model Layer Struct Name Protocol ----- ----------- -------- 7. Application |\ HTTP, FTP, DHCP, SSH, SMTP ... * 6. Presentation |- Data ASCII, EBCDIC, JPEG, MPEG, ... 5. Session |/ NFS, NetBIOS, RPC, SQL, ... 4. Transport Segment/Datagram TCP/UDP * H2H Transport; crosses boundaries 3. Network Packet (Datagram) IP, ARP, IGMP,... * Internet 2. (Data) Link Frame/PDU Ethernet, PPP, HDLC, Token-Ring, ... * P2P Link; within a boundary 1. Physical Bit Ethernet, Frame-Relay, ATM, serial, ... PDU is "Protocol Data Unit" H2H is "Host to Host" P2P is "Peer to Peer" "Host Layers": 4,5,6,7 "Media Layers": 1,2,3 "Link Layers": 1,2 Condensible to FOUR (4) per Unix philosophy (& Cisco) Internet Protocol Suite a.k.a. "TCP/IP Stack" https://beej.us/guide/bgnet/html#lowlevel Layer Handler ----- ------- Application (telnet, ftp, etc.) App H2H Transport (TCP, UDP) Kernel Internet (IP and routing) Kernel Network Access (Ethernet, WiFi, or whatever) HW Data Encapsulation, e.g., Ethernet(IP[UDP{TFTP}]) Internet Protocol Suite a.k.a. "TCP/IP Stack" (*) OSI Layers 2+3+4+7; a SEPARATE MODEL for computer neworking; FOUR (4) Layers. https://en.wikipedia.org/wiki/Internet_protocol_suite IPS Layer Struct Name Protocol OSI Layer(s) --------- ----------- -------- ------------ 7. Application Data HTTP, FTP, DHCP, SSH, SMTP ... L5+L6+L7 (Sessn+Prsntn+App) 4. H2H Transport Segment/Datagram TCP/UDP L4 (Transport) 3. Internet Packet (Datagram) IP, ARP, IGMP, ... L3 (Network) 2. Link/Network Frame (PDU) Ethernet, PPP, ... L1+L2 (PHY+DL) URL Uniform Resource Locator (URL) is a specific type of Uniform Resource Identifier (URI), which is a string of characters used to identify a resource. https://en.wikipedia.org/wiki/URL scheme:(//{user[:password]@}host[:port])(/path)(?query)(#fragment) scheme://host(:port#)/path/.../(?query-string)(#anchor) schemes Underlying protocol (such as HTTP, HTTPS, FTP) host IP or domain name of HTTP server port# Default port is 80; can omit if default, else must specify, e.g., http://www.foobar.com:8080/ path Relative path of Resource query-string Data sent to server per GET method of HTTP Protocol anchor Anchor (Bookmark) Query Delimiter is `&` or `;` key1=value1&key2=value2 FORM submission GET method sends data to server in URL of the request POST method sends data to server in body of the request DMZ a.k.a. Perimeter Network; physical or logical subnet that contains and exposes external-facing services to an untrusted network, e.g, the Internet; "DMZ host" of a home router is a host (one IP address) on the LAN that has ALL traffic sent to it which is not otherwise forwarded to other LAN hosts. https://en.wikipedia.org/wiki/DMZ_(computing) DHCP Reservation a.k.a. Static {DHCP/Route List/Port Forwarding} Bastion Host (Jump Box) a special purpose, hardened computer on a network specifically for withstanding attack; for perimeter access control security; typically a proxy server; placed either outside a firewall or in a DMZ subnet; any server that is fully exposed to attack (by being on the public side of the DMZ), unprotected by a firewall or filtering router; AWS instance in public subnet, typically accessed using SSH or RDP; SSH Jump Host is set up using ProxyCommand with OpenSSH (execute ssh command on remote host to jump to the next host and forward all traffic through; `ssh -J user1@host1:port1 user2@host2:port2`) https://en.wikipedia.org/wiki/Bastion_host DNS The Domain Name System (DNS); mapping NAMEs (domain) to NUMBERs (IP); manage the map btwn the two namespaces (NAME/NUMBER); a HIERARCHICAL DECENTRALIZED NAMING SYSTEM (1985) for resources connected to an IP network; associates various information with domain names; maps names to numbers. DNS NAME SERVERs are responsible for ANSWERing DNS QUERIES; translating a queried domain (name) to its (numerical) IP Address. To decentralize the DNS database, the DNS system DELEGATES its RESPONSIBILITY by designating AUTHORITATIVE NAME SERVERs (SOA record type; Start Of Authority) per DOMAIN. The domain's SOA Name Server further delegates responsibility for that domain to a DELEGATION SET of 4 Name Servers (NS record type). Network administrators may further DELEGATE AUTHORITY over sub-domains of their allocated name space to other name servers. Referred to as "Delegating responsibility for a subdomain to (name servers at) a HOSTED ZONE", or "Delegating a subdomain to other name servers." This mechanism provides distributed and fault tolerant service and was designed to avoid a single large central database. DNS also specifies the technical functionality of the DATABASE SERVICE that is at its core. It defines the DNS protocol, a detailed spec of the DATA STRUCTURES and DATA COMMUNICATION EXCHANGES used in the DNS, as part of the INTERNET PROTOCOL SUITE. https://en.wikipedia.org/wiki/Domain_Name_System DOMAIN NAME https://en.wikipedia.org/wiki/Domain_name DNS Root Zone (.) https://en.wikipedia.org/wiki/DNS_root_zone Nameless top-level DNS zone in the hierarchical namespace of the DNS. Denoted by the trailing dot (.) of a FQDN (foo.com.) . TLD (Top Level Domain; last-dot-name); https://en.wikipedia.org/wiki/Top-level_domain IANA (Internet Assigned Numbers Authority) controls these. GENERIC (gTLD): .com, .gov, .org, ... COUNTRY-CODE (ccTLD): .uk, .cn, ... Root Zone Database represents the delegation details of top-level domains. http://www.iana.org/domains/root/db gTLD https://en.wikipedia.org/wiki/Generic_top-level_domain ccTLD https://en.wikipedia.org/wiki/Internationalized_country_code_top-level_domain SLD (Second Level Domain) Second-to-last dot-name; typically the name of the organization, but can be other if country code (ccTLD) or such is used: google if google.com, gov if .gov.uk, ..., i.e., {gTLD}.{ccTLD} or such. FQDN (foo.com.) "Fully Qualified Domain Name" Unambiguous, complete domain name. Note the trailing dot; the (nameless) DNS root itself. . The (nameless) DNS root domain. com. com is a TLD foo.com. foo is a SLD, and the Root/Main/Parent Domain. bar.foo.com. bar is a SUBDOMAIN. Zone Apex (foo.com) The Zone Apex is the Root/Naked/Parent DOMAIN of a HOSTED ZONE. Must have an A-type record (IPv4 Address); required per DNS RFC (RFC1033) HOSTED ZONE any distinct, contiguous portion of the domain name space in the DNS for which ADMINISTRATIVE RESPONSIBILITY has been delegated to a single manager. E.g., Route 53 > Hosted Zones; must contain an NS record. ZONE FILE A structured file storing a (Hosted) Zone's DNS records; a component of the DNS database. Although not intended to be a general purpose database, DNS can store records for other types of data; DNSSEC records, Responsible Person (RP) records, Generic text strings (TXT); also used to combat unsolicited email (spam) by storing a real-time BLACKHOLE LIST (DNSBL or RBL). RECORD TYPEs stored in the DNS database (the most common) SOA (Start of Authority) - authority-domain Server that supplied the data for the zone - domain-of-zone-admin Zone Administrator (Responsible Person; RP) - zone-serial-number Current version of the data file - Number of seconds: refresh-time Seconds to wait before checking for updates retry-time Failed zone transfer expire-time Refresh before expire negative caching TTL TTL on resource records FORMAT: [authority-domain] [domain-of-zone-admin] [zone-serial-number] [refresh-time] [retry-time] [expire-time] [negative caching TTL] E.g., ns-381.awsdns-47.com. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400 NS (Name Server) This record lists the DELEGATED SET of 4 AUTHORITATIVE NAME SERVERS, which answers DNS queries from data configured by an original source, vs from another name server's cache of data. Every DNS zone must be ASSIGNED a set of Authoritative Name Servers. Every PARENT DOMAIN zone must include an NS record. SUBDOMAINS can have their own Hosted Zone, containing their own NS record, listing their own Delegated Set of four (4) Authoritative Name Servers. Such requires DELEGATING RESPONSIBILITY (from the parent) to their Authoritative Name Servers by adding an NS record at the Parent Domain, which lists the subdomain's Delegation Set. So, the Parent Domain (Zone Apex) would have TWO (2) NS records; one for itself (foo.com) and one for the subdomain (bar.foo.com). This is more flexible, having more options than the alternate method. Alternately, subdomains can be established per A-record and CNAME-record in the Parent Domain (Zone Apex). Some Hosted Zone providers offer additional, proprietary setups. E.g., AWS Route 53 conjures an "Alias" record, a hybrid which maps (domain) name to (resource) name, kind of like a CNAME, yet reliably satisfies the DNS requirement that every domain name has an A-type record; doing so all in one "answer" (response to DNS record query). CNAME (Canonical Name; CName) Used to resolve one subdomain name to another name; point several to one; DNS does not allow CNAME type record for Main/Naked Domain Name (Zone Apex) A (Address; IPv4 Address) Translates domain NAME to NUMBER (IPv4 Address); DNS requires the Main/Naked Domain Name (foo.com) to have an A (type) record. While vital, it's not much help in virtual environments where IP addresses are transient. AWS conjured their own proprietary record type to handle this; "Alias Record". AAAA (Address; IPv6 Address) PTR (Pointer; for reverse DNS lookups) MX (SMTP Mail Exchanger) Alias (@ AWS) An AWS-Route53–specific DNS extension; a hybrid of A-type and CNAME-type records; a mapping of domain NAME to (AWS) resource NAME; avoids the problem of transient (unreliable) IP addresses in virtual/containerized environments. Yet reliably satisfying DNS requirements for an A-type record. Parent and child (sub)domain(s) are both allowed Alias type records. LIMITATION: The target (name) must be ELB|S3|CloudFront E.g., foo.com => elb1234.elb.amazonaws.com DNS RESOLUTION PROCESS and URLs 1. OS checks `hosts` file for URL mapping/resolution. If none, 2. OS checks if any cache exists in the DNS. If none, 3. OS finds the first DNS resolution server in its TCP/IP settings, which is likely a local DNS server, e.g., Gateway Router; if domain name present, then resolves IP. This DNS resolution is AUTHORITATIVE. Else, 4. if the local DNS server doesn't contain the domain name but a mapping relationship exists in the cache, the local DNS server returns resolved IP. This DNS resolution is NOT authoritative. 5. If the local DNS server cannot resolve this domain name either by configuration of regional resources or cache, it will proceed to the next step, which depends on the local DNS server's settings. https://astaxie.gitbooks.io/build-web-application-with-golang/content/en/03.1.html Whether or not the local DNS server enables forwarding, the IP address of the domain name always returns to the local DNS server, and the local DNS server sends it back to the client. Round Robin (RR) DNS A scheme whereof one domain name is mapped to a list of IP addresses; the RR DNS Server answers domain name queries with a randomly chosen IP address from a pool of redundant IP hosts (servers hosting identical services). Used as a technique of LOAD DISTRIBUTION or FAULT-TOLERANCE PROVISIONING; often used to LOAD BALANCE requests between a number of Web servers; "A poor-man's load balancer". IP Addresses IPv4 32-bit; 4 billion addresses IPv6 128 bit; 340 undecillion addresses; not well supported DOMAIN REGISTRAR An authority that ASSIGNs domain names directly under one or more top-level domains (TLDs); REGISTERS domain name with InterNIC, an IANA service; WhoIS database containing all registered domain names ICANN + IANA ("Internet Corp for Assigned Names & Numbers" + "Internet Assigned Numbers Authority") Manages the DNS; ICANN functions per contract with IANA; ICANN is a nonprofit org for coordinating the maintenance and procedures of several databases related to internet namespaces (names and numbers; domains & IPs); performs technical maintenance work of the Central Internet Address pools and DNS Root Zone registries per contract with IANA. CONTRACT with US gov ENDED @ 2016; regarding IANA stewardship between ICANN and NTIA (US National Telecommunications and Information Administration; Dept of Commerce); a "global multi-stakeholder community" is taking over. https://en.wikipedia.org/wiki/ICANN IPv6 Special Addresses https://tools.ietf.org/html/rfc4291#section-2.7 ::1 127.0.0.1 @ IPv4; loopback address, fe00::0 Class E @ IPv4; Scope 0 (Reserved); reserved for future use. ff02::1 192.168.x.255 @ IPv4; Reserved Multicast; Scope 2 (Link-local). ff02::2 All IPv6 routers; Reserved Multicast; Scope 2 (Link-local). ff02::3 Unassigned; formerly all hosts (excl. routers); Reserved Multicast; Scope 2 (Link-local) HTTP PROTOCOL Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, and hypermedia information systems; HYPERTEXT is structured text that uses logical links (HYPERLINKS) between nodes containing text. HTTP is the protocol to exchange or transfer hypertext. HTTP is the foundation of data communication for the World Wide Web; for communication between browser and web server; based on the TCP protocol; usual/default SERVER PORT 80; utilizes the REQUEST-RESPONSE MODEL; clients send requests and servers respond; clients always setup new connections and send HTTP requests to servers. Servers do NOT connect to clients proactively, nor establish callback connections. A Client/Server CONNECTION between a client and a server CAN BE CLOSED BY EITHER SIDE. HTTP is a STATELESS protocol, i.e., for any two connections (requests/responses), the server has no knowledge about the relationship between the two, even if both came from the same client. Thus the need for web apps to handle SESSION management, e.g., use COOKIES to maintain state (of connections). All TCP attacks will affect HTTP communications at the server. E.g., SYN flooding, DoS and DDoS attacks. HTTP was initiated by Tim Berners-Lee at CERN in 1989. Standards development of HTTP was coordinated by the Internet Engineering Task Force (IETF) and the World Wide Web Consortium (W3C), culminating in the publication of a series of Requests for Comments (RFCs). The first definition of HTTP/1.1, the version of HTTP in common use, per RFC 2068 in 1997; obsoleted by RFC 2616 in 1999; again by the RFC 7230 family of RFCs in 2014; the successor, HTTP/2, was standardized in 2015, and is now supported by major web servers and browsers over TLS using ALPN extension, where TLS 1.2 or newer is required. HTTP https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol REQUEST METHODs https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods HTTP REQUEST PACKAGE 3 parts: REQUEST LINE, REQUEST HEADER, and BODY (@ POST, not GET). GET /domains/example/ HTTP/1.1 // REQUEST LINE: request-method URL protocol/version Host:www.iana.org // domain name; 1st line of REQUEST HEADER User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTM... // browser information Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 // mime types acceptable to client Accept-Encoding:gzip,deflate,sdch // stream compression Accept-Charset:UTF-8,*;q=0.5 // client-side character set // BODY, request resource arguments (for example, arguments in POST) HTTP RESPONSE PACKAGE HTTP/1.1 200 OK // STATUS LINE: protocol/version status-code status-reason Server: nginx/1.0.8 // WEB SERVER SOFTWARE and its VERSION in the server machine Date:Date: Tue, 30 Oct 2012 04:14:25 GMT // RESPONDED TIME Content-Type: text/html // RESPONDED DATA TYPE Transfer-Encoding: chunked // if "chunked", Content-lenght NOT given; see spec Connection: keep-alive // "Connection" | keep-alive | close Content-Length: 90 // length of body -, / => _ JWT segments (3) are Base64URL encoded IPFS (P2P) https://ipfs.io/ IP File System; URI identifies content, not location; replaces HTTP; IPFS network finds the nodes having the data, using DHT (Distributed Hash Table), retrieve it, and verifies using the hash (@ URI) that it's the correct data. IPFS network becomes a finely-grained, trustless, distributed, easily federated Content Delivery Network (CDN) https://ipfs.io/ipfs/QmNhFJjGcMPqpuYfxL62VVB9528NXqDNMFXiqN5bgFYiZ1/its-time-for-the-permanent-web.html DHT (Distributed Hash Table) a lookup service similar to a hash table (table of key-value pairs); participating nodes can efficiently retrieve the value associated with a given key; responsibility for maintaining the mapping from keys to values is distributed among the nodes, in such a way that a change in the set of participants causes a minimal amount of disruption; allows a DHT to scale to extremely large numbers of nodes and to handle continual node arrivals, departures, and failures. DHTs form an infrastructure that can be used to build more complex services, such as anycast, cooperative Web caching, distributed file systems, domain name services, instant messaging, multicast, and also peer-to-peer file sharing and content distribution systems. Notable distributed networks that use DHTs include BitTorrent's distributed tracker, the Coral Content Distribution Network, the Kad network, the Storm botnet, the Tox instant messenger, Freenet and the YaCy search engine. https://en.wikipedia.org/wiki/Distributed_hash_table DHCP (Dynamic Host Configuration Protocol) provides an IP (Internet Protocol) host with its IP address and other related configuration information such as the subnet mask and default gateway. DHCP Reservation a.k.a. Static {DHCP/Route List/Port Forwarding} Static IP addresses (e.g., at gateway router) for any nodes (e.g., downstream router) to forward ports to. Else manually configuring IPs @ node OS. Static IPs MUST BE OUTSIDE outside the automatic (DHCP) address range (of the gateway router). UPnP port forwards may OVERWRITE static port forwards. If your static port forwarding is important, turn off UPnP. NAT (Network Address Translation) a process to map IP addresses to/from internal/external (LAN/WAN) networks; typically handled at gateway node (router); allows for a firewall between the two, and for IP address reuse. Port (Range) Forwarding a.k.a. "Port Mapping" a NAT application that redirects a communication request from one address and port number (ADDR:PORT) combination to another WHILE packets are TRAVERSING A NETWORK GATEWAY, such as a router or firewall. UPnP is the easiest (automatic) way to handle Port Forward settings. Applications supporting UPnP automatically request the (gateway/NAT) router to open/close the port they're listening on whenever the application starts/stops. Automatic port forwarding with UPnP means you needn't manually script IP addresses, ports, nor any such parameters, neither at client PC nor router. (The application using (UPnP) Port Forwarding must be in the list of Windows Firewall exceptions!) REF: http://www.portforward.com http://www.dd-wrt.com/wiki/index.php/Port_Forwarding Port Triggering (Triggered Port Forwarding) Forwarding requests to a range of ports to whatever machine connected to a remote host on the Trigger Port. It's semi-automatic and doesn't care about static IP addresses. Used for web services having a known/unique port. E.g., AIM client machine/app sends request to, e.g., 207.234.129.65:5190 (trigger port is 5190), so setup Port Triggering @ router to forward on that trigger to local ports (range) 4117-4443. (The local port range is specified by the client app.) NAT-PMP (NAT Port Mapping Protocol) Implemented in many network address translation (NAT) routers. NAT-PMP allows a computer in a private network (behind a NAT router) to automatically configure the router to allow parties outside the private network to contact it. NAT-PMP runs over UDP port 5351. It essentially automates the process of port forwarding. NAT-PMP is the precursor to Port Control Protocol (PCP); an alternative to Internet Gateway Device (IGD) Standardized Device Control Protocol, created by Apple, 2005. Port Control Protocol (PCP) Newest scheme (2013) to solve NAT/port public/private WAN/LAN issues; to replace all prior/existing port forwarding schemes. MAC (Media Access Control) ARP (Address Resolution Protocol) http://linux-ip.net/html/ether-arp.html#ether-arp-overview @ IPv4; maps network (IP) addresses to hardware (MAC) addresses used by a data link protocol; interface between OSI Layer-2 (Data Link) and Layer-1 (Physical). The protocol operates below Layer 3 (Network); interface between Layer 3 and Layer 2; between Network and Data-Link. IP Traffic UNICAST A conversation between two hosts. Though there may be routers between them, the two hosts are carrying on a 'private' conversation. Common Unicast protocols: HTTP (web), SMTP (sending mail), POP3 (fetching mail), IRC (chat), SSH (secure shell), and LDAP (directory access) BROADCAST One destination IP addresses all hosts in a given network range; "chatty network traffic"; like shouting in a room. Used at the Ethernet (Layers 1,2) and the IP layer (Layer 3) Node a connection point, a redistribution point (e.g. data communications equipment), or a communication endpoint (e.g. data terminal equipment); a device that implements IPv6. The definition of a node depends on the network and protocol layer referred to. Router A networking node/device that forwards data packets between computer networks. Host Any node that is not a router. Each PC on the LAN is a host. CIDR Classless Inter-Domain Routing; a method for allocating IP addresses & routing; 1993; superceeded classful network design; to slow the rapid exhaustion of IPv4 addresses; CIDR notation: 192.168.2.0/24 (IPv4) IP Addresses + Ports (common) DHCP range (default) 192.168.1.100 - 192.168.1.149 Private IP Address RANGEs (rfc1918) 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) Typical Home setup ... 192.168.1.1 ... Gateway Router LAN (inside) IP Address 255.255.255.0 ... Subnet Mask (24 bit mask); allows 254 Host IDs 192.168.1 ... Network ID 192.168.100.1 ... DOCSIS Modem Router client referred to as 'host'; All on LAN have same 'Network ID', and each has unique 'Host ID'. Ports 80 Web server 21 FTP server 22 SSH server 5190 AIM server 5351 NAT-PMP, UDP Wikipedia https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing