Results 1 to 7 of 7

Thread: Open a port on a router on the network.

  1. #1
    Join Date
    Mar 2006
    Location
    Grunnen, Nederland
    Beans
    463
    Distro
    Ubuntu 10.04 Lucid Lynx

    Open a port on a router on the network.

    Hi, I'm writing a small python script. Part of it needs to listen on a predefined port for incoming messages from over the Internet. The problem is that it would most of the time be behind a router. How do i tell the router to forward the port to me (many p2p programs for instance already support this, however i couldn't find a singe bash, nor python function for this)?

    thanks in advance.

  2. #2
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,270
    Distro
    Kubuntu

    Re: Open a port on a router on the network.

    Configure your router to forward the data coming in on port "A" to the port "B" that your app is listening on.

    The port "A" that you advertise to your peers does *not* have to be the same as the port "B" that your app listens on, however it can be the same.

    If your router is "lame" (such as mine, which is the Linksys WRT54G) and it does not permit port-forwarding from a port "A" to a port "B", then you can consider using the application called "redir". I believe the following is needed, and then you will need to reference the help-manuals to setup the configuration:
    Code:
    sudo apt-get install redir

    P.S. If you have a Linksys Router (WRT54G), then there exists a special OS for it called "tomato". I have not used it, but I have heard good things about it.

  3. #3
    Join Date
    Aug 2006
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Open a port on a router on the network.

    You can do it using the router's interface, which is different on every model. The site below might help.
    http://portforward.com/

  4. #4
    Join Date
    Aug 2007
    Location
    127.0.0.1
    Beans
    1,800
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Open a port on a router on the network.

    Old Linksys (not wireless) have that option under:

    Application & Gaming > Port Range Forwarding.

    It's a common procedure, you code with ports as you would normally, and then redirect ports accordingly.
    "Just in terms of allocation of time resources, religion is not very efficient. There's a lot more I could be doing on a Sunday morning."
    -Bill Gates

  5. #5
    Join Date
    Apr 2006
    Location
    Atlanta, USA
    Beans
    427

    Re: Open a port on a router on the network.

    I believe what you are referring to is uPnP. If your router supports this, you can request that it automatically set up port forwarding for you (see: uPnP NAT traversal. As for how you would code this, I haven't the foggiest idea. Try googling for uPnP, IGD, NAT Traversal, etc.

    Hope this helps.
    Here we are, trapped in the amber of the moment. There is no why.

  6. #6
    Join Date
    Mar 2006
    Location
    Grunnen, Nederland
    Beans
    463
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Open a port on a router on the network.

    Quote Originally Posted by johnl View Post
    I believe what you are referring to is uPnP. If your router supports this, you can request that it automatically set up port forwarding for you (see: uPnP NAT traversal. As for how you would code this, I haven't the foggiest idea. Try googling for uPnP, IGD, NAT Traversal, etc.

    Hope this helps.
    I was indeed referring to upnp. However i was wondering if there wasn't just a simple program available that would just do something like

    forward [router ip] [router port] [my ip] [my port]

    and that being all.

  7. #7
    Join Date
    Apr 2006
    Location
    Atlanta, USA
    Beans
    427

    Re: Open a port on a router on the network.

    Hi,

    try downloading miniupnpc (not d) from here: http://miniupnp.free.fr/files/ and compiling it. It should generate a file 'upnpc-shared'


    Code:
    ./upnpc-shared
    upnpc : miniupnpc library test client. (c) 2006-2009 Thomas Bernard
    Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
    for more information.
    Usage : ./upnpc-shared [options] -a ip port external_port protocol
                    Add port redirection
            ./upnpc-shared [options] -d external_port protocol [port2 protocol2]Â*[...]
                    Delete port redirection
            ./upnpc-shared [options] -s
                    Get Connection status
            ./upnpc-shared [options] -l
                    List redirections
            ./upnpc-shared [options] -r port1 protocol1 [port2 protocol2] [...]
                    Add all redirections to the current host
    It looks like the "-a" option will do exactly what you want. It will automagically discover your router IP if the router is UPnP compatible.

    Hope this helps.
    Here we are, trapped in the amber of the moment. There is no why.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •