Ubuntu: cannot establish TCP connection with VPS



Question:

Vince Stewart
I have a VPS on Ubuntu 12 and a home computer on Ubuntu 12. I have a Java application on the VPS which opens a tcp socket listening on port 4000 and also an Http listener. My ssh service operates on port 55555. Once the application has been started I get a this report when I enter on the command line: netstat -t -l

Active Internet connections (only servers)  Proto Recv-Q Send-Q Local Address           Foreign Address         State        tcp        0      0 *:55555                 *:*                     LISTEN       tcp6       0      0 [::]:http-alt           [::]:*                  LISTEN       tcp6       0      0 [::]:55555              [::]:*                  LISTEN       tcp6       0      0 vps.mdomai.com:4000     [::]:*                  LISTEN       

with denyhosts operating my /etc/hosts.allow is just one line

ALL: xxx.xxx.xxx.xxx  (xxx.xxx.xxx.xxx is my static home IP address)  

/etc/hosts.deny is:

ALL:ALL  

I can connect from home using:

telnet yyy.yyy.yyy.yyy 55555  or telnet yyy.yyy.yyy.yyy 8080  (yyy.yyy.yyy.yyy is for my VPS address)  

but with:

telnet yyy.yyy.yyy.yyy 4000   

an error is thrown ("Unable to connect to remote host: connection refused"). This seems like a firewall issue. I am pretty sure I have not changed iptables so should be VPS default. Many thanks for any suggestions. When I issue sudo ufw raw, I get:

IPV4 (raw):  Chain INPUT (policy ACCEPT 21043 packets, 2314421 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain OUTPUT (policy ACCEPT 21077 packets, 2152970 bytes)  pkts      bytes target     prot opt in     out     source               destination           Chain PREROUTING (policy ACCEPT 318 packets, 41345 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain INPUT (policy ACCEPT 42 packets, 7128 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain OUTPUT (policy ACCEPT 347 packets, 24571 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain POSTROUTING (policy ACCEPT 347 packets, 24571 bytes)  pkts      bytes target     prot opt in     out     source               destination           Chain PREROUTING (policy ACCEPT 6241 packets, 691583 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain INPUT (policy ACCEPT 5965 packets, 657366 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain OUTPUT (policy ACCEPT 5936 packets, 614188 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain POSTROUTING (policy ACCEPT 10872 packets, 1131008 bytes)  pkts      bytes target     prot opt in     out     source               destination           Chain PREROUTING (policy ACCEPT 6241 packets, 691583 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain OUTPUT (policy ACCEPT 5936 packets, 614188 bytes)  pkts      bytes target     prot opt in     out     source               destination               IPV6:  Chain INPUT (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination           Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain INPUT (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination           Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination             Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)  pkts      bytes target     prot opt in     out     source               destination           


Solution:1

You have only opened the ipv6 port 4000, as per.

tcp6 0 0 vps.mdomai.com:4000 [::]:* LISTEN

Have you tried via ipv6 on vps.mdomai.com:4000?

What if you go:

netstat -an --inet | grep LISTEN


Solution:2

I am now providing what was the eventual solution to my problem because I think it highlights an important issue for non-experts (such as I am). That being the /etc/hosts file entry.

I was using the same java application at my VPS and my home computer and these were supposed to communicate over TCP. My home computer accessed the internet via a DSL modem which had a fixed IP address. When I tried to direct a message from home to VPS, the java reported timeout (which just meant that a connection could not be made).

I had already allocated my computer a fixed address withing the local network (i.e. 192.168.1.57) because it just seemed sensible. But the crucial change that I eventually made was to register my computer's internet address (i.e. 192.168.1.57) into the Ubuntu file /etc/hosts; now the java running at the home machine read its own "inet address" as 192.168.1.57 instead of 127.1.0.1 and everything started to work. I also needed to provide the VPS with my DSL fixed IP address (203.x.x.x) and a port number which was port-forwarded to the 192.168.1.57 machine. I hope this might help someone.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »