Category Archives: Linux

MUA and MTA

In the last two posts, we’ve talked about how email is handled in DNS. It’s an important first step, you can’t send email if you don’t know where it’s going to go. Now we’re going to talk about two parts of the email system called the MUA and MTA.

The MUA is the Mail User Agent. How’s that for a boring term? It means that program you (the user) are using to send and read email. That page in your web browser, that application on your phone, whatever you’re using, that’s called a MUA. I’ll list a few examples:

  • elm (REALLY OLD)
  • pine (Not as old as elm, but OLD)
  • outlook (Microsoft’s flagship!)
  • your web browser of choice
  • thunderbird (OLD)
  • mail (aka that app on your Mac)

That’s just a few of the programs that can send and read email. Your system doesn’t actually receive it though, that’s the job of the MTA. Your MUA doesn’t do the real job of sending it either, it hands that off to the MTA as well.

So what’s an MTA? An MTA is a Mail Transfer Agent. It’s the computer program that actually sends and receives your email. You don’t see it work, it’s like when you send your email you drop it into a box:

A box

A box

the MTA picks it up and sends it along, like a postman:

Postal Van

Postal Van

And it lands in the other person’s Inbox:

Inbox

Inbox

Of course, that’s not what your inbox looks like, but it’s  a pretty picture.  Your inbox is actually a file whose format depends on the MTA and most MTAs have their own format.

There’s many different MTAs available. Your system uses whatever the system administrator set up, so you don’t have to worry about it. A few of them are:

  • sendmail (one of the originals!)
  • exim (not as old as sendmail)
  • qmail (older than exim but not as old as sendmail)

You don’t have to worry about the set up and management of these systems, someone else does that. If you want to learn, there’s books (and books and books) on the subject.

MX Preference

In the previous post, we talked about MX records. When we looked at gmail.com’s MX records, there were numbers before the hostnames. Those numbers are preferences, also known as MX preference.

How’s that for a technically boring term? MX preference means something when the computer is determining which of the records to use as a destination for my email. Let’s look at those results for gmail.com again:

gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.

 

The one with the lowest number has the highest preference. How’s that for a contradictory sentence? But it’s how it works. This means that if I’m sending email to gmail.com, then the first place it’s going to try is the system gmail-smtp-in.l.google.com. If this fails, then it goes to the next in the list by preference, that is, alt2.gmail-smtp-in.l.google.com.

The geniuses (Not Dr. Strange and Ironman!) who designed this knew that people really wanted to get their email. Well, not spam email, but they didn’t consider that. They knew that people really wanted email and it should work, so they made it so what should happen is that the system sending the email should try each in order of MX preference.

Not everyone does it, of course. The Internet is a cooperative and it depends on people doing the ‘right thing’ or an approximation close enough to keep things running. Sometimes you’ll send an email and see a bounce from the mailer-daemon (not a real demon), but if you try again in just a few minutes, it’ll go through.

Either the other domain didn’t have a server up to receive the email or the system didn’t check through the MX preference list like it should have, or there was a real demon in the system. Any one of these could have caused the problem.  Especially the demon, demons are trouble.

Fred the Demon

Fred the Demon

I call mine Fred.

Disclaimer: There are no real demons in the Internet. …I think.

Email and DNS

I get lots of email, some of it I want, some of it I’d rather not see. I’m sure that’s true for everyone with an email address. If I get the email, how does it get there? If I send email to my brother, how does my computer know how to get the email to him? It’s a bit of a complicated process, so we’re going to break it down and start by talking about Email and DNS.

One day, I decide I want to send an email to myfriend@example.com.

Why did I say example.com rather than a domain like gmail.com or hotmail.com? That’s because example.com is a domain that was set aside at the beginning of Internet time so people can use it in examples without referring to existing domains. It’s an example, just like its name.  It’s useful to use it because existing domains have been known to go away or change behavior, but example.com is always that, an example.

Ok, back to the subject at hand!

I’m sending email to myfriend@example.com and my first question is how does my email know where to send it?  My second question is, do I send it to example.com or somewhere else?

The geniuses that set up the Internet originally knew that the owner of a domain wasn’t necessarily the same person that ran the domain. The  domain computerlamp.net is what has this blog and while I own that domain, I don’t run things around here. I let DreamHost (Hi guys!) run this for me. That means that they handle my email, I don’t. All I do is read it.

DNS lets us know this by using the MX record. (MX means ‘mail exchanger’. They skipped the E when they made the acronym.)

The MX record for computerlamp.net is:

computerlamp.net mail is handled by 0 mx2.sub4.homie.mail.dreamhost.com.
computerlamp.net mail is handled by 0 mx1.sub4.homie.mail.dreamhost.com.

I did this using the command host.  Using the -t flag, my command was:

Alpha:~ computerlamp$ host -t MX computerlamp.net

If I wanted to know who handles the email for gmail.com, I’d do:

Alpha:~ computerlamp$ host -t MX gmail.com
gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.

I got 5 responses back… with numbers in them! Next time, we’ll talk about what those numbers mean.

Running out of time

In this post, I said that Linux keeps time by counting seconds. So, here’s a good question: Is there a number that Linux can’t count past? I mean, if you sat there and counted, you could keep going and going and going until you fell asleep. Linux doesn’t actually fall asleep, it keeps counting… until it can’t. We’ll call it the ‘Running out of Time’ problem.

It’s not like when the good guy runs out of time trying to stop the bomb and everything explodes.

Time is Running Out

Running out of Time

Your system isn’t going to explode! I promise. It just runs out of ways to keep counting.

Most systems today are 32 bit systems or 64 bit systems. That 32-bit (or 64-bit) refers to several different internal operations of your system. We’re going to talk about what it means in terms of numbers. If your system is a 32 bit system, that means the largest number it can store is 2^32. That’s 4294967296. That looks like a big number, doesn’t it? It seems like it’d take a while to count that high. If your system is a 64 bit system, the largest number it can store is 2^64. That’s 2^32 squared or 4294967296 squared. That’s.. a REALLY big number.

The running out of time problem has to do with 32 bit systems.  On January 19, 2038, the number of seconds from January 1, 1970 is going to be larger than 4294967296.  Your 32 bit system isn’t going to be able to count any higher than that and, well, interesting things will happen, or won’t happen.

Running out of Time

Running out of Time

Your 64-bit system doesn’t have that problem, since it can count so much higher than your 32-bit system.

Is there a solution for this problem? Well, no. There’s a lot of smart people working on it though. Those smart people don’t include Tony Stark or Dr. Strange or even Batman, but they’re going to figure it out. Hopefully before January 19, 2038.

Linux® Time

So let’s talk about Linux® and time again. We’ve talked about the calendar, we’ve talked about the Network Time Protocol, but let’s talk about how Linux® stores it.

Everyone seems to have their own way they want to write the date. In Europe, they like to lis t the date first but in America, they like to list the month first. Some people even like to list the year first. And that’s just the date. Now there’s the time! There is the standard of hour, minute, second, but what if you want to write year, hour, month, minute, day, and then seconds? There’s no reason you shouldn’t, right?

Well, keeping track of all of those choices isn’t something Linux® should have to do. Instead, it keeps time by counting seconds, and you can take those seconds and make them look however you want.

Linux® had to start counting seconds at some point, and they chose to start at January 1, 1970.  That’s weird, right?  Linux® wasn’t released until 1991, why did they choose 1970?

Well, I could spin an awesome story about how that’s the instant the first real computer was turned on, or that Iron Man first turned his suit on, or Batman decreed it to be the start of the new era (or new new era), but that would be wrong. The real story isn’t that it’s the birthday of Unix (the Operating System that Linux® mimics), the real story is that it looked pretty.

Computers used to keep time on the sixteenth of a second. This caused problems, because that meant the computer could only tell time for a couple of years before it couldn’t store it anymore. The decision was made that ‘gee, we should use seconds, that’ll work better’. (There was more discussion about this. Imagine the Avengers and the Justice League trying to agree on something.) Once that decision was made, they said ‘huh. Well, let’s start counting from January 1, 1970. That’s a nice round time. Even though it’s 1972 now, that’ll work great’.

And so that’s what they did, they started counting from January 1, 1970.  All Linux® time is stored like that, it just prints out the pretty time (in the format you want).    Check out the man page for date, it will tell you how.

Network Time Protocol

Ever noticed how a clock may not have the exact right time? Like it’s close, but not there? The same thing can happen with a computer. It relies upon its internal clock, but that can be almost, but not quite, right. Luckily, there’s a protocol to fix that (the unofficial motto of the Internet) called Network Time Protocol.

This lets you automatically make sure the clock on your computer is set to the right time. This is really important if you have many computers working together. Kind of like Tony Stark’s drones in the Age of Ultron movie. Suppose he sent them after Ultron but the clocks are all just a little bit off. Instead of blasting Ultron all at once, you’d get one shot, a few minutes later another, and then another, and.. see? that’s not a good thing. You want one BLAST to take Ultron (and HIS drones) out.

So, how does it work? To begin with, you have a really accurate clock, something like an Atomic Clock. That has an awesome name, right? Sounds like something used in a Doomsday weapon to make sure that no one can stop it, except maybe Super Man. It’s one of the most accurate clocks known, so that’s a good thing to ask.

There’s computers that synchronize directly to the clocks, so those are a good thing to ask too. Generally, there’s a list of servers on your system that your system will synchronize to. Network Time Protocol is designed to use the list and say ‘yo, other computer, tell me what time it is’ and then adjust your computer if it’s off.

The list of servers is kept in the file ntp.conf which is generally located at /etc/ntp.conf. Let’s look at it:

# /etc/ntp.conf, configuration for ntpd

driftfile /var/lib/ntp/ntp.drift
statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable


# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example

# pool.ntp.org maps to more than 300 low-stratum NTP servers.
# Your server will pick a different set every time it starts up.
#  *** Please consider joining the pool! ***
#  *** <http://www.pool.ntp.org/join.html> ***
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst

There’s lots of information in there. The important part is the names after that word server. This computer uses servers by the name of 0.debian.pool.ntp.org 1.debian.pool.ntp.org, 2.debian.pool.ntp.org and 3.debian.pool.ntp.org to keep the time straight. This means that if one of those isn’t available, the Network Time Protocol will ask one of the other ones.
One of the interesting facts about the Network Time Protocol is that it’s one of the oldest protocols on the Internet. People have been trying to keep the times synchronized on their computers as long as they’ve been able to talk to other computers.

How about a Date?

I bet your cell phone knows what today’s date is.  Your computer should know too, right?  Depending on how your system is set up, you might even see the current date on your screen.  Well, your command line also knows what date it is and can tell you if you ask it.  The command is called (drum roll here please):  date

Alpha:~ computerlamp$ date
Fri Apr 28 15:21:15 EDT 2017

That’s the date that I wrote this and it even include the actual time.  That’s rather useful, isn’t it?

What else can we do?  Well, let’s find out what today’s month looks like.  I had an appointment on the 15th but I forgot what day of the week that was.  Well, there’s a command for that!

Alpha:~ computerlamp$ cal
     April 2017
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

That’s one useful command, isn’t it?  I can see that the 15th was on a Saturday.  But hey, it’s almost the end of the month, I want to know what day of the week May 14th is.  Well, I can ask that too:

Alpha:~ computerlamp$ cal 5 2017
      May 2017
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

I just asked it for the calendar for the fifth month of the year 2017.  Huh.  I wonder what happens if I ask it for the calendar for May 2020.

Alpha:~ computerlamp$ cal 5 2020
      May 2020
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

What do you know, that works too!  I can ask for the month and year for almost any time!  I bet that would come in use when Flash starts playing with the timeline again

The Flash Changing Time Again!

The Flash Changing Time Again!

I bet if he goes way back into the past I can figure out what the calendar looks like.

According to this Captain America disappeared around April 18, 1945.  That was a Wednesday!

Alpha:~ computerlamp$ cal April 1945
     April 1945
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

So The Flash could go back in time and rescue him, right?  Except that Captain America is Marvel and The Flash is DC.  Oh well, details, right?

sudo

So one day, Tony Stark noticed a wasp in his lab.  He could put on the whole suit to kill it, or he could just put on the glove.  The whole suit is overkill, right?  Just one glove would take care of the whole thing.  There’s a similar idea in Linux®.  Using su to get root powers is overkill, the ‘just enough’ command is sudo.

Glove vs Wasp

Iron Man’s Glove vs Wasp

sudo lets you execute a command as another user.  You can be root, you can be tonystark, batman, spock… you can be anyone you want, but you have to be given the power.  You can’t just walk up to the computer terminal and say ‘today, I’ll be batman, Batman’s user name.  I’ll do whatever batman can do on this Linux® system because sudo will let me’.

That’s kind of like putting on Batman’s suit and declaring yourself Batman.  It doesn’t work like that… though I wouldn’t mind being Batman for a day and driving around in the Batmobile.  That thing looks awesome.

Once you’re given permissions, you execute the commands like this:

Alpha:~ computerlamp$ sudo -u batman vi plans

If I have the permissions to do it, I can edit the plans file as batman.  I’m hoping it contains the plans for how to stop the Riddler.  Riddles aren’t my thing.

Anyway, how do you know what commands you have?  Well, there’s a flag for that!  (The other Linux® motto.)

