Code Stuff

Summary

Stuff I getted asked about on interviews. It’s a compilation of things I learned across talking to many folks about paying me to do what I find interesting and am passionate about. I can never directly thank these people stumping me and prompting me to keep on learning and growing and getting better … THANK YOU !!!

TODOs

There are no “TODOs” I can think of on 01APR2019MON:

  1. One

Networking

Never ever have I talked with somebody and not had an exciting conversation about the various “network models” and “name the protocol” 🙂

Protocols

ICMP is a control protocol, meaning that it designed to not carry application data, but rather information about the status of the network itself. The best known example of ICMP in practice is the ping utility, that uses ICMP to probe remote hosts for responsiveness and overall round-trip time of the probe messages.

Both Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are transportation protocols, they are used to pass the actual data. The main difference between TCP and UDP is that TCP is a connection oriented protocol, it guarantees that all sent packets will reach the destination in the correct order.

UDP, on the other hand, is a connection-less protocol. Communication is datagram oriented, so the integrity is guaranteed only on the single datagram. Datagrams reach destination and can arrive out of order or don’t arrive at all. It’s generally used for real time communication, where a little percentage of packet loss rate is preferable to the overhead of a TCP connection.

Internet protocol suite

Application layer

BGP DHCP DNS FTP HTTP HTTPS IMAP LDAP MGCP MQTT NNTP NTP POP ONC/RPC RTP RTSP RIP SIP SMTP SNMP SSH Telnet TLS/SSL XMPP more…

Transport layer

TCP UDP DCCP SCTP RSVP more…

Internet layer

IP IPv4 IPv6 ICMP ICMPv6 ECN IGMP IPsec more…

Link layer

ARP NDP OSPF Tunnels L2TP PPP MAC Ethernet Wi-Fi DSL ISDN FDDI

ICMP

Internet Control Message Protocol

  1. ping

UDP

User Datagram Protocol

  1. Domain Name System (DNS)
  2. Simple Network Management Protocol (SNMP)
  3. Routing Information Protocol (RIP)
  4. Dynamic Host Configuration Protocol (DHCP)

TCP

Transmission Control Protocol

  1. World Wide Web (WWW)
  2. email
  3. File Transfer Protocol
  4. Secure Shell
  5. peer-to-peer file sharing
  6. streaming media

Classless Inter Domain Routing

CIDR – Classless Inter Domain Routing

Classless InterDomain Routing (CIDR) was invented to keep the Internet from running out of IP Addresses. The use of a CIDR notated address can easily represent classful addresses (Class A = /8, Class B = /16, and Class C = /24).

Private Addresses

There exist “ranges” of IP addresses that are reserved and you should know them in case you’re debugging stuff and you see for instance 192.168.1.100 which can’t be a “service on the web”.

Should you be so inclined you can use sipcalc (will probably have to install) to generate the ranges of IPs above like:

sipcalc 10.0.0.0/8

sipcalc 172.16.0.0/12

sipcalc 192.168.0.0/16

In April 2012, IANA allocated 100.64.0.0/10 for use in dedicated carrier-grade NAT scenarios.

Personally I think “localhost” (“home”) at 127.0.0.1 is private. Actually, any IPv4 address in 127.0.0.0/8 is a loopback address.

Additionally .0 (network space) and .255 (broadcast address) can’t be used. It’s slight more complicated and “addresses ending in 0 or 255” goes into greater detail.

And finally there is a largish set of addresses considered “special-use addresses“.

Linux

Load

Never ever have I talked with somebody and not had an exciting conversation about “load average” 🙂

Put very simply if you “magically” had all available CPU[s] 100% running process[es] (one process per CPU) and nothing else was wanting/needing those CPU[s] (unlikely but go with me here) then “load would equal the number of CPU[s]“.

Let’s make this real easy and forget the “average” part. It’s over 1, 5 and 15 minutes and uses a gnarly formula “exponentially damped/weighted moving average”1 and it doesn’t matter for the explanation.

Simply put “load” is “number of processes using or wanting to use the CPU[s]”. More specifically here are the possible “CPU states” (from man top search on Process Status) and the first three highlighted count towards “load”:

  1. D = uninterruptible sleep
  2. I = idle
  3. R = running
  4. S = sleeping
  5. T = stopped by job control signal
  6. t = stopped by debugger during trace
  7. Z = zombie

Here’s a link2 that shows the addition of “the origin of uninterruptible”.

The OS computes it and iterally stores it in file /proc/loadavg. man 5 proc and search on (go figure) /proc/loadavg for details.

By the way an easy way to get the number of CPUs is nproc. There are a bunch of other ways that a web search on linux number of cpu will be helpful.

Servers In Virtualized Environments

Fundamentals Of Scripting Languages

Boot Process

I definitely would not use this as the “end all of knowledge” for this. I use this to review stuff before I interview.

By the way this is found at man bootup 7 but it’s not the easiest to decipher in my opinion.

Here’s the basics3:

  1. BIOS POST (Basic I/O System – Power On Self Test)
  2. MBR (Master Boot Record) – 512 byte
  3. GRUB2 – loads the selected kernel into memory and turns control of the computer over to the kernel
  4. kernel
  5. systemd – responsible for bringing the Linux host up to a state in which productive work can be done
  6. runlevel

And more on runlevels … I would seriously do more research on this topic but:

Some quick commands worth having fresh:

## display the default target unit
systemctl get-default

## list all currently loaded target units
systemctl list-units --type target

Problem Diagnosis

Installing Configuring Maintaining Services

I think I need to restructure this section but for now …

There are many services that can do Layer 4 load balancing: Nginx/Nginx Plus, HAProxy, and the one we’ll look at today, IPVS.

Apache

MySQL

Nginx

SNMP

Network Tools

Iptables

IPVS

HAProxy

Build And Monitor Services On Production Servers

Print Friendly

Subversion

$Id: code-stuff.txt 4075 2019-04-02 13:06:52Z hoopchuk $

  1. https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
  2. http://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html
  3. https://opensource.com/article/17/2/linux-boot-and-startup