Tired of MLB.TV blackouts? Here's a free way to circumvent some of them.

If you're like me, you love Baseball.  Major League Baseball has done a fantastic job of making games readily accessible to fans via their MLB.TV subscriptions.  If you're an avid fan, a fantasy nut, or whatever else, you might think that $120 to watch tons of baseball on the internet over the course of the season isn't a bad deal.  I'd tend to agree.  There's really only one downfall: you're not going to be able to watch in-market games due to TV blackout restrictions.  For example, I live in the Chicago area, and cannot watch Cubs and Sox games online. 

MLB.TV restricts viewing based on the geolocation of your internet protocol address.  If your IP address is located geographically in a region that has a game on local television, you will be blacked out from that game.  Simple enough.  

This really isn't a big deal most of the time.  I'm able to watch these games on local TV.  But what about day games during the work week?  Both the Sox and the Cubs played a day game today to open the season, so even if you have an MLB.TV subscription, you're out of luck if you're at work with no TV.  The best you could do with the computer is listen to the radio broadcast while you're blacked out from the video feed.  

The logical solution to this problem is using a proxy server to surf the web.  This way, MLB.TV will assume you are viewing from the geographic region of the proxy server's IP address.  There are open proxies around, but I wouldn't use them.  Even if they don't pose some sort of security risk to your system, they likely will not have sufficient bandwidth and connection consistency to watch baseball, especially in 720p.

So what do you do?  You need a proxy.  You want it to be secure as possible.  You need it to be well out of your geographic region.  I recently paid $5.95 for a month of VPS service from burst.net that will allow me to open a proxy based in Scranton, PA.  I thought I pretty much had it made, until I tried watching the Cubs game today.  I was blacked out.  They were playing the Pittsburgh Pirates, which meant my Pennsylvanian proxy was of no use to me to watch the game.

Then it dawned on me:  "Doesn't Amazon's Elastic Compute Cloud (EC2) offer services out of multiple states and countries?"

The answer is yes.  You can create an instance of many different operating systems almost instantly in datacenters around the world.  They even have a free tier, too.  Note that the free tier is only free for 1 year.  After this you will pay per hour for the instance (2 cents an hour for micro) and by the gigabyte for bandwidth (10 cents/gig in, 15 cents/gig out).  After fiddling around with it, I'm wondering why the heck I haven't tried this before.  For more information on what you get on the free tier of AWS, check out http://aws.amazon.com/free/.  Here are the basics: You can run their "micro" sized instances (which is more than enough for what we're doing here) for 750 hours/month at no charge, after which you will have to pay by the hour.  That's about 31 days if anyone is counting.  This means you can run 1 micro instance for an entire month without charge.  The main limiting factor here is bandwidth.  On the free tier, you get 15 gigabytes of incoming traffic and 15 gigabytes of outgoing traffic.  This total probably won't get you through a month of MLB.TV, but if you're just using it to occasionally circumvent IP geolocation to watch games, you shouldn't have too much trouble.  The price for bandwidth over this limit is 10 cents per gigabyte on incoming traffic and 15 cents a gigabyte for outgoing traffic.  Meaning if you go over the limit, and you're using it as a proxy, you probably stand to pay about 25 cents a gigabyte, since the proxy will use both incoming and outgoing traffic.  This really isn't too bad of a price, and for the worst case scenario, you'd be paying a few bucks a month to watch baseball wherever you want.  After your free year is up, you can start and stop the instance whenever you need to circumvent IP geolocation, only paying (probably) a buck or two at most to watch a game.

I realize that this information isn't really that useful without some sort of guidance on how to set up the proxy.  I will do my best and provide some screen shots for clarity.  Please be warned that MLB.TV policies may prohibit doing this kind of thing.  I'm not responsible for anything you do with this information so proceed with whatever amount of caution your adult mind sees fit.

HOW TO: Circumvent IP Geolocation using Amazon EC2

