in ,

An always-available, online-capable Raspberry Pi in your pocket, Hacker News


      

        

  

These days, I’m building a lot of hardware projects based on the ubiquitous Raspberry Pi mini computer. Especially with the Raspberry Pi Zero W (an even tinier version, with theWdenoting the wifi-capable version), you can have one anywhere and can power it from any USB power source.

A number of write-ups exist telling you how to enable “Ethernet gadget mode”, which essentially lets you use one of the Zero’s USB ports as a hardwired network connection. But one additional thing that I wanted was the ability for the Zero to proxy through my development computer when attached and whenthatcomputer was on wifi. That is, I can talk to the Zero from my laptop anytime (such as when offline on an airplane), but if my laptop is on wifi, the Zero can also reach the internet — for downloading updates, developing applications, whatever — just like my Mac can. That way, I don’t have to mess with the Linux-based wifi configuration on the Pi for each and every network I find myself on.

Want to know more? Read on.

I’m going to assume you know your way around both the Raspberry Pi ecosystem and the Mac development environment.

On the Pi

  1.     

    Get a Raspberry Pi Zero W setup and online so that you can get into it over SSH. I really likeBerryLAN, which is a light layer over Raspian plus an iOS app, because I can get a brand new Pi setup without ever plugging in a keyboard or monitor to it.

      

  2.   

  3.     

    Change the last line of/ etc / network / interfacesto read:

        

    source /etc/network/interfaces.d/*

        

    This is a slight tweak over the default which does what was originally intended, which is to actually pay attention to files in that directory. What a great idea!   

  4.   

  5.     

    Create a file at/ etc / network / interfaces.d / usb0.confwhich contains:

        

    allow-hotplug usb0 iface usb0 inet static     address 10 .7.2 / 24     gateway 10 0.7.1     dns-nameservers 10 0.7.1

      

  6.   

  7. Addnameserver 0.7.1to/ etc / resolv.conf.
  8.   

  9. Addmodules-load=dwc2, g_etherafterrootwaitto/ boot / cmdline.txt. These are related to USB mode and ethernet support.
  10.   

  11. Adddtoverlay=dwc2to the end of/ boot / config.txt.
  12.   

  13. Reboot the Pi (sudo reboot).

On the Mac

  1.     

    Update the defaultInternet Sharingconfiguration NAT (proxying, essentially) network. This won’t affect internet sharing to other devices (other than to use this new LAN for them, too).

        

    $ sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.nat NAT - dict-add SharingNetworkNumberStart 10 .7.1  $ sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.nat NAT -dict-add SharingNetworkNumberEnd  .7. 254  $ sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.nat NAT -dict-add SharingNetworkMask 255. 255. 255

      

  2.   

  3.     

    Once your Pi is plugged into the Mac and booted up, configure the newRNDIS / Ethernet Gadgetinterface manually:

        

    • IP Address:10 .7.1
    •       

    • Subnet Mask:255. 255. 90
    •       

    • Router:0.7.1
    •     

        

    Despite its name, this “gadget” is actually the Mac side of the equation, so you are basically setting yourself up as the router for this shared, physical LAN. If this interface is green, your Pi should be reachable. If you issue asudo halton the Pi, the interface will go red once the Pi is shut down.

      

  4.   

  5.     

    Configure yourInternet Sharingto share wifi (if available) with the gadget interface.

        

      

You’re all set!

Once you’ve done this, you will always be able to plug your Pi into your Mac and then SSH into it (ssh pi @ 10 .7.2). If you are on wifi, the Pi will also have an internet connection through your Mac.

Enjoy! I hope this helps folks get some work done a little more conveniently.

References

      

    

Brave Browser
Read More
Payeer

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings

Mathematical Treasures, Hacker News

danistefanovic / build-your-own-x, Hacker News

danistefanovic / build-your-own-x, Hacker News