Raspberry Pi based Wifi Routers – Hacker Noon

This rather long post steps you through the process of setting up a WiFi router on a Raspberry Pi Zero W or Raspberry Pi 3. There are a number of reasons why you might want to do such a thing:

  • Setup a demo any where access point for your web apps
  • Create deployable devices for use in network testing.

As an added bonus this post also describes how to install NodeJS and the AWS command line tool to created scripted workflows with AWS.

Setting up the Raspberry Pi

Setup the Raspberry Pi Zero W using Raspbian Lite. The version I used was 2018-06-27-raspbian-stretch-lite.img

The following instructions are Mac OSX centric but not too different for how you’d do this using other operating systems.

Locate SD card

On Mac you can do this using diskutil via the command line. Execute the command below and look for a /dev/disk that matches the size of your SD card. For me, that’s /dev/disk2

$ diskutil list

Unmount the SD card

Next unmount the SD card using the disk number.

$ diskutil unmountDisk /dev/disk2

Flash the OS image

Use the dd command to flash the Raspbian lite image onto your SD card. Be careful when doing this!

This is a good time to mention that the dd command can be very dangerous if you’re not careful using it. Always make sure that you’re pointing dd to the correct disk drive! You wouldn’t want to erase the wrong drive. After all, there’s a reason why the command is known as the Disk Destroyer, but that’s not what dd stands for. See this bit of dd history if you’re interested.

$ sudo dd bs=1m if=./2018-06-27-raspbian-stretch-lite.img of=/dev/disk2 conv=sync

While dd is running you can press ctrl-t on your keyboard to check on the status. The SD disk flash can take a while based on the speed of your SD card.

It’s recommended that you use a Class 6 or Class 10 microSDHC card for performance reasons.

Once the copy completes you can cd onto the card:

$ cd /Volumes/boot

Create an empty ssh file to tell the OS that you wish to enable SSH access:

$ touch ssh

Next create a wpa_supplicant.conf file with the following, make sure to replace your ssid and psk fields with your router’s settings.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid="YOUR-SSID"
psk="YOUR-PASSWORD"
scan_ssid=1
}

Safely unmount the SD after your changes.

$ cd ~
$ diskutil unmountDisk /dev/disk2

Connecting to and configuring your Raspberry Pi

Next, insert the SD into your Pi Zero and boot the device.

Give that a minute or so to complete then try pinging the device to locate it.

$ ping raspberrypi.local

Or locate the device using your network router or a Wifi scanner such as Who’s on My Wifi

You can ssh into the device using:

$ ssh [email protected]
or
$ ssh [email protected]

The default password is raspberry.

If you encounter the following error:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

then simply edit your .ssh/known_hosts file and remove the line that has the raspberrypi entry.

$ vi /Users/${USER}/.ssh/known_hosts

So moving right along, once you sign in, the first order of business is to change the password!

$ passwd

The username will still remain pi but you’ll be able to sign in using your new password.

You can optionally proceed to make other tweaks using the raspi-config utility if you’d like.

$ sudo raspi-config

Next make sure the OS is up to date:

$ sudo apt-get update
$ sudo apt-get upgrade
  • A note regarding the update command above: if while installing packages you get an error such as E: Unable to fetch some archives, maybe run apt-get update or try with — fix-missing? Then rerun sudo apt-get update and retry the package update that failed. This has proven to be successful.

Lastly, here take a moment to setup your timezone:

$ sudo dpkg-reconfigure tzdata

read original article here