Step 1:  Sign up for an Amazon AWS account.  I did this a while ago, so I forget what that entails completely, but I know it isn't hard.

Step 2: Within AWS, sign up for EC2.  This should involve them calling your phone and entering a PIN to make sure you're who you say you are.  

Step 3: You will now have access to the EC2 dashboard within AWS.  Now, let's create an instance. I've attached a screenhot of bascially what you will see in the EC2 Dashboard: 

Screen_shot_2011-04-01_at_7

Not surprisingly, if you hit "Launch Instance" from this panel you will begin a wizard to launch an instance.  If the meaning of "instance" in this context is confusing you, I'd suggest you read up just a little on EC2: http://aws.amazon.com/ec2/

The first thing that comes up after hitting "Launch Instance" is a wizard that looks like this:

Screen_shot_2011-04-01_at_7

Any of the options you see with a star on the right can be used for the free tier.  It is important that you choose an AMI that fits this criterion.  After all, this isn't a guide about how to buy anything...

For this guide, I will explain how to use the instance as a proxy using the "Basic 32-bit Amazon Linux AMI 2011.02.1 Beta (AMI Id: ami-8c1fece5)" option.  I don't prefer this OS for most uses, but for what we're doing here it will be completely fine.  It's also the first option, so it is easy to find. (note: If you would prefer to use Ubuntu, as I do, click the "community ami's" tab in the wizard, and search for ami-c2a255ab. That should be 10.04 Lucid)

Hit the "Select" button to select the type of instance to run, and you will get to the second page of the wizard.  AT THIS POINT MAKE SURE TO SELECT "MICRO" FOR THE INSTANCE TYPE!

Screen_shot_2011-04-01_at_7

The next page should give you a couple options, such as Kernel and RAM disk ID's.  Leave at default values and click continue.  The next page should have key and value fields.  The first key is filled in for (it says Name).  Leave this alone and in the value field to the right of it, pick a name for your instance.  It doesn't matter what you choose. I chose "Proxy Server"

Screen_shot_2011-04-01_at_7

The next screen of the wizard is important.  The purpose is to set up a public/private key pair for connecting to the server.  You won't be entering a password when you log in to the server, the key will do the talking for you.  Call it whatever you want but I would recommend keeping the name short.  I'll go with proxy.  After you enter the name, click on the download button.  Save the file somewhere easy to remember.  If you're using *nix, I would just put it in your home directory.  In Mac OS X, that would be /Users/<username>.  It varies in linux distros but you can navigate to your home directory easily using the tilde symbol (~).  Example: cd ~/

The reason I put it in my home directory is that when I open a terminal and want to use the key I just downloaded, I don't have to include any path information.  If you're using Windows, just save the file somewhere you can find it for now and I'll get back to this subject shortly.

The next page of the wizard should contain firewall information.  The only port we will be using here is 22 for SSH.  Make sure this port is open for the instance to be able to receive ssh connections.  This should be done for you by default, I believe.  If you can't connect to the instance in a future step, make sure its not a firewall issue and that you have port 22 open.

After you're done with that page, you should see a summary of everything you've configured.  Take this last chance to make sure that you're using a "Micro" instance which qualifies for the free tier of AWS.  If everything looks good, hit launch!

Screen_shot_2011-04-01_at_7
 Upon hitting launch, it should only be a matter of moments before the instance is live.  Amazon's nifty AJAX interface will let you know when its running without refreshing the page.  At this point, we're almost watching in-market baseball over the internet.  Hang in there, the setup is almost over.

Step 4: Now that the instance is running, we need to connect to it.  I will explain this twice, once for Mac and once for Windows.

The first step regardless of what operating system you have is to determine the ip address of your instance.  Right clicking on the instance in your EC2 control panel will bring up a context menu, at the top of which you will see the word "Connect."  If you click on this, it will give you a command that you can copy and paste into a terminal.  It should be something along the lines of: ssh -i proxy.pem root@<yourinstancehostname>.

