1

I have a Raspberry Pi running Raspbian which is connected over ethernet to my router. The router has been running both with DCHP and Static IP addresses and over the local LAN I can connect fine over ssh, for example. However, the device never shows in the list of connected devices on the router so I cannot configure port forwarding for external access.

I would have said that this was a problem with the router but I have now tried with two different routers (BT Home Hub 2 and Edimax BR-6428) with the same results so I am thinking that it must be the OS.

Is there some setting that I need to make the device appear to the router?

  • As an aside, I have three Raspbian Rpi's connected wirelessly, using upnpc to advertise themselves and set up whatever forwardings they require to do their job(s). File server, Web Server, SSH, music, video output, and so on. So much easier to let them set things up automatically, I don't miss adjusting router settings. – lornix May 21 '14 at 22:31
1

If your Rpi is on the network with a static IP, it never talks to the router to 'advertise' itself.

A really simple solution is to use the upnpc program (in miniupnpc package) to set your port forwarding dynamically. MUCH easier than tweaking the router all the time.

You'll need upnp enabled on your router, usual caveats apply here.

The following command will forward internet port 1337 to internal port 22 on the server:

upnpc -e "ssh server" -a $(hostname --all-ip-addresses) 22 1337 tcp

See the man page for upnpc of course for more details, but here you can see -e sets the name of the forward setting, -a lists the server's IP addresses, the last three items are inside port, outside port, type of connection (tcp/udp).

I use a similar command to forward port 80 from outside to my own web server too, don't have to set up a DMZ with all that that entails security-wise. (and no, I didn't put my actual external ssh port number here... duh!)


Another method would be to set a static DHCP setting for your Rpi in the router, and shift your Rpi back to dynamic IP (DHCP) mode... but unless you're going to also set up some sort of name-server system, this gets hairy fast since your RPi address COULD change. (Yes, I know it's not supposed to... )

Letting it set up its own forwarding using its current IP address is the best way, as it adapts as needed.

  • Sorry for the delay. Yep that works great but seems to be lost on a reboot. Is there anyway to make to persist through reboots? – williamsdb May 28 '14 at 15:32
  • I use a cron job to reassert this every 15 minutes, takes care of either the Rpi or the router being rebooted/reset. Just easier that way. Also, upnpc -l (ell), shows current uPnP forwardings, so you can check it from any other computer on your network too. Very handy. – lornix May 29 '14 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.