0

On our router (which has WiFi), we have one ethernet port which is currently being used by my laptop. I need my raspberry pi model B rev. 2 connected to the network as well, but it doesn't use WiFi. (My laptop can, but i prefer ethernet.) I don't want to purchase a network switch, so what I've been doing is sharing our family Macbook Pro's WiFi connection using internet sharing, and connecting the pi to the Macbook over ethernet. The pi now has internet, but here's the catch: I want to run a web server on the pi, and be able to access it from my laptop. Is there a way to port forward over internet sharing?

P.S. If it helps, the web server will be running on port 8080.

To visualize the setup:

 Home Router --+-- WiFi  -- MBP* -- Ether -- Pi
               |
               +-- Ether -- Laptop
  • Internet Sharing

nohillside
  • 100,768
  • Unfortunately, I won't be able to x11forward ssh into the mac and type in the pi's ip, because i haven't installed a browser that uses x11, and i dont want to. – Lennon McLean Jul 20 '20 at 01:35
  • I think i found my answer at this link. however, im not certain it will work so help is still appreciated. https://apple.stackexchange.com/questions/156847/port-forwarding-from-a-shared-connection Edit: Nvm, natd does not exsist any more :( – Lennon McLean Jul 20 '20 at 02:06
  • If I understand you config correctly, you have a double NAT issue which causes all sorts of problems. There's a a NAT behind your router and and one one behind your Mac so the Pi is double NAT’ed. Get an inexpensive switch - port forwarding will be problematic at best – Allan Jul 20 '20 at 11:54
  • there is no nat in the macbook. if you could tell me how to forward port 8080 on the raspberry pi so that all tue other computers in my network (namely my laptop) can access it, that would be great. if you cant, then this question isn't for you. – Lennon McLean Jul 20 '20 at 11:58
  • You simply can’t have internet saring without a NAT network. What’s the IP addresses of all your interfaces including the Pi? – Allan Jul 20 '20 at 12:20
  • @Allan ok then there is an NAT in the macbook, but I dont need to expose the web server to the full internet, just to the other computers in the home network. in other words, i only need ti get through one NAT. – Lennon McLean Jul 20 '20 at 12:22
  • Does https://apple.stackexchange.com/questions/100492/redirect-traffic-using-pf-along-with-internet-sharing help? – nohillside Jul 20 '20 at 12:46
  • @nohillside pf is only used to redirect traffic to another port (as I know it), so no, but thanks anyways :) – Lennon McLean Jul 20 '20 at 17:57
  • @Allan the pi's ip on eth0 (ethernet) is 192.168.2.7, the mac's ip on bridge100 (internet sharing) is 192.168.2.1 the mac's ip on en1 (wifi) is 192.168.0.114, and my laptop's ip is 192.168.0.110 on eth0 (ethernet) (yes it has linux) – Lennon McLean Jul 20 '20 at 18:01

2 Answers2

1

I got it! I wrote a node.js script, like so, to redirect requests on port 8080 of the macbook to port 8080 of the raspberry pi. the pi's ip is 192.168.2.7.
the script:

var net = require('net');
net.createServer(function(socket) {
  var raspberrypi = net.connect(8080, '192.168.2.7');
  raspberrypi.on('connect', function() {
    raspberrypi.on('data', function(data) {
      socket.write(data);
    });
    socket.on('data', function(data) {
      raspberrypi.write(data);
    });
  });
}).listen(8080);
0

The reason I had to connect to the network via ethernet was because I lost the WiFi USB adapter for the pi. I found it and fixed it, and also got WiFi working on my laptop, so I'm very happy right now.

Also, I'm pretty sure someone will close this question for being too specific.