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.
Related
Could anyone please help me with steps how to verify if port is open/available to use.
Basically we have to verify in one of our server (windows) that
7200 port is open for use.
we have one deployment coming up, and team have end point like htts://servername::7200/index.html
If you are trying to use TCP(Transmission Control Protocol) port then run the telnet host port and see the result
connection refused means that nothing is running on that port
accepted means that something is running on that port
timeout means that a firewall is blocking access
I am in developer network and the JBoss to be monitored using JVisualVM is behind client firewall in separate network. JBoss is exposed to us through a NAT. The exposed JMX port works when using telnet from our developer network, but JVisualVM still doesn't find the remote JMX. Apparently this can be due to two things: 1) one or several dynamic RMI sockets need to be accessed, or 2) the "java.rmi.server.hostname" is not defined. My problem may be both points 1 and 2, but apparently since we have SSH access this can be tackled according to this site:
http://rafaelsteil.com/setting-up-jmx-for-jconsole-visualvm-on-ec2-plus-jetty-configuration/
“java.rmi.server.hostname” is the public hostname (like example.com) of your server, without HTTP or anything else. You cannot use an internal address, otherwise you won’t be able to remotely access the service.
However I have one question about the "java.rmi.server.hostname", should the defined IP address be the server internal IP or NAT IP which is publicly expoed to our developer network?
I have actually just tackled this problem myself and figured it out.
I would wager that the problem is the RMI connections - you can't predict which ports it will use and so you can't get it to work with a firewall.
The workaround is to use an SSH proxy:
SSH to the box where your application is running but use the -D option like this:
ssh user#remoteHost -D 9999
This will start a socks proxy on your local machine on port 9999.
Open JVisualVM and in the preferences, under 'network' configure it to use a socks proxy at localhost, on port 9999.
If you do the above, you should then be able to connect to the remote machine as normal and since all the RMI traffic is now going over the SSH proxy, it is punched through the firewall and works nicely.
Good luck :-)
I am trying to tcp connect to a server machine in java, by using its public i.p. but when i run the client application i constantly getting a connection refused error. if i used localhost instead of the public ip, it works perfectly.
i search the internet for several causes of the issue but i couldnt fix it.
i forwarded the port to my machines' local i.p address(192.168.1.3) in routers settings. then i checked if port is listening when i ran the server application using netstat -an. i saw lines like,
0.0.0.0:19999 or []:19999 .
19999 is the port number i am trying to listen to. Then i changed my ServerSocket constructor to the 3 parameter one, which also binds the local address.
InetAddress miad = InetAddress.getByAddress(addr);
ServerSocket socket1 = new ServerSocket(port,10,miad);
addr is the InetAddress of my machines local i.p. After these modifications, when i start the server application, i run netstat and it shows:
TCP 192.168.1.3:19999 0.0.0.0 LISTENING
Here i think that my server is listening on the port specified properly.
I have also disabled my firewall and antivirus software.
I have seen several threads and discussions on the net about the issue, and tried most of the things mentioned there, but i keep getting the connection refused error.
What can i be doing wrong? It runs without any errors when i test with localhost.
This is because of the router (not very sure, but almost). Try to see if a webservice like www.canyouseeme.org can connect to your server.
The main idea is that an internal machine (inside the LAN) cannot connect to a machine inside the same LAN by using the external (public) IP address.
I'm pretty sure that it will work, using you internal ip (192.168.1.3).
And if you are sure that you forwarded ports correctly, CanYouSeeMe will say your server is reachable. If it doesn't, make sure you ISP isn't blocking the ports for some kind of "safety reasons".
To figure out if your problem relates to Java and programming please do
telnet 192.168.1.3 19999
If it can't connect then superuser.com would be a better place to discuss this issue.
I need to connect to a mysql database across a network.
The connection string ive given is
"jdbc:mysql://host/dbname"
i can access the site across the network but the only problem is with the java database connection.
Ive updated the phpmyadmin.conf file giving
# Deny from all
Allow from all
But still the database connection cannot be made.
Please help me..
I don't know much aboud phpmyadmin, but what I did to configure a remote db:
The connection string is: jdbc:mysql://host:port/dbname
The port is 3306 by default
The mysql user is often name#localhost, you need to configure a user for the remote (client) machine (IP address, hostname, wildcard)
HTH
Ok, there are few things you need to check ...
1) If your database got username/password
2) Have you restarted your server after altering phpmyadmin.conf?
3) Make sure you are connecting to the correct port. Ex: mysql://host:port/dbname (if port differs from default.
4) make sure that the PC that have the DB allows incoming connections through the port.
If you still facing problems, try disabling your antivirus/firewall on the PC that have the DM and try.
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.