-2

I have a centos 6.5 machine running a java server socket on port 9000. All these while it have been running well and suddenly when I tried to start it using this command java myService nothing seems to work. Below are some commands I tried to find why its not running.

# netstat -tpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 *:sunrpc                    *:*                         LISTEN      1762/rpcbind
tcp        0      0 *:ssh                       *:*                         LISTEN      7105/sshd
tcp        0      0 localhost:ipp               *:*                         LISTEN      1911/cupsd
tcp        0      0 localhost:smtp              *:*                         LISTEN      2128/master
tcp        0      0 *:41002                     *:*                         LISTEN      1883/rpc.statd
tcp        0      0 *:sunrpc                    *:*                         LISTEN      1762/rpcbind
tcp        0      0 *:http                      *:*                         LISTEN      5914/httpd
tcp        0      0 *:ssh                       *:*                         LISTEN      7105/sshd
tcp        0      0 localhost:ipp               *:*                         LISTEN      1911/cupsd
tcp        0      0 localhost:smtp              *:*                         LISTEN      2128/master
tcp        0      0 *:33914                     *:*                         LISTEN      1883/rpc.statd
tcp        0      0 *:15003                     *:*                         LISTEN      4695/java

Also I run this command to find below result.

$ grep -e 9000 -e 9700 -e 9900 /etc/services
cslistener      9000/tcp                        # CSlistener
cslistener      9000/udp                        # CSlistener
board-roar      9700/tcp                        # Board M.I.T. Service
board-roar      9700/udp                        # Board M.I.T. Service
iua             9900/tcp                        # IUA
iua             9900/udp                        # IUA
iua             9900/sctp                       # IUA

What is confusing is that all these while it have been running well and suddenly when I start my original service I dont see its listening on port 9000? What could be the issue?

8
  • 2
    That is a list of services. It appears to be completely irrelevant to your problem, which unfortunately you neglected to explain. You should explain exactly what your problem is. Dec 1, 2014 at 11:00
  • My problem when I try to run my service like usual it just nothing is listening on port 9000
    – user132638
    Dec 1, 2014 at 11:04
  • 1
    The comment really still does not help folks on here determine whats going on. Try to edit your question, and do a step by step tear down with a full synopsis EG: Introduction, What you tried, What you expected to happen, what actually happened. in each section, 1) I did X, 2) then I did Y and so on. Details, Details and more Details, the more you include and the better you fill out your question, the faster folks will help. Don't worry if you don't understand things, type it out anyway, let folks see what your attempting to do.
    – shawty
    Dec 1, 2014 at 11:28
  • Do you execute netstat -tpl as root? Your normal user might not see everything. Dec 1, 2014 at 11:36
  • @Shawty I have rephrase and added the result of netstat -tpl too hope its clearer now?
    – user132638
    Dec 1, 2014 at 12:24

1 Answer 1

0

Under Linux/Unix generally only one application at a time can access a TCP port.

If you have something listening on say port 9000, then try to run something else on that, the second application will refuse to start up.

In your case, you need to identify first, what the application is that's listening.

Before I start listing commands however, you MUST run all of these as a root user, or user with system admin privileges, if you do not, then you will ONLY see the output that is allowed to be seen by the running user.

The lsof command can be used to get a list of all ports open on a machine, and the name of the process that has them open.

In my case typing

lsof -i -n -P

Gives me the following output

postgres  16507 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  16507 postgres    9u  IPv4 2626399      0t0  TCP 127.0.0.1:5432->127.0.0.1:43769 (ESTABLISHED)
postgres  16508 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  16508 postgres    9u  IPv4 2631818      0t0  TCP 127.0.0.1:5432->127.0.0.1:43770 (ESTABLISHED)
postgres  16509 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  16509 postgres    9u  IPv4 2631575      0t0  TCP 127.0.0.1:5432->127.0.0.1:43771 (ESTABLISHED)
postgres  16510 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  16510 postgres    9u  IPv4 2631576      0t0  TCP 127.0.0.1:5432->127.0.0.1:43772 (ESTABLISHED)
postgres  16511 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  16511 postgres    9u  IPv4 2631825      0t0  TCP 127.0.0.1:5432->127.0.0.1:43773 (ESTABLISHED)
postgres  16512 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  16512 postgres    9u  IPv4 2631826      0t0  TCP 127.0.0.1:5432->127.0.0.1:43774 (ESTABLISHED)
cleanup   16513  postfix   15u  IPv4 2626405      0t0  TCP 127.0.0.1:43775->127.0.0.1:5432 (ESTABLISHED)
cleanup   16513  postfix   16u  IPv4 2631596      0t0  TCP 127.0.0.1:43776->127.0.0.1:5432 (ESTABLISHED)
postgres  16514 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  16514 postgres    9u  IPv4 2631595      0t0  TCP 127.0.0.1:5432->127.0.0.1:43775 (ESTABLISHED)
postgres  16515 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  16515 postgres    9u  IPv4 2626409      0t0  TCP 127.0.0.1:5432->127.0.0.1:43776 (ESTABLISHED)
postgres  18500 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  18500 postgres    9u  IPv4 2451534      0t0  TCP 127.0.0.1:5432->127.0.0.1:36938 (ESTABLISHED)
postgres  18689 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  18689 postgres    9u  IPv4 2452045      0t0  TCP 127.0.0.1:5432->127.0.0.1:36981 (ESTABLISHED)
postgres  22048 postgres    8u  IPv4   10293      0t0  UDP 127.0.0.1:38068->127.0.0.1:38068
postgres  22048 postgres    9u  IPv4 2472075      0t0  TCP 127.0.0.1:5432->127.0.0.1:37727 (ESTABLISHED)
root@poweredge2:/proc#

I've sanitised some of the output for obvious reasons

As you can see, in the far column, you have a number of lines that have "127.0.0.1:00000" where 00000 is a port number.

If you apply a grep to this, then you should be able to filter out the application that's using port 9000 EG:

enter image description here

lsof -i -n -P | grep 5432

I have nothing running on port 9000 on the system I'm testing this on, so as you can see from the image I've used port 5432 (Which I happen to know has a postgres instance running)

Once you have a list of suspected applications sitting listening on the port in question, if you then look at the first two columns, you'll see the app name and the process id.

In my image above for example, the postgress service in the bottom most line is using pid = 22048

If i was then to use

kill 22048

That process would then get terminated by the operating system, and free up the port it was listening on.

Warning

It goes without saying that randomly killing processes in a live running system is both dangerous and irresponsible. Be sure that you have permission to kill these processes, and that you are 100% sure you have the correct program identified.

If your doing this on a system that you don't have permission on, you very likley will land yourself in a whole heap of trouble, moto of the story:

THINK before you press that enter key

Alternatively, if you CAN'T kill the process listening on port 9000, then you should absolutely try to re-configure the service you do want to run, to listen to a different port.

2
  • lsof -i -n -P | grep 5432 should give me what programme is running it right? Once if I find out the programme how to n stop it just kill will do ? Or any thing stopping selinux etc?
    – user132638
    Dec 1, 2014 at 16:19
  • My comment tells you everything you need to know already to stop it, but you need to substitute the '5432' that I used for the correct numbers that your investigating. I used '5432' because I don'y have anything running on port 9000. Head the warning I put at the bottom though, and make sure your not killing anything you shouldn't be.
    – shawty
    Dec 1, 2014 at 16:44

Not the answer you're looking for? Browse other questions tagged .