6

How can I open 8080 port for listening?

In normal situation, I have tomcat7 that listens on port 8080.

     sudo netstat -tanpu | grep ":8080"
tcp6       0      0 :::8080                 :::*                    LISTEN      7519/java

After that, I stop tomcat7 with sudo service tomcat7 stop. So, now 8080 port is closed.

I did sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT to open it, but the port is not listening.

sudo netstat -tanpu | grep ":8080"
tcp6       0      0 127.0.0.1:8080          127.0.0.1:37064         TIME_WAIT   -

How can I open this port (8080) for listening for another application ( not tomcat)?

8

You are confusing two concepts. Iptables handles access control for your networking. When you accept input traffic with a destination of TCP port 8008 that you just means you are letting the internet send traffic to that port. It has no effect on what, if anything, is listening on the port.

To listen on a port you need a program set up to do that. In your original case, tomcat was that program. You stopped it so now nothing is listening on that port. To open it back up as a listener you need to start tomcat, or any other program that you want, to listen on that port. What program you select to listen on that port is entirely dependent on what service you want to provide on that port.

The iptables commands don't affect whether or not your program is listening, it just affects whether or not traffic from the internet is allowed to talk to that program.

If you just want to open up a network port that dumps whatever is sent to it, the program you want is netcat. The command

nc -l -p 8080 

This will cause netcat to listen on port 8080 and dump whatever is sent to that port to standard output. You can redirect its output to a file if you want to save the data sent to that port. If you want anything more sophisticated than a raw data dump, you will need to determine what specific program(s) are capable of handling your data and start one of those instead.

  • I edited my question. I want to open the port 8080 for another application – user15992 Nov 9 '15 at 17:47
  • @user15992 which application? What do you want to do on that port? – casey Nov 9 '15 at 17:48
  • I'm using Docker. I need to receive some information from the container on port 8080 – user15992 Nov 9 '15 at 17:49
  • @user15992 with what program do you want to receive that information? e.g. what kind of information is it? – casey Nov 9 '15 at 17:49
  • @user15992 see my edit for a netcat example. It may or may not be suitable for you, but I can't provide a better answer without more detail from you. – casey Nov 9 '15 at 17:54
3

You do not open a port. You run a program, and the program listens for connections on a port. So you need to ensure that no other programs are listening to port 8080, then you need to configure your program to listen to port 8080, and then you need to run your program.

1

An application (such as tomcat) opens a port; once you stop that application, the port is closed. To open it again, you must (re)start an application that opens that port. You might sudo service tomcat7 start, for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.