Connecting to MySQL on a Remote Server through Port Forwarding and Reverse SSH Tunnel

I had a problem connecting to a remote server that has its ports blocked by the ISP. So technically, I can’t port forward my way into the server. The only way around this is to SSH connect from my remote server to my main server and access the remote server via reverse SSH tunneling. This tutorial will show the steps on how I connected to my database server on the remote server via port forwarding on my PC and reverse SSH tunneling on my main server.

  1. Connect from the remote server (B) to the main server (A).
    • #> screen autossh -R22222:localhost:22 your_remote_IP_address
      • screen – new terminal so you can disconnect and work on other stuffs
      • autossh – reconnects if ssh is broken or is disconnected
      • -R -> tells the client that the remote port to open for the reverse tunnel
      • 22222 -> of course, the port to be used on the other end
      • localhost:22 -> anything attached on port 22222 will reach localhost port 22
      • your_remote_IP_address – not much explaining needed
  2. Now on the main server ( A ), to connect to remote server via the SSH tunnel created.
    • #> ssh -p 22222 username@localhost -L 4406:localhost:3306
      • -p 22222 -> instructs the SSH client to connect to localhost via port 22222
      • -L 4406:localhost:3306 -> this tells the client to forward all packets that is sent on port 4406 to localhost and target port 3306. That’s if the connection succeeds, will be on the remote server already.
  3. On my dev machine, I setup my SSH client ( putty ) to bind to port 99999 and forward  it to the main server on port 4406.
  4. I then have my DB Client attach to port 99999 on connect

Image shown below….

Sources: StackExchange



Shrink/Compact and Re-size VMWare Image in VMWare Player

I had an office PC converted into a VMWare image and wanted to reduce the image file after cleaning up unwanted files and applications. The compact command for the HDD will not totally reduce the image file size in the HOST OS.

VM Image OS is Windows XP. For linux, I will assume a different process.

To literally reduce file size in the host OS, what I did…

  1. Free up disk space.
  2. Zero fill freed up space, I used CCleaner
  3. Shutdown the VM
  4. Run again VMWare Player and right click on the VM
  5. Go to Hard Disk and under Utilities -> Compact
  6. Finish the compact phase and start the VM again.
  7. Install any Partitioning software, I used EaseUS.
  8. After completing the installation, re-size the Hard Disk that has the freed up space to a smaller space that you want
  9. Apply the re-reize
  10. Shutdown the VM, the actual size on the Host OS will now have the reduced file size.

You can expand the size again of the partition/hard disk using the partitioning software and it will not affect the actual VM image file size in the host OS until you start adding new files/data into it.

Installing Gitorious in Ubuntu 12.04 Server – How-To

I wanted to setup my own Git repository locally and with an accompanying front end GUI. Before Gitorious, I installed Git from scratch and also installed Gitolite. That will be another post later on.

Initially I followed the script from but its based on Ubuntu 11.04, there are some missing packages that was not part of the installation script so I had to run the script manually and jump from one tutorial to the other, but the main flow I used is from that script. This is the documentation of the installation process.

Note: I added the PPA to Git’s updated source so I would be using their latest release not Ubuntu’s Git package. ( Google around for Git’s PPA repository, its easy enough 😉 )

Also I was not logged into root ( which I prefer, so I had to do a lot of sudo-ing =S )

Execute these line-by-line… please don’y copy everything then go pressing enter.

Update your Ubuntu server to latest patches and install the packages bellow.

sudo aptitude install build-essential zlib1g-dev libcurl4-openssl-dev postfix apg geoip-bin libgeoip1 sqlite3 libsqlite3-dev libgeoip-dev libpcre3 libpcre3-dev zlib1g zlib1g-dev libyaml-dev libmysqlclient-dev libonig-dev zip unzip memcached git-core git-svn git-doc git-cvs libreadline-dev openjdk-6-jdk sqlite3 libsqlite3-dev libmagick++3 libmagick++-dev libapache2-mod-xsendfile libxslt1-dev libreadline5 libxslt-dev libxml2-dev imagemagick apache2-dev activemq

Update Ruby Gems
Continue Reading

Yahoo! Mail SSL Support

Yahoo! Mail finally has SSL support, or I just noticed it now.
Anyway.. for those who are paranoid or takes security to another level, like me, you can enable SSL support under the Mail Options, under the Options tab. Just enable the check box and save your settings. You need to reload the page as well as clear your cookies after enabling this feature. I had to clear my cookies for the SSL page to load.
Screen shot below.


ExtJS/Sencha Paging Event Handling and Custom Parameters

Sencha ( formerly ExtJS ) has a cool paging toolbar at the bottom of their Grid List component. There are sometimes scenarios that I want to pass values, lets say ID or search terms, for the next/previous page to retrieve. Sadly the buttons ( First, Previous, Next, Last and Refresh ) does not have any onClick event handlers to initialize the parameters before sending to the database. The only thing close to handling this requirement that I found is that you have to set a listener for the beforechange event under Ext.PagingToolbar to initialize the parameters and values before the component sends the data to the server. This way any variables can be set before sending.

The variables that are sent to the server is normally start and limit, what if I want to add a filter to the query? One way is adding baseParams to your data store and change their value using setBaseParam when the beforechange event is fired.

Sample code below.
Continue Reading

VMWare Sphere 5 Boot Delay

Update: This will also work for 5.1 and 5.5.

Note, this is a WhiteBox setup so not all parts are officially supported by VMWare. Specs below…

  • i7 2600K
  • Gigabyte P67A-UD4 B3
  • 8GB DDR3-1866hz 9-9-9
  • 1TB Samsung F3 drives
  • Intel Gigabit Network card

Now, the issue here is that after a clean install of VMWare Sphere 5, boot-up would take at least 5-9 min to complete from a clean power-on. Compared to an upgrade from VMWare Sphere 4.1U1 which will load all the necessary drivers right away after a restart/power-on. It seems like its not detecting the HDD at all at first glance but soon found its way. Further tests, experiments and research yielded that this is a side-effect on how VMWare handled their installation process in VMWare Sphere 5 compared to 4.1U1. In 4.1U1, it uses the MBR for the boot process by default, while in 5.0 it uses GPT. You can fixed this if you force the installer to use MBR during the installation phase.
Continue Reading

Ubuntu 10.04 Server ACPI/APM Support

Advance Configuration and Power Interface (ACPI) or APM ( Advance Power Management ) support for Ubuntu 10.04 was not installed by default after server installation.  I needed this so that during power outage I can just press the power button to automatically shutdown the PC.

sudo aptitude install acpi acpi-support apm

This will install the power-button-power-off feature in you server.

Enable Built-in Intel 82579 Based Ethernet Card in Intel DH61WW Motherboard under Ubuntu 10.04 Server LTS

82579 based Ethernet network cards are only supported in Kernel 2.6.36 and up, thus Ubuntu 10.04 LTS will not have out-of-the-box support for the network card. I needed this to work since I’ll be using this as my server and 11.04 is not LTS, I have no choice. To fix this with the motherboard I have from Intel, here are the steps that I did…

  1. Download the driver source from Intel driver webpage here, or the latest one they have. Double check if the driver supports the version of the network card, the one I have is 82579.
  2. Ready the Ubuntu server, install make gcc g++ and linux headers
    aptitude install make gcc g++ linux-headers-`uname -r`
  3. Un-pack the src driver that you just downloaded, compile and install.
    gunzip [filename].tar.gz
    tar -xvf [filename].tar
    cd [folder_name]/src
    make install
  4. If everything goes well, no error should come out, then enable your new ethernet card.
    modprobe e1000e
  5. You can check your new network card via ifconfig
    Enjoy! 😉

Note: If you update your kernel or linux image via aptitude safe-upgrade or dist-upgrade, you need to remove the e1000e module, re-compile the driver and install the newly compiled driver again.

Blocking DNS requests with Shorewall to prevent OpenDNS Bypass

Here’s a way to block users from using a different DNS address other than your own local DNS server to bypass OpenDNS filtering. I’m currently using Shorewall in an Ubuntu 8.04 LTS server setup as my Firewall, Gateway and DNS, and works nicely. This should also work in 10.04 or other Ubuntu install that has Shorewall firewall. Side effect for the user will be that they wont be able to surf the net until they revert back to the assigned DNS to use.

In your Shorewall Rules file, add this above the other rules.

DNS/ACCEPT  $FW     net
DNS/ACCEPT  net     $FW
DNS/DROP    loc     net
DNS/DROP    net     loc

$FW is your firewall/gateway and in my setup my DNS. You can change $FW to loc:<dns_ip_address> if your DNS is located in another machine other than your gateway.

Have fun raining in on their parade 😉

P.S. You can add filters to allow certain IP or MAC addresses to use DNS outside (i.e. Google DNS ).

Auto Updating OpenDNS with Dynamic IP Address via Ubuntu Server

I have a linux Ubuntu server and a dynamic IP for the DSL connection. The office needs web filtering and getting a static IP will just add cost to the now tight budget. Looking around there is actually a way to update OpenDNS IP address under linux. Below are what is needed to be installed and configured.

  • Any latest Ubuntu server ( I’m using Ubuntu 10.10 Server )
  • ddclient installed (use “aptitude install ddclient”)
  • net connection, I have set up my linux server as a firewall/gateway

After installing ddclient, go to /etc and edit ddclient.conf, below is the format that I used, modify it to suite your configuration.

<openDNS_network_label_here> #this can be found under settings, just the label, nothing else should be added here

Save the new configuration file and restart the client /etc/init.d/ddclient restart
Also make sure that the network that your going to update the IP address has set its Dynamic IP Update option enabled. This can be found under the advance setting of the network.