i am using the java sbbi library to forward ports. but my router is conected to another router, so the external ip of the first router is a ip that was given by the second router dhcp. is there a way to forward the ports on the second router as well? here is my code:
InternetGatewayDevice[] devices=InternetGatewayDevice.getDevices( 1000 );
System.out.println("Found "+devices.length+" Devices");
InternetGatewayDevice dev = devices[ 0 ];
System.out.println(dev);
System.out.println( "External IP = " + dev.getExternalIPAddress() );
System.out.println( dev.addPortMapping( "Streamternet", "TCP", null, 1333,
"192.168.0.105", 8888, 0 ) );
System.out.println( "waiting for connection" );
HTTPServer.main(null);
I log into router 1 and go to the DMZ settings and put the WAN IP address of the 2nd router there. Now router 1 is out of the way for port forwarding and triggering as all incoming connections are now being forwarded to router 2. Now in router 2 I can setup my port forwarding & triggering rules just like normal. So here is a quick step by step.
If your router is UPNP compatible you can easily port forward using UPNP by mapping certain ports (TCP or UDP) with the following program. Can you use this method for other programs like discord / skype / whatever you want? Yes. This item has been added to your Favorites.
The first layer of NAT has the IP range 192.168.1.1-255, and then 2nd layer has IP range 192.168.50.1-255. On a machine inside the 2nd layer of NAT, just setup port forwarding with upnpc like normal. $ upnpc -a 192.168.50.123 6667 6667 tcp ... $ upnpc -l # this will confirm the rule is in place ...
UPnP Port Mapper communicates with your router with the UPnP protocol, so you’ll also need a router with UPnP enabled to use this application. If UPnP is disabled on your network’s router, this program can’t do anything. After downloading UPnP Port Mapper, double-click the .jar file to launch it.
As far as i know it's not possible with your current setup because you cannot access your router's gateway directly.
There are 2 solutions i can think of.
Hope i could help.
As @Danpe said in his answer, UPnP won't let you open ports when you're behind multiple NATs.
As I'm also working on a P2P software and from what I've gathered, here is what one can try to connect two peers:
If above doesn't work, app is either behind a router that doesn't support UPnP, NAT-PNP... or you're behind multiple levels of NATs. Now you can either:
Communicate with the user of the app that she needs to open ports on those routers. This is, as you've mentioned in comments, an unfortunate solution as it assumes advanced technical knowledge from the user. But it does seem to be what some companies actually do. See here for example.
Use a relay server such as a one using TURN protocol through which users with closed ports will communicate. This relay server may be one or more of peers whose ports are open (as is the case with uTorrent), or it can be your server, or a combination of the two: if there are peers with open ports, use those, otherwise use your own server (this is the case with Skype).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With