LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Listen to a port (https://www.linuxquestions.org/questions/linux-newbie-8/listen-to-a-port-891119/)

rediff08 07-11-2011 10:59 AM

Listen to a port
 
Hey Guys,

I would like to open a port 1004. My firewall is disabled. I want a program to listen to this port. Is there a way I could check if the port is open/listening? I tried telnet localhost 1004 and it keep saying connection refused. I don't know if telnet is a way to check if the port is open?

Thanks

anomie 07-11-2011 11:04 AM

On the server itself:
Code:

$ netstat -ltn
(i.e. Display "l"istening "t"cp sockets, and do "n"ot resolve IPs or port numbers.)

rediff08 07-11-2011 11:12 AM

This is the output for that command
Code:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address              Foreign Address            State
tcp        0      0 127.0.0.1:2208              0.0.0.0:*                  LISTEN
tcp        0      0 0.0.0.0:617                0.0.0.0:*                  LISTEN
tcp        0      0 0.0.0.0:111                0.0.0.0:*                  LISTEN
tcp        0      0 0.0.0.0:2001                0.0.0.0:*                  LISTEN
tcp        0      0 0.0.0.0:1521                0.0.0.0:*                  LISTEN
tcp        0      0 0.0.0.0:4434                0.0.0.0:*                  LISTEN
tcp        0      0 127.0.0.1:631              0.0.0.0:*                  LISTEN
tcp        0      0 127.0.0.1:25                0.0.0.0:*                  LISTEN
tcp        0      0 0.0.0.0:3003                0.0.0.0:*                  LISTEN
tcp        0      0 127.0.0.1:2207              0.0.0.0:*                  LISTEN
tcp        0      0 :::22                      :::*                        LISTEN

I am not seeing port 1004. I'm not sure how to add 1004 to that list.

anomie 07-11-2011 11:28 AM

Tcp port 1004 will appear on that list once you actually have a daemon that's listening for connections on it. Currently there isn't one.

rediff08 07-11-2011 11:50 AM

Oh okay. Thank you

baxzius 07-11-2011 12:03 PM

once solved,please make this thread as solved .please!

saiju@wavecrest.gi 07-11-2011 12:25 PM

HI ,

Try this method to open 1004 port..

1) check weather 1004 is listening or not.
[root@Saiju-VM-2 ~]# netstat -ant | grep 1004
[root@Saiju-VM-2 ~]#

2) if it is not listening.

[root@Saiju-VM-2 ~]# vi /etc/httpd/conf/httpd.conf
Edit httpd.conf in apache configuration.

Add Listen 1004 line .

#
#Listen 12.34.56.78:80
Listen 80
Listen 1004

3) restart httpd service.
[root@Saiju-VM-2 ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for Saiju-VM-2
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
4) check weather 1004 port is listening or not..

[root@Saiju-VM-2 ~]# netstat -ant | grep 1004
tcp 0 0 :::1004 :::* LISTEN

Let me know if you face any issues..

Thanks & regds
Saiju

anomie 07-11-2011 12:28 PM

@saiju: With respect, why in the world would he want to run an unnecessary daemon (Apache web server)?

If the goal is to put some arbitrary listener on tcp 1004, then nc(1) is lighter and is already installed on most systems.

rediff08 07-11-2011 03:01 PM

I tried using nc -l 1004 but it doesn't really give me any output.

TB0ne 07-11-2011 03:51 PM

Quote:

Originally Posted by rediff08 (Post 4411733)
Hey Guys,

I would like to open a port 1004. My firewall is disabled. I want a program to listen to this port. Is there a way I could check if the port is open/listening? I tried telnet localhost 1004 and it keep saying connection refused. I don't know if telnet is a way to check if the port is open?

Thanks

The real question here would be, what are you trying to do? You can pretty much make ANY service listen on ANY port...what are you trying to run? What are you looking to do?


All times are GMT -5. The time now is 02:18 AM.