This is fine, exept by default you can ssh into it as root.  It will make you use the username "ec2-user" ("ubuntu" on ubuntu) @<yourinstancehostname>

So, the command should really be: ssh -i proxy.pem ec2-user@<yourinstancehostname>

If everything is set up correctly, you will be in an ssh session with the server.  By default, ec2-user (or ubuntu) has sudo rights, so to switch to the root account you could type "sudo su" or you could prefix any commands you wish to run as root with "sudo".  Google "bash commands" if you need more help in this area of things.  But know that all you need to do is get connected to the server, so the commands once you're connected really don't matter.

Mac OS X:  Open up Terminal.  If this isn't on your dock, you can search spotlight for it (the looking glass on the top right of your screen) and open it from there.  I would recommend keeping this on your dock, especially if you fancy yourself a *nix enthusiast.  If you've connected already via terminal, close the connection.  We're going to connect, but this time, we're going to open a SOCKS5 proxy which will transfer the data through the ssh tunnel (securely I might add).  Instead of the last command we used to connect, try this one:

ssh -i proxy.pem -D 9999 ec2-user@<yourinstancehostname>

the -D 9999 part of that command opens a proxy on your machine which uses the SSH session to fetch data.  This is called "tunneling" or using an ssh tunnel.

Windows:  I guess there's no sense in writing this tutorial for Mac alone, because most people who see it probably won't be using mac.  The only difference in how to go about this in windows is the SSH connection.  Since windows doesn't have a bash terminal, you'll need to connect to the server using an SSH client such as putty.  Putty is free and good, so just download it and stop worrying:  http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Once you've downloaded putty, checkout amazon's guide for connecting to an ec2 instance using the key you downloaded earlier.  That guide can be found here: http://docs.amazonwebservices.com/AmazonEC2/gsg/2006-06-26/putty.html 

Putty has options on the left, one of which is SSH.  Click on it to expand.  There is a tunneling section.  Follow this guide to set up putty to create an ssh tunnel:  http://oldsite.precedence.co.uk/nc/putty.html

 

Step 5: Now we have to configure our system to use the proxy to retrieve information from the internet instead of its normal channels.  I will show you how to do this in firefox because it uses proxy settings idependantly from system proxy settings.  Open up firefox, and go to preferences.  In the "advanced" tab hit network, and then under connections, set up a socks5 proxy using the address "localhost" and port 9999 (or whatever value you used when setting up the tunnel).  Here's a screenshot in case it has been hard to follow:

Screen_shot_2011-04-01_at_8

If you have the ssh session open, and firefox configured properly, you will now browse the web via proxy.  Check your ip address on whatismyip.com before and after to make sure that its working and your ip has changed in the eyes of the webserver you're accessing.

The voila, you're done!  Enjoy baseball wherever you want.  The best part about all this is that its free for the first 15 gigs incoming and 15 gigs outgoing to/from the instance.  Like I said before, the worst case is you'll spend a few bucks on overages but it won't break the bank.

You can of course use this proxy setup to browse the web even when you're not trying to circumvent geolocation of your IP address.  I would recommend having it ready to go in case you're in an area with public wifi.  Information going through the ssh tunnel is encrypted and will be kept private even on open networks.  That's reason enough to have this in your back pocket.

And, of course, if you already have a shell account somewhere you can use that.  The awesome part of EC2 is that you can stop an instance and start a new one in a totally different place (such as Ireland, Tokyo, and Singapore) so you can circumvent geolocation nomatter where the content is blacked out.

Enjoy.  If you have questions or are having problems, try leaving a comment and I'll see what I can do to help.

Edit 1: A random internet stranger has informed me that once you initiate the connection to an mlb.tv video feed, you can turn off the proxy (in firefox settings) and continue viewing on your home connection.  You know, the one that SHOULD be blacked out.  This makes the bandwidth issue basically non-existent.  Thanks for the tip!