Sunday, May 27, 2007

VPN in Ubuntu

After my previous attempt at creating a VPN in Ubuntu I reverted all my work because I was rather unhappy with the results. After digging a bit more I found out I could actually use pptpconfig, as long as I didn't actually clicked the "Start" button. Here's the trick:

Start by installing pptpconfig. Add the following to your /etc/apt/sources.list file:

# James Cameron's PPTP GUI packaging
deb ./

Then install the app:

sudo apt-get update
sudo apt-get install pptpconfig

Now run it (sudo pptpconfig) and configure your VPN. In the "Routing" options, select "Client to LAN". Lets assume you called your new configuration MyVPN.

You can close pptpconfig. Go over to /etc/ppp/ip-up.d/ and create a new file called vpnroute (sudo gedit vpnroute). Assuming that the network you want to connect to uses IPs like 192.168.0.*, add this to the file:
if [ "${PPP_IPPARAM}" = "MyVPN" ]; then
route add -net netmask dev ppp0
Don't forget to make it executable, or it won't work:

chmod a+x vpnroute

And that's it. To start your VPN run:

sudo pon MyVPN

To stop it run:

sudo poff MyVPN

VPN in Ubuntu using Network Manager

UPDATE: I found a better way to connect to a VPN. Check this post.

Imagine you have a Windows Network at work and you're stuck at home waiting for the plummer to fix the sink. No problem, just connect via VPN to your workplace, launch a Remote Desktop and in no time you're working in that piece of code you must deliver yesterday. Being this such a useful and common scenario, how come it is so hard to set up in Ubuntu?

Here's how I managed to connect to my workplace via VPN using Ubuntu. Let me say upfront that I'm not particularly happy with the result, and I'll try to do it some other way in the near future. But if you're desperate this will do. This is not an How To, but rather a step by step description of the tries and failures. Maybe it can help someone that finds the same error messages I've encountered. Well, here goes:

First I tried pptpconfig. Everything seemed to be properly configured, but all I got was the error message:

Cannot determine ethernet address for proxy ARP (Update: Actually this is not a problem. Just add noproxyarp to the pppd parameters.)

So I decided to install the Network Manager PPTP package:

sudo apt-get install network-manager-pptp

And restarted everything that depended on the package:

sudo /etc/dbus-1/event.d/25NetworkManager restart
sudo /etc/dbus-1/event.d/26NetworkManagerDispatcher restart
killall gnome-panel
nm-applet &

The killall and nm-applet commands are there to restart the Network Manager icon on your gnome panel. If for some reason the Network Manager icon does not appear (happened to me) just execute:

sudo /etc/dbus-1/event.d/25NetworkManager start
killall gnome-panel
nm-applet &

If you click the Network Manager icon now, you should have a "VPN Connections" entry. Just configure your own VPN connection and it should appear in the list of VPNs. Click it. If it works, you're in luck. If it doesn't, keep reading.

To keep an eye on what's going on with the VPN connection, just tail syslog:

sudo tail -f /var/log/syslog

That's how I found this error message:

(...) no currently active network device, won't activate VPN.

I googled for a while and found that if you want to use Network Manager to take care of your VPN, you cannot have a Wireless Connection manually configured. Oh boy... So I opened the manual configuration, saved my current configuration and in the properties of the Wireless connection ticked the box "Enable roaming mode". Because I have a somewhat odd configuration of routers at home, I also had to reconfigure all the routers, but I won't bother you with that.

My main problem with the roaming mode is that it stores the WEP password in the keyring. That's all fine and safe, but it means that when I login, besides having to enter my username and password I also have to put my keyring password! Very annoying!

On with the show. Connect VPN. More mysterious errors in syslog:

LCP terminated by peer (+ bunch of characters blogger won't let my type)

This is a funny one! First because it was a bit lost in the middle of a bunch of error messages. Second because, at least to me, it means absolutely nothing! Using a bit of intuition I thought it might be an authentication problem, so I just ticked all the boxes in the "Authentication" tab in the VPN configuration dialog and... it worked! I have a VPN connection to my workplace!

Just for wrap up, here's what I didn't like about all this:
  1. It's a lot of work for something so common.
  2. Because the WEP is in the keyring I must enter the keyring password each time I login.
  3. I must use roaming for my wireless connection. This means the router must do the configuration, and my routers suck at that.
  4. PPTP logs are there for the people who know the code or the protocol by heart.
  5. I'll probably just revert to my old configuration and try a new way of connecting via VPN.I got back to my old configuration and managed to configure the VPN in a different way.

Saturday, May 26, 2007

Ubuntu, NVidia and Automatic updates

So you have your Ubuntu system up and running, you click the button to do an innocent software update and suddenly... Bye bye X! What happened?

Well, during my upgrade to Feisty I installed the NVidia drivers' packages and they were updated. And since for some reason Ubuntu's NVidia drivers still don't work, I lost my X! So, once again, it's back to w3m to download and install the NVidia drivers from NVidia's website...

This is easy to solve, but I would rather that it didn't happen again. So I removed the Ubuntu packages from my installation.

sudo apt-get remove nvidia-glx
sudo apt-get remove nvidia-kernel-common

After doing this you must reinstall the NVidia drivers, because removing these packages also deletes a bunch of required files. As a bonus, you win about 100Mb of free space. :-)

Sunday, May 20, 2007

Automate Everything!

The other day, while waiting for another computer reboot or something similar, I grabbed The Pragmatic Programmer from the shelf. I already read the book, so I was just quickly browsing the tips in the book when I found this one: "Automate Everything". (you can find it by looking for "Don't Use Manual Procedures" in the previous link).

I already do this at work, but I started thinking it would be a really good idea to start applying this principle to my home projects. Take my sister's in law website. Here's the procedure I use to upload it to the server:
  1. Open googleanalytics.txt and copy the contents
  2. Open pageend.php and paste googleanalytics.txt content
  3. Open gFTP
  4. Open KeePassX to fetch the site's password
  5. Use gFTP to transfer some of the directories in the development folder (this actually counts as about 10 steps!)
  6. Check if I didn't make a mistake in the gFTP 10 steps!
  7. Open pageend.php and remove googleanalytics.txt content
Some notes on these procedures: I never did steps 1, 2 and 7. It was too much work so I never actually got Google Analytics to work until yesterday. I'm not kidding about step 5 being about 10 steps... I actually uploaded the folders one by one to make sure I got all the right files and that the .svn folders weren't copied. This may seem rather stupid, but since I executed this procedure about once a month it wasn't really a problem, just a nuisance.

Still I decided to automate everything. I did a shell script and right now I have a one step procedure to upload the site:
  1. Run ./
And what did I gain with this 2 hour or so investment?
  1. I learned more about bash programming
  2. I learned how sed works
  3. I learned about wput
  4. I got Google Analytics working on the website
  5. I'll be doing no more mistakes while uploading the site
  6. I can make small changes to the site without thinking about the dreaded upload process
  7. I feel like a better geek! :)

Saturday, May 12, 2007


Are you looking for the best free text editor? Looking for the best wma to mp3 converter? It is quite easy to find free software to do these tasks, the problem is that after you install and test them all, your Windows installation is suddenly filled with registry entries and software you really don't want!

A while a go while browsing LifeHacker I read an article about a software that promised to end these troubles: Sandboxie. So I gave it a try.

I had some wma files to convert to MP3 files and found this free converter, so I installed Sandboxie and run the installer of the software. Everything went OK and the software was installed. I then run the free converter inside the Sandboxie and converted the files. Sure enough the converted files only appeared in the special folder selected by Sandboxie to be the sandbox.

I copied the MP3 files to a real folder on disk, turned off and cleared the contentes of the sandbox. And my Windows installation was exactly what it was before I installed the converter!

I only wished I knew about this software before testing 14 different text editors and totally trashing my Windows installation.