Server in a NAT subet? - TCP-IP

This is a discussion on Server in a NAT subet? - TCP-IP ; Hi, I have a few NAT related questions. Here is my scenario; I have a generic wireless ADSL modem/router, and I would like to open a TCP/IP connection from outside the subnet to a node in the subnet. My thinking ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Server in a NAT subet?

  1. Server in a NAT subet?

    Hi,

    I have a few NAT related questions. Here is my scenario; I have a
    generic wireless ADSL modem/router, and I would like to open a TCP/IP
    connection from outside the subnet to a node in the subnet.

    My thinking is:

    1. The router in its basic form of operation does simple IP
    translation? Ie, 192.168.1.2 <-> A.B.C.D where A.B.C.D is the IP
    address given by the ADSL provider.

    Basically, the router is what it says on the tin, an IP router?

    2. Connection establishment:

    2.1. Client in the subnet, server somewhere on the internet:

    The client in the subnet opens a TCP connection to the server,eg,
    connect() call. The sockaddr returned by the server accept() function
    has the IP address of the router and the port number which the client
    opened? Basically the router replaced the IP header from subnet address
    to its address.

    Server sends data: The router has a table of open connections (stateful
    NAT), and forwards the IP packet to the node which has opened the
    connection.

    2.2. Server in the subnet and client somewhere else with a global
    routable address.

    I have a problem at this point. I would like the server to publish its
    address which gets stored in a database and at one point in time a
    client reads the address and decides to call the server.

    I can't publish node's IP address as this is not reachable from
    outside, and I am not sure what happens if I publish the routers
    address.

    Question 1. Is it possible for a node in the subnet, to know that it is
    in a subnet and its address isn't global. How would an application
    check this? I mean what socket functions do I need?

    Question 2. Let's assume the node knows it is in a subnet, how would
    the node read the global address of the router?

    Question 3. Let's assume the server published router's address and
    the client connects(). Since, there is no open connection from within
    the subnet, how does the router know where to route the packets?

    Question 4. Is this where port forwarding comes in play? The router
    sends all packets destined for a certain port number to the node which
    is registered for port forwarding? But this requires administrative
    changes in the router, what if the user moves to a subnet, gets IP with
    dhcp and can't register for port forwarding?

    Question 5. Is there such a broadcast packet (ARP message) in the
    routers as "who is listening on port X?"? The server that publishes
    the address is listen()'ing for connect() from clients.

    Any general comments on how to write a server behind a NAT would be
    helpful.


    Regards,

    UM


  2. Re: Server in a NAT subet?

    In article <1164295739.596216.164940@l39g2000cwd.googlegroups. com>,
    "UM" wrote:

    > Hi,
    >
    > I have a few NAT related questions. Here is my scenario; I have a
    > generic wireless ADSL modem/router, and I would like to open a TCP/IP
    > connection from outside the subnet to a node in the subnet.
    >
    > My thinking is:
    >
    > 1. The router in its basic form of operation does simple IP
    > translation? Ie, 192.168.1.2 <-> A.B.C.D where A.B.C.D is the IP
    > address given by the ADSL provider.
    >
    > Basically, the router is what it says on the tin, an IP router?
    >
    > 2. Connection establishment:
    >
    > 2.1. Client in the subnet, server somewhere on the internet:
    >
    > The client in the subnet opens a TCP connection to the server,eg,
    > connect() call. The sockaddr returned by the server accept() function
    > has the IP address of the router and the port number which the client
    > opened? Basically the router replaced the IP header from subnet address
    > to its address.
    >
    > Server sends data: The router has a table of open connections (stateful
    > NAT), and forwards the IP packet to the node which has opened the
    > connection.
    >
    > 2.2. Server in the subnet and client somewhere else with a global
    > routable address.
    >
    > I have a problem at this point. I would like the server to publish its
    > address which gets stored in a database and at one point in time a
    > client reads the address and decides to call the server.
    >
    > I can't publish node's IP address as this is not reachable from
    > outside, and I am not sure what happens if I publish the routers
    > address.
    >
    > Question 1. Is it possible for a node in the subnet, to know that it is
    > in a subnet and its address isn't global. How would an application
    > check this? I mean what socket functions do I need?


    All addresses are "in a subnet". I think you mean "in a private subnet".

    It could look at its address and notice that it's in one of the private
    address ranges.

    > Question 2. Let's assume the node knows it is in a subnet, how would
    > the node read the global address of the router?


    It could connect to some server out on the Internet, and ask it what
    address it sees the connection coming from. For instance, you can go to
    the web site http://www.whatismyip.com and it will display the router's
    IP. You could also make use of a dynamic DNS service like dyndns.org;
    these provide a client application that interacts with their server.

    > Question 3. Let's assume the server published router's address and
    > the client connects(). Since, there is no open connection from within
    > the subnet, how does the router know where to route the packets?


    See the answers to 4 & 5.

    > Question 4. Is this where port forwarding comes in play? The router
    > sends all packets destined for a certain port number to the node which
    > is registered for port forwarding? But this requires administrative
    > changes in the router, what if the user moves to a subnet, gets IP with
    > dhcp and can't register for port forwarding?


    Correct.

    > Question 5. Is there such a broadcast packet (ARP message) in the
    > routers as "who is listening on port X?"? The server that publishes
    > the address is listen()'ing for connect() from clients.


    There's a protocol called Universal Plug & Play (UPnP) that allows the
    server to broadcast its availability, and UPnP-compatible routers will
    automatically forward the port.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

+ Reply to Thread