Saturday, October 22, 2011

Using SSH tunneling to access database through ssh

rh6 is the client, vmxdb04b is the database server,

firewall port open is incomming port 22 for vmxdb04b

donghua@rh6:~$ ssh -N -p 22 oracle@vmxdb04b -L 8888/vmxdb04b/1521

oracle@vmxdb04b's password:

-p 22 oracle@vmxdb04b: build ssh connection to vmxdb04b

-L 8888/vmxdb04b/1521 : Start a local listening port 8888 on rh6, and forward all the packet data to vmxdb04b:1521. Here the vmxdb04b can change to any host for forwarding purpose.

-N instructs OpenSSH to not execute a command on the remote system.

donghua@rh6:~$ netstat -na|more

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0* LISTEN

tcp 0 0* LISTEN

tcp 0 0* LISTEN

tcp 0 0* LISTEN

donghua@rh6:~$ sqlplus donghua/donghua@localhost:8888/orcl

SQL*Plus: Release Production on Sat Oct 22 09:40:32 2011

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select username,program,machine,paddr from v$session where sid=userenv('SID');


------------------------------ ------------------------------------------------





DONGHUA sqlplus@rh6 (TNS V1-V3)