TransWikia.com

How can I access a computer behind internet sharing?

Ask Different Asked by Lennon McLean on October 30, 2021

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 

2 Answers

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.

Answered by Lennon McLean on October 30, 2021

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);

Answered by Lennon McLean on October 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP