I have my Raspberry Pi (Model B Rev. 2 UK) connected to my PC through an Ethernet cable, which provides the Pi with an internet connection and allows me to SSH into it. It took me a few hours to get this working (pinging raspberrypi in the Windows console could not find the hostname and Pi finding software did not work, static IPs of allowed me to connect if I set my LAN to but the network did not work, I have no HDMI screen so I needed to edit the SD Card files in a Linux VM, etc.) and now I can finally connect and SSH.

My computer to which the Pi is connected is connected to the internet via WiFi and has the IP on the Wifi card and on the Ethernet card.

The Pi can access the network, but I would like to access the Pi outside of my house. My port 22 is portforwarded and my Connection sharing of my Wifi adapter has an SSH entry added.

Edit: here is my /etc/network/interfaces file:

iface eth0 inet static

  • Do you have public ip provided by your isp? If so then you could access raspberry on Internet by using port-forwading feature on your router.
    – xdhe
    Commented Jun 18, 2016 at 22:17
  • @xdhe I know what you are saying, and as I said I have port-forwarded the required port. The problem is that the Pi is not connected directly to the router - it is connected to the PC, and although it has an independent IP on the PC-Pi LAN network, it does not have one on the WLAN network to which the Computer is connected - both the Raspberry Pi and the Computer are recognised as the same device by the Router.
    – The Marg
    Commented Jun 18, 2016 at 22:31
  • However, I decided to just move the router closer to me and plug it into the Ethernet port. This solved all the issues, after I reverted the interfaces file to initial configuration of course. As for the actual question, the answer would be something like: If someone wants to connect to, redirect them to locally, without them knowing they are redirected
    – The Marg
    Commented Jun 18, 2016 at 22:32
  • Uhh sorry i didn't read the whole question. Its still bit unclear to me. Did your raspi have both wifi and ethernet connected to the router? Maybe this link could help tho goo.gl/KB7mu9
    – xdhe
    Commented Jun 18, 2016 at 22:56
  • @xdhe The raspberry is not connected to the router at all.
    – The Marg
    Commented Jun 20, 2016 at 19:08

1 Answer 1


Here's a diagram of your network:

Router <---> PC <---> Pi

First off, your Pi is connected to your computer, which is connected to your router. I'm not sure why, but here's one way it can be done:

  1. Make sure your router's port forward is pointed to your PC ( and not the Pi ( This is because packets cannot magically skip a router when jumping between subnets. Therefore, your PC has to act as a router. I assume you have a subnet mask of

  2. Now that your primary router knows where to forward traffic, your PC should now be receiving packets on port 22. The problem is that your PC doesn't know what to do with them, so treating your PC as a router, you somehow have to "port forward" port 22 on your PC.

If you're on Linux, it should be a breeze. If you're on Windows, you somehow need to find an equivalent of these Linux commands:

iptables -t nat -A PREROUTING -p tcp -i wlan0 --dport 22 -j DNAT --to-destination
iptables -A FORWARD -p tcp -d --dport 22 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

These basically mean if traffic is coming from wlan0 (wifi) port 22 and is heading to, accept it, NAT it, then forward it.

I haven't tried bridging the two connections (WiFi and Ethernet) right away. If that's the case, simply point the port forward to the Pi directly on your main router. (or at least that's how I think Windows networking works.)

Visualizing the network first really helps with coming up with a solution, hence the diagram.

  • Unfortunately I am not on Linux, but your answer may help someone, I just decided to move and solve my problem.
    – The Marg
    Commented Jun 20, 2016 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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