Question

I set up a simple socket that will accept connections on port 1337. It accepts connections via localhost:

$ nc -vv localhost 1337
found 0 associations
found 1 connections:
 1: flags=82<CONNECTED,PREFERRED>
outif lo0
src ::1 port 57224
dst ::1 port 1337
rank info not available
TCP aux info available

Connection to localhost port 1337 [tcp/menandmice-dns] succeeded!
^C

I use Cocoa-PortMapper (https://github.com/mugginsoft/Cocoa-PortMapper) to forward this port to the NAT router I am behind.

portMapper = [[PortMapper alloc] initWithPort:1337];

portMapper.desiredPublicPort = 1337;

[[NSNotificationCenter defaultCenter] addObserverForName:PortMapperChangedNotification object:portMapper queue:nil usingBlock:^(NSNotification *note) {
    NSLog(@"Successfully mapped: %@", portMapper.isMapped ? @"YES" : @"NO");
    NSLog(@"Mapped %@:%hu", portMapper.publicAddress, portMapper.publicPort);
}];

if(![portMapper waitTillOpened]) {
    NSLog(@"Could not open port");
}

It returns YES, and in my routers UPnP Portmap table I can see that there is an active TCP mapping on external port 1337, to internal port 1337 on my computers local IP.

However, connecting to the service via the external IP does not work:

$ nc -vv xxx.89.136.xx 1337
nc: connectx to xxx.89.136.xx port 1337 (tcp) failed: Connection refused

If I set up a port forwarding rule in the router manually, the connection works. Why doesn't the UPnP port mapping work even though my router says it works?

Was it helpful?

Solution

As it turns out, the Port mapping worked from outside my network. When I connected the the server from somewhere else, but not when I connected from the local computer via my external IP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top