Monthly Archives: June 2012

How to create an Ubuntu Application

If you are a beginner, here is a great tutorial on how to create your first Ubuntu application.  The tutorial will show you how to create a simple web browser using webkit.  It goes into setting up your UI, writing the code (in python) and creating an Ubuntu package and publishing it into the Ubuntu Software Center (like Google Play or App Store).

Excluding DROP and CREATE TABLE From mysqldump

How do you dump data from a mysql database table without the drop and create tables showing up before the inserts?

The following solution will just give you a list of insert statements. Simply use the options –skip-triggers –compact –no-create-info.
Here is an example.

What Are The Major Differences Between InnoDB and MyISAM Storage Engines?

InnoDB vs MyISAM

This pertains to MySQL 5.5

  • InnoDB stores data in a file(s) called a tablespace. In newer versions of MySQL, you can store the data and indexes in separate files. MyISAM stores the data and indexes in two files (.MYD, .MYI). InnoDB is extremely critical about its tablespace and log files (They normally should be backed up together). You can’t just backup your data by copying files like you would with MyISAM. In some situations you can only restore a table to the server from which you backed it up!
  • InnoDB are built on clustered indexes and uses MVCC to achieve high concurrency. This provides very fast primary key lookups. MyISAM doesn’t support transactions, FK contraints, or row-level locks. MyISAM uses shared and exclusive locks on the entire table. However, concurrent reads & inserts for new rows are allowed.
  • InnoDB is crash safe (Assuming your flushes are truly durable on disk and not on some volatile cache). MyISAM is no where close to being crash safe. If you care about your data, use InnoDB. It might be OK to use MyISAM for read-only workloads.
  • InnoDB will support full-text indexes in MySQL 5.6. MyISAM currently supports this feature. Normally these type of things should be offloaded to something like a Sphinx server.
  • InnoDB repairs are reasonably fast. MyISAM is slow and you might not get all your data back. Eek.
  • InnoDB requires a lot of memory (buffer pool). The data and indexes are cached in memory. Changes are written to the log buffer (physical memory) and are flushed every second to the log files (method depends on innodb_flush_log_at_trx_commit value). Having the data in memory is a huge performance boost. MyISAM only caches indexes (key_buffer_size) so that’s where you would allocate most of your memory if you’re only using MyISAM.

Overall InnoDB has a lot more intricacies but it’s worth learning about. In 99% of the cases, you should just stick to InnoDB unless you have a good reason not to.

Introduction to IP Addresses and Subnetting

An IP address contains a network portion and a host portion. The netmask determines the division between the portions. Together the operating system can determine which IPs are part of the local subnet and which ones are outside. I know this sounds really confusing so allow me to demonstrate. We will be using the Classless Internet Domain Routing (CIDR) notation.

An IP address (IPv4, 32 bits) of 192.168.1.200 with a subnet mask of 255.255.255.0 is represented in CIDR notation as: 192.168.1.200/24 (First 24 bits have binary value of 1, 11111111 = 255). The /24 is called the netmask.

  • The network address is 192.168.1.0 (Logical AND between the address and the netmask).
  • There’s one subnet with 256 addresses.
  • Only 254 addresses are usable because the first one is used for the network address and the last is the broadcast address.

If we use 192.168.1.200/26, the netmask is 255.255.255.192. This netmask tells us that the  broadcast addresses will begin with 192.168.1 and that the range of each subnet is 64 (256-192). The way to find out the number of subnets and hosts is simple. Find out the number of added bits (26-24 = 2). Find out how many bits are left (8-2 = 6). Calculate 2^6 and you get 64. This is the number of hosts per subnet. For the total number of subnets all you do is divide 256/64 and we’ll get 4 subnets.

A table might make this clearer:

Mask Bits # of Subnets # of Hosts Added Bits Subnet Mask Bits (Dec)
/24 1 256 0 0
/25 2 128 1 128
/26 4 64 2 192
/27 8 32 3 224
/28 16 16 4 240
/29 32 8 5 248
/30 64 4 6 252

The next steps is to find:

  1. Network Address of the IP
  2. Broadcast Address of the IP

Let’s take for example 192.168.1.75/27. Using the chart above we know there are 8 subnets with 32 addresses each. This IP obviously cannot reside in the .32 to .63 range so it must be in the .64 to .93 range. Hence the network address for 192.168.1.75/27 is 192.168.1.64 and the broadcast address is 192.168.1.95.

So what’s the point of all this madness? Here’s a real world example. Say you’re hired to divide up a 10.14.1.0/24 network into 20 subnets. Each subnet represents a department in the company. How would you do this? From looking at the chart above, you’ll need to allocate 32 subnets, which means you need to change the netmask to /29. Each subnet will have 8 hosts which has only 5 usable addresses (You need one for network address, broadcast, and router).

Types of IP Addresses

Loopback

Commonly known as localhost. You’ve might’ve seen it on a shirt of a geek as its numeric counterpart 127.0.0.1. Packets through this interface will never leave the your network card.

Unicast

The packets will be destined for a specific IP address.

Multicast

The router will send the packets to multiple locations at the same time. Addresses in the range 224.0.0.0 to 239.255.255.255 are reserved for multicast. 244.0.0.0 – 224.0.0.255 are link-local addresses that cannot escape to the internet.

Limited Broadcast

Packets are sent to every computer on the same subnet. Example is 255.255.255.255

Directed Broadcast

Packets are sent to a specific subnet then broadcast across all hosts.

RFC 1918 / Private Network

The internet will not route these addresses. A NAT is normally used to convert it to a routable address prior to being sent.

  • 10.0.0.0 – 10.255.255.255
  • 172.16.0.0 – 172.31.255.255
  • 192.168.0.0 – 192.168.255.255

IP Nodes, Network Types, and TCP/UDP Basics

IP Nodes

Every single networked computer needs to know three things:

  1. IP Address – The operating system will respond to packets destined for its IP address unless in promiscuous mode.
  2. Netmask – Allows the OS to know how large the local network is.
  3. Router IP Address / Gateway – When your computer wants to communicate outside the subnet, then it must speak with a router.

Network Types

  • WAN – Wide Area Network. ISDN, Frame-Relay, ATM protocols.
  • LAN – Ethernet

TCP/UDP

  • TCP
    • Reliable – Prevents corrupted transfers.
    • FTP and HTTP use this protocol.
  • UDP
    • Unreliable but fast.
    • Great for streaming video or video games.

What is DNS Delay?

What is DNS?

  • When you visit a website, your computer needs to convert a domain name to an IP address. DNS (Domain Name System) does this translation. For example, google.com translates to http://74.125.224.95/
  • DNS servers are distributed and are constantly updating each other.
  • Every computer has a name server. If you’re a home user, it’ll most likely point to your router. This can be changed to Google DNS or OpenDNS, etc.
  • When you register your domain name, the registrar will have some default name servers for you and allow you to change it.
  • You get this name server from either your registrar, hosting site, or another 3rd party (dnsmadeeasy.com) DNS service. From there you can assign an IP address to your domain name (given by your webhost). Just create an “A” record with “www” and you’re set. Keep in mind some hosts automatically assign you an IP based on your domain name (lunarpages.com) so all you have to do is use their name servers.
  • This is where the delay comes in. Some DNS companies make the changes immediately and some only update a few times a day. Once the changes are made, it will notify other DNS servers about the change.

How DNS Works:

  1. Your computer has a DNS server it refers to. You can find out what this is by typing “ipconfig /all” in Windows or “cat /etc/resolv.conf” in Linux.
  2. Your local name server doesn’t know anything but the root name servers. Run “nslookup -type=ns .” to find out what your local name server can see.
  3. Your computer uses these root name servers to first look up the “.com” (Top-level Domain) portion of your request which returns a list of TLD name servers.
  4. From this list you’ll look up the second part of the domain “google.com” with “nslookup -type=ns google.com (ip address from list).” This will return a list of name servers that will have the IP of the domain.
  5. Finally type in “nslookup google.com (one of the dns servers from the last list)” and you will get the IP address. Translation is complete!
  6. Now your local name server will remember this translation up to a certain period of time. Your browser will also cache the translation so it doesn’t even have to refer to your local name server.
  7. How long will the translation be cached? This is the main cause of the DNS delay. You can run “dig google.com” to find out how long the TTL (Time To Live) is in seconds. The ANSWER SECTION shows how long the local name server will remember the translation and the AUTHORITY SECTION tells you how long it’ll remember the DNS server used.
  8. If you change the IP of your domain, then the delay length is partially depended up on the speed at which your DNS service makes the changes. This can take a few minutes to 24 hours. My DNS manager (dnsmadeeasy.com) makes the changes instantly.
  9. Once the changes are set, it has to propagate to all name servers which can take a long time. The average is 24 hours. So combined delay from the DNS company and propagation could be up to 48 hours.
  10. Obviously you can make propagation much faster if you change the TTL. Some DNS services don’t allow you to change this value but it can range from 300 seconds (5 minutes) to 86,400 seconds (24 hours). If you have a TTL of 300 set, and you change your IP, it will take the rest of the world 5 minutes to be updated with the new IP.