Alpha:~ computerlamp$ sudo -l
Matching Defaults entries for computerlamp on Alpha:
    env_reset, env_keep+=BLOCKSIZE, env_keep+="COLORFGBG COLORTERM",
    env_keep+=__CF_USER_TEXT_ENCODING, env_keep+="CHARSET LANG LANGUAGE LC_ALL LC_COLLATE
    LC_CTYPE", env_keep+="LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME", env_keep+="LINES
    COLUMNS", env_keep+=LSCOLORS, env_keep+=SSH_AUTH_SOCK, env_keep+=TZ, env_keep+="DISPLAY
    XAUTHORIZATION XAUTHORITY", env_keep+="EDITOR VISUAL", env_keep+="HOME MAIL",
    lecture_file=/etc/sudo_lecture

User computerlamp may run the following commands on Alpha:
    (ALL) ALL

So the first part of that response we’ll talk about another time.  It’s the last line that’s the most interesting.  It says that I can run all commands on Alpha.  Every single one!

So why do I use sudo rather than su?  Well, it’s to keep myself from making mistakes. If I have to think about each command before I use it, then I’ll be more careful.

Remember, for both sudo and su, it’s like Spiderman’s Uncle Ben said.

Spiderman!

With great power comes great responsibility!

Swap on/Swap off/Swap!

In the last post we talked about computer memory and there was that weird line in the free command results called swap.  I also promised to talk about it this week.

So there you are in Math class one day and your teacher writes the most complex equation on the board you’ve ever seen and says ‘SOLVE IT!’.  What do you do?  Well, you pull out a piece of paper and get to work.

swap is kind of like that piece of paper.  The computer wants to do all its thinking in the memory it has installed for that, but sometimes that doesn’t work.  So instead of pulling out a piece of paper and doing work on that, it uses swap.  It would be more fun if your computer could stop what its doing and pull out paper, but it wouldn’t work as well.

So what exactly is swap anyway?  Well, when you set up your system, you designate a part of your hard drive to be the swap space.  This means that the computer is using its remembering memory for thinking memory.  Sounds weird, but it works.  You remember when you think sometimes, right?  You remember how to do the math problem while you’re thinking about the math problem.  Or you’re thinking about how Iron Man would solve it rather than actually solving it, but hey, whatever keeps the math teacher happy!

So let’s look at the result of that free command again:

Alpha:~ computerlamp$ free -g
             total       used       free     shared    buffers     cached
Mem:            31         29          1          0          0         12
-/+ buffers/cache:         17         13
Swap:            2          2          0

According to this, I have 2 gigabytes of swap to use and I’ve used both of them.  In other words, I’ve used up all the paper I had free to do my work on and there’s no more available.  Not exactly the best spot to be in, but I’m sure I can borrow some from the guy next to me… except that doesn’t really work with computers.    But your administrator can add swap if she decides she needs it.

The Kernel Version

Over the years, Iron Man has had a lot of suits.  The suit he had when he started out looks nothing like the suit he wore in the Civil War movie.  Linux® kernels are something like that, the first kernels don’t look anything like the kernels of today.  There are different kernel versions that depend on what the person who put it together wanted and what hardware you’re running.

In other words, the kernel version of your Linux® system probably doesn’t look anything like the kernel version of the system I’m running.  But you can’t tell just by looking at the system what kernel version you’re running, so it’s not like Iron Man’s suit.  It would be neat if it was, imagine if your system put on a new suit every time you put a new kernel on it.  I think it would be awesome for it to change color at least every time I put on a new kernel, but it doesn’t work like that.

Luckily, there’s a command to find out what kernel version you’re running and it’s called uname.  The man page for it

uname man page

uname man page

Tells you exactly what it’s designed for,  it’s to print system information.

So, what information do I want?  I want the kernel version!

That’s:

Alpha:~ computerlamp$ uname -v
#1 SMP Tue Aug 12 09:58:26 UTC 2014

What else can I find out?

Well, I can find out what machine name I’m running, that’s uname -m

I can find out the name of my computer, that’s uname -b.  I can also find out the name of my computer using a different command.  That one is

Alpha:~ computerlamp$ hostname
Alpha
Alpha:~ computerlamp$ uname -b 
Alpha

Either way I run the command, I get the same result out, which means as usual there’s more than one way to do it!

I can also find out my processor, or my hardware platform, or the operating system.

But wait, you say, of course I know my operating system, I’m using Linux®.  Well, it’s always good to double check that using our friendly comman.

Alpha:~ computerlamp$ uname -o 
GNU/Linux

If you have multiple systems, it’s always useful to find out what kernel version you’re running on each one.  It’s a good idea to keep it consistent, but that’s up to the administrator.