1

I am stuggeling with port 9000: Connection refused error.

I work on Ubuntu 14.04 and faced the problem when trying to run Hadoop in a non-distributed mode, as a single Java process (compare Hadoop 2.4.1 documentation). I tried to follow Hadoop Wiki suggestions on this error (hadoop/ConnectionRefused) but I did not succed (I am a beginner Ubuntu user and find it difficult even to 100% understand the suggestions given). I posted a stackoverflow question from which I conclude that I have some general problem with port 9000 Connection.

telnet output:

martakarass@marta-komputer:~$ telnet localhost 9000
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

nmap output:

martakarass@marta-komputer:~$ nmap localhost

Starting Nmap 6.40 ( http://nmap.org ) at 2015-04-27 11:09 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00022s latency).
Not shown: 995 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
139/tcp open  netbios-ssn
445/tcp open  microsoft-ds
631/tcp open  ipp
902/tcp open  iss-realsecure

Nmap done: 1 IP address (1 host up) scanned in 0.08 seconds

Netcat configuration:

I tried to make use of the following command to force the 9000 port to be open:

nc -k -l 9000

but it did not work well (I was still not able to perform the standlone operation mentioned and linked above).

Judging from my google research results, I see that the problem is quite common and poses a huge struggle especially for those who are not good at "admin-job-related issues". As I belong to those, I kindly ask for answers to the following questions:

  • Q1: What is the origin of such problem in general? (Some for a layman introductory words / references about basic issues connected to ports / connections etc. would be very very welome).

  • Q2: How to deal with this problem?

Update.

sudo netstat -nlp | grep :9000

returns nothing.

3 Answers3

1

TL;DR first, more details following:

"Connection refused" is the error you get when you try to connect to a service on a computer or server (or locally on your own computer) when the said service is either not listening on the specified TCP port (wrong port or service not started), or when a firewall explicitly rejects a connection instead of ignoring the request (not very common behavior).

And now a little more detail:

It can only happen with TCP (UDP services are sessionless) and this error is indeed very common for sys admins.

When a client application connects to a TCP service, it'll send a first packet with the SYN flag set. If we simplify, there are two possible answers to that:

  • The server actualy listens on the required TCP port and replies with a SYN-ACK packet to acknowledge the SYN packet, after which the clients rends an ACK packet to "confirm" to the server that the SYN-ACK was received. That's the moment where you have established a TCP session, and when you can start "talking" with the server.
  • The server receives your SYN packet, but isn't listening on the requested port. The connection is rejected with a packet that has the RST (reset) flag set. This is 99% of the time when you get the infamous "connection refused".

How do I fix this ?

Well, there are a few things you can check: Are you querying the right port on the client side ? Is your service started ? Is it listening on the right port ?

Those three questions will generally help you solve your issue.

Quick generic command to be entered on the server (the machine that runs the service)

Checking that the service is listening on the expected port

ss -nat | grep <enter port number here> | grep LISTEN

Some people on older systems might also use this

netstat -an | grep <enter port number here> | grep LISTEN

If you don't see anything here that looks like your port number, your service is either not started or not listening on the port number you specified.

Checking that the service is running

service <service name> status
1

Try do disable iptables:

sudo service iptables stop && sudo service ip6tables stop

Then restart hadoop. If this helped you need make proper configuration for your firewall.

UNIm95
  • 704
0

Eventually, I managed to make my service listen to the port 9000 by adding to the /etc/ssh/sshd_config file the following line:

Port 9000

I followed this serverguide/openssh-server (it contains also some important remarks about making a copy of the original file, restarting the sshd server application etc.)

After this I can see:

telnet output:

martakarass@marta-komputer:~$ telnet localhost 9000
Trying 127.0.0.1...
Connected to localhost.

nmap output:

martakarass@marta-komputer:~$ nmap localhost

Starting Nmap 6.40 ( http://nmap.org ) at 2015-05-01 18:28 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00023s latency).
Not shown: 994 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
631/tcp  open  ipp
902/tcp  open  iss-realsecure
9000/tcp open  cslistener

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds

netstat output:

martakarass@marta-komputer:~$ sudo netstat -nlp | grep :9000
tcp        0      0 0.0.0.0:9000            0.0.0.0:*               LISTEN      16397/sshd      
tcp6       0      0 :::9000                 :::*                    LISTEN      16397/sshd