March 1, 2017

Setting up Raspberry Pi, wifi, static IP


Goal

Set up headless RPi, Wifi with static IP.

Environment

  • Windows 10 64bit
  • Raspberry Pi 1A, 1B, 3B, Zero
  • External monitor, powered USB hub, wifi dongle, keyboard/mouse.
  • RPi OS; Raspibian Jessie Lite 

Although I will be using RPi headless, the easiest way to set up is hook up external monitor, powered USB hub, connect keyboard mouse + wifi module.  I tried different headless set up, but they all were too inconvenient, especially with RPi models with only one USB port.


Install/Setup Raspberry Pi on SD

  1. Raspberry Pi OS download: https://www.raspberrypi.org/downloads/
  2. I got the easy one, Raspbian Jessie Lite, https://www.raspberrypi.org/downloads/raspbian/
  3. Use Win32 Disk Image to write the OS onto SD card https://sourceforge.net/projects/win32diskimager/ 

Setting up RPi

  1. Insert the SD card and boot it up.
  2. Log in: ID=pi, password= raspberry  
    • Do NOT change the password yet!
  3. sudo raspi-config
  4. configure/enable desired features:
    • hostname
    • interfacing option
    • overclock
    • adavnced options: memory split - 16 is the minimum. Any lower number will set it to default value.
    • localisation (select appropriate selections for your location)
      • Change Locale: uncheck everything, and check en_US.UTF-8
      • Change Timezone: America > New_York
        • Change wi-fi Country Set... : select US
  5. sudo vi /etc/default/keyboard 
    • change to: XKBLAYOUT="us"
  6. sudo reboot
  7. After reboot, test your keyboard typing special characters, such as !@#$%^ ... etc.
  8. If it works fine, then change password, typing "passwd"
    • This step is the last, because if you use special characters in password, the keyboard works properly after localization/keyboard layout change.

Setting up wifi

$ sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

and edit as follow -- change BOLD strings for your wifi:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="## YOUR SSID ##"
    psk="## YOUR WIFI PASSWORD ##"
}

Static IP

$ sudo vi /etc/network/interfaces

and set up as below -- chage BOLD strings to your needs:
auto lo
iface lo inet loopback

iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        dns-nameservers 192.168.1.1

allow-hotplug wlan0
iface wlan0 inet static
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
        address 192.168.1.101
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        dns-nameservers 192.168.1.1

allow-hotplug wlan1
iface wlan1 inet manual
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Don't forget to disable DHCPCD:
$ sudo systemctl disable dhcpcd

Reboot and check your static IP
$ sudo reboot

...after reboot and check...
$ ip addr

Update and Install Software

Update, upgrade:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo reboot

Install Software:

$ sudo apt-get install mc tree screen python figlet dnsutils python-setuptools python-pip

Note: for web server, I prefer Apache for normal servers H/W, but for RPi, it's better to use Nginx as its memory usage is a lot lower.


No comments: