I am currently developing a java application that uses JDBC inorder to connect to MySQL on a computer running Mac OS 10.6.7. The server that I connect to suddenly decided to use SSH. I've managed to connect to the database using MySQLWorkbench so there is nothing wrong with the connection.
My next attempt was to start the terminal and type ssh username#sshserver.com -L 3305:databaseserver:3306 and then start Eclipse and run my application. The terminal prompted me for my password but JDBC could not connect. I tried SSH Tunnel Manager with the following settings: http://imageshack.us/photo/my-images/146/sshb.jpg/ and it also prompts me for the password and then gives a green light. Still no success. The application worked fine before when i just connected without SSH. I would be very grateful for any help, I googled and tested every suggestion I found but nothing worked.
Two issues to keep in mind using tunnels:
Remember that when you use a tunnel, your JDBC client should connect to localhost port 3305 (or 3306, whatever you're actually using). It shouldn't continue trying to connect directly to the remote host.
SSH will tunnel the connection to the remote end and try to connect to "databaseserver" port 3306 from there. If ssh on the remote host can't resolve the hostname that you gave it, it won't be able to make the connection. Since you are tunneling to the database server, you could try connecting to "localhost" or "127.0.0.1" instead.
Related
I work with several IBM i systems. One of them needs me to set an SSH connection before opening an 5250 session. I use the command: ssh -i Keys_rsa L 50023:localhost:23 USER#HOST and after open a 5250 session pointing to IP 127.0.0.1 and it works... But i have a java program that gets some data from the server that cant connect. I need an example of connecting and setting ports. I use JTOpen/JT400 AS400 object but i think i need to move to a SecureAS400 object... Can anyone help?
I am having a aws server(10.10.10.1) which will act as a CISCO Router and it will port forward to another aws server(10.10.10.2). Now I am connecting a server in ssh using the following command.
ssh -i server.pem ec2-user#10.10.10.1 -p 2222
Then it will connect to the Server 10.10.10.2.
Now I need to run a socket program there and I need a client(Which will run in local) program to connect that.
I tried in many ways but I am not able to connect that.
I am new in socket programming please help me to sort out.
Below Answer Result:
I have tried to connect through the SSH tunnel and the tunnel is working for the router and it is not going to the aws server
Please see my tunnel command,
ssh -i server.pem -L 9080:10.10.10.2:8090 ec2-user#10.10.10.1
I also ran a Socket server code in 10.10.10.2 and the client code in my local machine.
Please help me to sort it out
This is your layout
DEV ---ssh---> PIVOT ---ssh---> SERVER
There's an SSH feature called port forwarding that allows the user to open a listening (server) socket on one end of the connection (-L for local, -R for remote) and proxy all socket reads and writes to another machine reachable from that end.
Since PIVOT can connect to SERVER you simply need a proxy on your DEV machine:
me#dev$ ssh -L 9005:server:80 pivot
And then when you talk to localhost:9005 on the development machine you are in fact talking to server:80 via the SSH channel.
Note: if host A can't directly connect to the server and you use it to ssh into B that can, you actually have to setup two forwards, one for each SSH bridge.
I'm using java/spring to connect to a local mysql database and run some integration tests. Sometimes I get Hibernate errors saying that a connection cannot be established. I've noticed this only happens when WiFi is turned on. If I turn off WiFi, and plug in an ethernet cable, the connection established just fine and all integration tasks pass.
I found sources for this issue regarding PHP, where localhost and 127.0.0.1 are treated differently (one uses TCP, while the other uses the local socket), but none of those solutions helped. I have ensured that IPV6 is disabled and the only parameters in the /etc/hosts file is "127.0.0.1 localhost"
Also, simply running mysql from the command line connects just fine, regardless of whether i use
mysql -u<username> -p -h127.0.0.1 //or
mysql -u<username> -p -hlocalhost
Does anyone have any idea why my WiFi connection is preventing me from connecting to my local DB from spring?
I have a play application connecting to a database at 1.2.3.4 but for some reason Play! (and other java apps too) cannot connect to it.
I did try editing the hosts file and setting a name for the IP like app01 1.2.3.4 however it only worked on the box where the DB was hosted and it didn't work for external machines. I can confirm that the right port is open in iptables and I've tried restarting it, too.
If I ping postgres at port 4567 at 1.2.3.4 from the same box, it works. But setting the same IP address in my java apps fail. What's wrong? Is it permissions or iptables issue? Thanks.
Stack trace:
Caused by: java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at java.net.Socket.<init>(Socket.java:392)
at java.net.Socket.<init>(Socket.java:206)
at org.postgresql.core.PGStream.<init>(PGStream.java:62)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
... 35 more
Can you connect to your DB via pgadmin (http://www.pgadmin.org/)?
Can you telnet from your machine on to the DB Server on the given port (telnet 1.2.3.4 4567)?
If you cannot telnet maybe the DB Server is blocking your connections?
Have you set any proxy server either only for java or only for rest of the system?
From the exception it seems more of a networking issue than anything with java...
Can you check firewall settings on the db server. You can try by telnet to check whether you are able to connect or not.
If you're behind a router you WILL BE ABLE to ping it from another local machine (usin the local IP), but you might not be able to ping from the outside if you are not port-forwarding correctly (You can configure this from your router).
Another thing to take in mind is that you CAN'T ping your own external IP from within the network, that means that you can ping 192.168.1.100 (Server) from 192.168.1.xx (Client), but you can't ping 72.15.xx.xx (port-forwarded to 192.168.1.100) from 192.168.1.xx (Client).
In order to do this you have to use an external tool, there are many webs that can do this for you, here's the one that I use:
http://www.yougetsignal.com/tools/open-ports/
If it says the port is open then it is open and it should work now, if it shows closed then you should double check that your firewall is allowing the data, maybe shut it down temporary to see it thats the prob.
If you need help adding a port exception to your firewall or forwarding a port from your router just tell me which distro/routerModel you're using and I'll try to dig some more info for you.
I have developed an application in java that access remote mysql database. While I am running it by netbeans IDE of system which have running that wamp server. But while i try I make connection in another system to remote system database by netbeans it shows following error.
Unable to add connection, Cannot establish a connection to jdbc:mysql://192.168.1.14:3306/test using(CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
Please, kindly help me.
Thanks in Advance
From mysql forums
You could be getting this because (1) the URL of the DB is wrong, because (2) the DB isn't set up to accept connections from the web host, or because (3) some intermediate networking component is misconfigured. (1) is your problem; (2) and (3) might be your problem or the web hosting's problem, depending on where the DB is located, what administrative privileges on the DB that you have, and how the networking is set up.
You need to have the right privileges to be able to connect to MySQL remotely. There are several tools available to set it up.
Here is an article outlining several steps of which the grant step is most commonly needed.
mysql> GRANT ALL ON foo.* TO bar#'202.54.10.20' IDENTIFIED BY 'PASSWORD';
There has also been problems reported when connecting to MySQL databases in Windows Vista, but i'm not sure wether this is relevant to this case or not.
Do you have ssh access to the server? I would have run a tunnel with ssh, plink or putty (ssh -L 3305:127.0.0.1:3306 192.168.1.14) and then use this connection url
jdbc:mysql://127.0.0.1:3305/test
It would be easier to assist if we'd known your operating system.
If this is a deployment situation, opening the firewall for port 3306 from your IP address is probably the right thing. In linux you might find the settings in /etc/sysconfig/iptables, but your sysadmin may have other safe guards in place. You must also verify that mysql is actually listening on the IP-address, and not only localhost.
MySQL is standard protected so you can't access it remotely. You'll have to grant MySQL as well as the user connecting to MySQL access from outside the MySQL-machine.
Perhaps a low-level network issue.
Can you ping that IP ?
Can you telnet to that IP/port ?
e.g. telnet 192.168.1.14 3306
Establishing whether you can talk to the machine and whether you can create a basic TCP connection to the MySQL process on that machine will tell you a lot - is your network sound, is a process listening on that port etc.