Help us understand the problem. What is going on with this article?

Headless Raspberry Pi - Setup WiFi and Static IP Address

Objective
Here we will learn how to Setup headless Raspberry Pi. We want to setup Raspberry Pi headless to access it via PuTTY (ssh) on a different machine or PC (using the same WiFi 2.4GHz network) with a static IP address.

Method 1 (See updated: Headless Raspberry Pi Setup Guide)

Follow Step A to Step D for setup Raspberry Pi without connecting it to a keyboard and monitor.

Step-A Setup wifi manually

Once we wrote image to SD card(see, Step 1 Download and Write Image to SD card). We need to setup wifi manually for Headless Raspberry Pi. Create wpa_supplicant.conf file, enter country, ssid, psk (password) details.

# In this example I am using macOS
cd /Volumes/boot/
nano wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=«your_ISO-3166-1_two-letter_country_code»

network={
    ssid="«your_SSID»"
    psk="«your_PSK»"
}

Step-B Enable SSH

To enable SSH on Raspberry Pi, please create an empty file with the name ssh (without any extension). Place this file in the root directory of the SD card.

# In this example I am using macOS
cd /Volumes/boot/
touch ssh

Step-C Scan IP address

Insert sd card in Raspberry Pi and power on. Wait for a minute.
Now search IP through one of the following app
(windows): https://www.advanced-ip-scanner.com/
(macOS): IP Scanner app (download from App Store)
ex.

# In this example I am using macOS

raspberry p IP Scanner

Step-D: Connect via ssh

Connect to your Raspberry Pi via ssh, use the IP address given in your result (Step-C)

# In this example I am using macOS (terminal app), on Windows you can use PuTTY.
ssh pi@192.168.179.2 -p 22

Password 'raspberry'

Method 2

If above method is not working for you, you need to follow Step 1 to 7 by connecting Raspberry Pi to a keyboard and a monitor.

Step 1 Download and Write Image to SD card

Download 'RASPBIAN STRETCH LITE' Image

Using 'Etcher' software to write 'RASPBIAN STRETCH LITE' Image to the SD card

Step 2 Power On

  • Plug in keyboard, monitor HDMI cable and insert SD card into Pi
  • Plug the power cable into Pi
  • Login with user name 'pi' and password 'raspberry'

Step 3 Switch to 'Root' user

To access Pi with 'Root' user, we will setup a new Password for the 'Root' user.

#login as a root user
pi@raspberrypi:~ $ sudo -i

#see the user name 'root'
root@raspberrypi:~#

#set a new password for the root user
root@raspberrypi:~# passwd

#Enter new UNIX password:
#Retype new UNIX password:
#passwd: password updated successfully
root@raspberrypi:~#

To access pi as a 'Root' user via ssh, we need to allow 'PermitRootLogin'.

#set 'PermitRootLogin' as 'yes'
root@raspberrypi:~# nano /etc/ssh/sshd_config

#Find 'PermitRootLogin prohibit-password' text and replace it as 'PermitRootLogin yes'
PermitRootLogin yes

#save sshd_config file (ctrl + x)

Step 4 Enable SSH Server

Enable remote command line access to your Pi using SSH

root@raspberrypi:~# raspi-config

#select -> '5 Interfacing Options Configure connections to peripherals'
#select -> 'P2 SSH Enable/Disable remote command line access to your Pi using SSH'
#'Would you like the SSH server to be enabled?' Yes

#'The SSH server is enabled' Ok

Step 5 Setup WiFi Network

Find SSID (You can use your mobile or computer)
find ssid of your wifi

You can also try the following command to find SSID via your Raspberry Pi.

root@raspberrypi:~# iwlist scan | grep SSID

                    ESSID:"HUMAX-58FAB"
                    ESSID:"HUMAX-59092"
lo        Interface doesn't support scanning.

eth0      Interface doesn't support scanning.

                    ESSID:"HUMAX-C86EB"
root@raspberrypi:~# raspi-config

# Select -> '2. Network Options Configure network settings'
# Select -> 'N2 Wi-fi Enter SSID and passphrase'
# 'Please enter SSID' 
# Ok
# 'Please enter passphrase. Leave it empty if none.'
# Ok
# Finish

#Reboot your Pi (see at the left bottom and type 'reboot' command) 
root@raspberrypi:~# reboot

# Login with user 'root' and Enter the password.

# Test outgoing traffic
root@raspberrypi:~# ping google.com
#64 bytes from xxxx-in-xx.xx.net (xxx): icmp_seq=1 ttl=53 time=49.9 ms
# press (ctrl + c)

Step 6 Setup static IP

#1. Enter following command
root@raspberrypi:~# ip -4 addr show dev wlan0 | grep inet
#output, ex.
inet 192.168.179.1/24 brd 192.168.179.255 scope global wlan0

#2. Enter Following command
root@raspberrypi:~# cat /etc/resolv.conf
# Generated by resolvconf, ex.
# nameserver 192.168.179.1

#3. Enter Following command to create a backup file
root@raspberrypi:~# cp /etc/dhcpcd.conf /etc/dhcpcd.conf.backup

#4. Open dhcpcd.conf file
root@raspberrypi:~# nano /etc/dhcpcd.conf 

#Based on the above information (#1 and #2), we will add following lines to the top of dhcpcd.conf
# We want to use static ip_address as 192.168.179.111 (based on #1, it should be in between lower address bound 192.168.179.1 and upper address bound 192.168.179.255), values of static routers and static domain_name_servers (based on #2)

interface wlan0
static ip_address=192.168.179.111
static routers=192.168.179.1
static domain_name_servers=192.168.179.1

#save the file (Ctrl + x) and reboot your pi
root@raspberrypi:~# reboot

Step 7 Connect via an another machine

We can try to access Pi (Connection Type: SSH) with "Host Name: 192.168.179.111" and "Port: 22" via an another machine but using the same wi-fi network. You can use PuTTY. In the following example I am using 'Terminal' app on my Mac computer.

ssh root@192.168.179.111 -p 22

#The authenticity of host '192.168.179.111 (192.168.179.111)' can't be established.
#ECDSA key fingerprint is SHA256:A32M**************************************.
# Are you sure you want to continue connecting (yes/no)? yes

#Enter the password (That we set in Step 3 for the 'root' user)
root@192.168.179.111's password: 

root@raspberrypi:~# 

Raspberry Pi Setup WiFi and Static IP

Happy Coding!
My Website (Learn Python) - https://PyBoys.com/
My Facebook Page - https://www.facebook.com/PythonMachineLearning/

Tutorial
Pythonで学ぶ機械学習入門チュートリアルシリーズは英語で書いています。Enthusiastic to learn and teach Python, Machine Learning and Deep Learning.
https://www.pyboys.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした