Opening A Port On A Server?

Discussion in 'Security' started by phish3rz, May 13, 2008.

  1. #1
    Hi, I am running a dedicated Linux server and I need to open a port so I can connect a script to a port, the only ports I have open is my cpanel and some others which all require authentication and are private. I have looked everywhere for a tutorial but i cannot find one. I dont know if it is a simple task or a complex one but i just wonder if there is anyone out there who knows how to open a port, it probably will need to be TCP or UDP.

    Any help wouldn't go amiss :)
    Thanks,
     
    phish3rz, May 13, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Are you running any kind of firewall, e.g. APF or just IPTables?
     
    jayshah, May 17, 2008 IP
  3. phish3rz

    phish3rz Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    IPTables i think :S
     
    phish3rz, May 18, 2008 IP
  4. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
  5. chtdatweb

    chtdatweb Well-Known Member

    Messages:
    1,473
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    160
    #5
    If your running linux it should be iptables. To open a port is very simple, logged in as root do this.

    iptables -A INPUT -p udp -m udp --dport PORT -m state --state NEW -j ACCEPT

    Where i have written PORT this is the port number you want opened

    This example is when opening a sensite port such as ssh, for security you can have only your IP address access it.

    iptables -A INPUT -s YOURIPHERE -p tcp -m tcp --dport PORT -m state --state NEW -j ACCEPT

    YOURIPHERE = your ip address
    PORT = port you want opened
     
    chtdatweb, May 18, 2008 IP
  6. phish3rz

    phish3rz Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    When ever I enter the above commands into SSH when i've logged in, and i've edited the port it says command not found.
     
    phish3rz, May 20, 2008 IP
  7. phish3rz

    phish3rz Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    oh, i was logged in as admin not root! Figured it now i hope
    thanks guys.
     
    phish3rz, May 20, 2008 IP
  8. phish3rz

    phish3rz Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Sorry about been a pain,
    The commands do work but when i go to http://www.myurl.com:Theport it says it cannot be connected.

    After i run the commands to open the port i use the command
    service iptables save
    to save the new configurations,

    Any help where im going wrong guys?
     
    phish3rz, May 20, 2008 IP
  9. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #9
    Try to telnet locally to see if the application is actually working.

    For example:

    telnet localhost THEPORT

    just replace THEPORT with the port ;)

    Jay
     
    jayshah, May 20, 2008 IP
  10. phish3rz

    phish3rz Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    When i do the above command, no it isnt working.
     
    phish3rz, May 20, 2008 IP
  11. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #11
    The next step would be to determine if something is listening on that port.

    Log in to the box and type this:
    netstat -a | grep LISTEN
    Code (markup):
    What you will see is a lot of output that should include IP addresses and ports. The ports may be translated into the services that usually run on that port so "80" becomes "http".

    Your port should be listed there. If it is not listed, this means that your script is not listening on the port you have opened and you won't be able to communicate with it.
     
    Ladadadada, May 31, 2008 IP
  12. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #12
    olddocks, Jun 12, 2008 IP