Accessing MYSQL server behind firewall using SSH

So, you want to access a MYSQL server but you only have an SSH terminal…
Not to worry, you can use SSH tunnelling to do this!

Basic Example

Example: ssh -L 3306:localhost:3306 user@IP -p SSHPORT

Now how do you control this dark ssh sorcery? Let’s break it down.

1) 3306:localhost:3306

  •  Open a port 3306 on my local machine to redirect
  • localhost:3306 means we are tunnelling to 3306 on SSH machine

2) user@IP

This is your username and the IP address of the server

3) -p SSHPORT

This is the ssh port if it is not on 22.

Another Example

ssh -L 9000:192.168.212.1:5000 user@192.168.2.1 -p 1234

You would use this if you wanted to:

  • use your computer port 9000
  • to access the port 5000 on IP 192.168.212.1
  • through the SSH server 192.168.2.1
  • with SSH server port on 1234

Happy SSHing!

 

Allowing/troubleshooting AirServer through windows 7 firewall

AirServer allows apple mobile devices (Ipads, Iphones) to stream the screen using the airplay protocol.

Unfortunately, AirServer did not work immediately right off the bat on my own machine and required modifying the Advanced firewall settings.

If you see anything appearing even you you have selected Airplay on the device, it may be an issue of the firewall.

In order to test this, disable the firewall for the local network using the instructions here.

On my own computer, I entered the advanced settings of windows firewall and added two inbound rules in order to expose freely the UDP and TCP ports required by AirServer.

Advanced Firewall Settings

Inbound Rule

Three

 

 

So, if your having issues using AirServer but do not want to disable the firewall add manual rules for the following ports as described on their site.

AirServer Ports

Using DD for windows to resume a failed file transfer from specific point

If you were transferring a large file and the network cut out you can either restart the copy, or use a tool such as DD for windows to resume from a specific point.
For very large files it is recommended to use better copiers such as robust copy.

I had a file that was 1 421 304 KB in size and I had copied around 60 percent.
Therefore, I needed to start after 852782 KB .

The following command was used:

dd bs=2k if=z:SURCE_FILE of=D:DESTINATION_FILE seek=5767168 skip=426391 --progress

Since skip takes number of blocks defined with size bs= , we skip to 426391.

426391  * 2KB = 852782 KB

Tunneling to VNC over SSH

You may want to connect to a headless/monitorless linux pc with a vnc server running that only exposes an SSH port.

I have used the following steps from windows.

  1. Server:
    Run VNCServer

    If not running already start your server.  You can set the resolution using -geometry tag. This will open a new port/session.

    vncserver -geometry 1920x1200

     

  2. Workstation:
    Create the tunnel to VNC port
    This maps the local pc port 5905 to localhost:5905 on the remote machine. VNC uses ports 5901 to 5909.

    ssh -L 5905:localhost:5905 menelaos@menelaos.server.net -p 22

     

  3. WorkStation:
    Create tunnel if needed of X-Server

    ssh -L 6005:localhost:6005 menelaos@menelaos.server.net -p 22

    More

Bash script to monitor server HTTP output length and e-mail an alert

Below is an example of a script that uses CURL to monitor the length of various HTTP server outputs and output a response if this is different than 103 characters.
This is my first bash script, so I had some reading/experimenting to do and it is quite rough.

Anecdote – forcing wifi bridge to connect to other AP

This is personal anecdote about how to  re-connect to a disconnected wifi bridge if your main AP is off/broken.

Usually our network is layered as follows:

Laptop
<-----[WIFI]----->
DLINK Powerline Enabled AP
<-----[Copper Power Wire]----->
TP LINK Powerline
<-----[Ethernet]----->
ADSL Modem & AP
<-----[WIFI]----->
Asus WL-330N3G 
<-----[ethernet]----->
WD Media Player

So 2 weeks ago the ADSL Modem (AP including LAN DHCP server) died but in the network I continued seeing the SSID. After scanning the network we saw that the ASUS wireless bridge transmits with the same SSID as the ADSL modem / AP. The actual modem is a Belkin but the wireless bridge uses the same SSID as seen below from an iphone app called “Net Analyzer”.

photo 1

More

Connecting to JMX from visualVM using SSH tunnel

I used the following source:

https://bowerstudios.com/node/731

I did this in windows using git bash that has ssh command. You can also do using cygwin or pure minggw.

1) Run ssh tunnel command in command prompt (I do this in git bash/MINGGW32).

ssh -D 9010 -p 22 root@IP -v

2) Run your application on server with JMX options

java -Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=9010 
-Dcom.sun.management.jmxremote.local.only=false 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false -jar 
application.jar

3) Run visualVM through socks proxy to connect:

visualvm -J-Dnetbeans.system_socks_proxy=localhost:9010 
-J-Djava.net.useSystemProxies=true

4) Actually add your JMX remote connection in visualVM

MysqlDump directly on mounted remote directory (CENTOS, Linux, Unix)

If you don’t have space to write a dump file, or want to directly send your SQL to another server (without intermediate transfers), using a remotely mounted folder is a way to go.

There are various mounting options such as:

  • SSHFS
  • NFS
  • Windows Shares (SAMBA)

More

Repeating a unix command every X seconds

The watch command can be used to repeat a command every X seconds.

Examples:

Monitor Disk Usage (updated per second)

watch -n1 df -h

DiskPrint Hello World (every second)

watch -n1 echo “Hello World”

Reference: 

http://unix.stackexchange.com/questions/10646/repeat-a-unix-command-every-x-seconds-forever

rebit 5 first impressions – synching to network share

Initially I was very happy with the idea of how rebit works. However, now having used it for two days I am dissappointed.

The option to have real-time painless synchronization is quite needed. Personally, I wanted to synch with my NAS at home, and my RAID 6 server at work.

Problems began immediately while trying to configure backup to network shares. The interface is very non-intuitive, but once you figure it out it becomes easy.

The initial backup is VERY slow. In addition to this, I couldn’t ascertain reliably what exactly was going on with my files. At some point the files in the rebit browser backup folder seemed empty.

I can say that my experience up to now has not been efficient nor easy. Instead, simply copying my files using fastcopy finished in 2 hours.

I will give a shot to the rebit 6 trial but I’m glad I didn’t fork over the 40 euros.