One of the more interesting things about developing Briefcase has been that the features most popular with users haven't always been the ones I necessarily expected. One that caught me by surprise was the popularity of using the remote bookmark features of Briefcase to connect to home computers while on the road.
The reason the popularity surprised me was that I know it can be tricky to set up remote login. But, it turns out that most people think it ought to be easy (and they are right, it ought to be!). Unfortunately, despite improvements in modern networking equipment, you've still got to know a little bit about networking if you are going to succeed. I've had a number of users launch in with little networking knowledge and pull it off. All they needed was a clear explanation of what was going on and a pointer in the right direction (and possibly a strong cup of coffee).
Here is my attempt to explain the process so that others may likewise succeed. Please leave me a note if you find any bits confusing.
What's the big picture?
You are on the road with your iPhone and you want to connect to your home computer. The picture looks something like the one below.
Most people who have devices like iPhones and Macs also have a wireless router plugged into their high speed modem. Some recent models of high speed modems even come with the routers built into them. Apple's AirPort Extreme is an example of a commonly used router. The router is the center of any home or small office network setup.
The Router
Most people are a little fuzzy on what exactly the router does. In general people know that they need one if they want to share their internet connection between multiple computers and devices. Few know how the router achieves it (or that the home router is actually responsible for saving the Internet as we know it...more on that later).
The router performs the following important tasks:
-
Internet (IP) address sharing
-
firewall protection of your computers from the Internet
-
wireless/local networking in your home/office
Address Sharing
Address sharing is the feature of routers that most affects your remote use of Briefcase, and it's also how the router managed to save the modern Internet.
The basic problem is that there aren't enough addresses on the Internet for each device or computer to have its own. There's been general concern about the Internet running out of addresses for decades. There are large scale solutions in the works which will eventually allow your toaster to have it's own Internet address, but in the mean time we've used address sharing to stretch out the existing pool of addresses.
So, this means that your ISP gives you just one internet address and that address is taken by your router. That means that your router has an address that is unique on the Internet.
Now, in order to be on your home network, your computers and other devices still need to have an address. Your router takes care of that by handing out addresses from a special pool that are reserved for use in local networks (LANs). Those addresses are not unique on the Internet. In fact, there may be a hundred thousand computers with the same same address as yours. Your router uses a technique called Network Address Translation to allow your computers to talk to the Internet using the router's address.
That means that there is no unique address you can enter into Briefcase that will point to your computer at home. But, you can get to your router.
Firewall
The other problem that the router presents is that it is designed to stop computers on the Internet from connecting to your computer. All connections between your computer and the Internet must be initiated by your computer.
That means that if you try to use Briefcase to connect to your computer from outside your local network, your router is designed to stop it from doing so.
The Solution
If you haven't guessed yet, the router is where the solution lies. Your router has a unique address on the Internet, and it controls the firewall. The idea is to make your router forward all requests of a certain kind to your Mac. In this case, we need to forward all Secure Shell (SSH) connection requests (what Briefcase uses) from your router to your Mac. Routers can tell networking requests apart by which port number they come in on. Each networking request has a port number associated with it. For SSH, the port number is usually port 22.
So, the solution is to make the router forward requests on port 22 to your Mac. Then, you put the address of your router into Briefcase and use that to connect.
Static Address
Before we start forwarding requests to your computer, we need to know what local address your computer is at. There is an additional complication in that your computer may not always be at the same address. Your router hands out addresses and may not always hand out the same one to the same computer.
So, the first thing to do is to make sure that your computer is assigned a constant or static address. On a Mac this is fairly easy.
First you should know that an IP address consists of four numbers, each in the range from 0 to 255, separated by '.'s. For example, 192.168.1.100. When you are making new static addresses, you only want to change the last number.
NOTE: You may want to make a new "Network Location," before you start changing network settings, especially if you are configuring a laptop. You can do that by selecting "Edit Locations" from the "Locations:" drop-down menu (Under System Preferences > Network). Then hit the "+" button to create a new "Location." This will make it easy for you to switch back to the default networking settings later if you want to.
Proceed by opening up System Preferences, then Network and selecting the network adapter you are using (left hand side bar). It will likely be the only one lit up green and marked as "Connected." Look for the drop-down menu that says "Using DHCP" and change it to "Using DHCP with manual address". Then, you choose a new address for your computer by changing the last number. Do not choose 0, 1, or 255 as the last number because they are special.
Port Forwarding
Now, we move onto forwarding traffic. The tricky part about explaining port forwarding is that there are hundreds of kinds of routers and high speed modems and they all do port forwarding differently. Fortunately, there is a resource on the web to help you out.
The first step is to go to http://portforward.com/routers.htm and find your router type (brand and model number) in the master list (If you don't know what kind of router you have, there should be a label on it somewhere - frequently it's on the bottom).
On this webpage (at the top of the router list, in the centre) you'll notice your external IP address displayed. Take note of this, you'll need it later.
Click on your router type. You will be taken to a new page that will display a new set of "protocol" options. Find SSH and click on it:
Follow the instruction on the next page that come up. This will walk you through all the steps needed to get your router to forward SSH requests from Briefcase to your computer.
Sleeping
Another thing to mention is that Briefcase cannot connect to a sleeping computer. You need to adjust your power settings (System Preferences > Energy Saver) so that your computer does not sleep (Put The Computer to Sleep... select "Never"). There is a way to wake up a sleeping computer remotely, but I have not implemented it yet. There are some other iPhone apps waking up computers, but they do not work with WiFi and I'm not sure how they would work through a router. I will be looking into that.
Connecting
By now you should have done the following:
-
set up a static address for your computer
-
recorded your external address
-
forwarded SSH traffic from your router to your computer
-
made sure that your computer will not sleep
The next step is to try it out on your iPhone with Briefcase. Hit the "+" on the Briefcase "Connect" screen to add a new remote bookmark. Enter a nickname, your external IP address, and the username for your account (on your computer) and save the bookmark.
Next, if you are still at home, you may want to turn off WiFi on your iPhone so that you can test your connection over 3G (iPod Touch users of course, can't use 3G and will only have remote login available to them when they are in a WiFi hotspot). To turn off WiFi on an iPhone, just go to the home screen and tap on "Settings" then "WiFi" and slide the WiFi switch to Off.
Cross your fingers and try out the bookmark. If you are stuck, you can email me at support@heymacsoftware.com and I'll try and help.
Final Notes
Now that you are hopefully connected, there is one other thing to worry about. Your ISP likely changes your router's address regularly (that's where your router gets its IP address from); unless you are paying extra for a static IP address (and you're probably not). Your options are to ask your ISP for a static address (expensive) or set up a static domain name on the internet (free) to keep track of your router's address. You get a static domain name through a DDNS service provider. I recommend dyndns.com.
IMPORTANT It can sometimes happen that your domain name is pointing to the wrong IP address (it's rare, but has happened to one customer). If this happens, Briefcase will bring up a warning which says "Host's Hash Value has Changed." If you see this warning, DO NOT LOG IN! If you do, you'll be sending your password to the wrong computer (possibly the computer of a hacker). Instead, hit cancel and at your earliest opportunity update your address with your DDNS provider.
That's All
I have tried to explain just enough of the networking lingo so that you'll understand what is going on. I hope I didn't get carried away. If you've got feedback or questions, please leave a comment below and I'll try to clarify where I can.
Good luck!