Headless Configuration

Headless configuration is a setup, when the Raspberry Pi is configured without using a display (TV or Monitor). In this case, it is connected to a PC or laptop and through that additional computer SSH login is possible to the Pi. (So basically no USB or HDMI port is used on the Pi, only the ethernet port.)

With headless setup, a Raspberry Pi model B (without any prior configuration) can be turned into a fully functioning device. Which means, if you have a WiFi router and a computer (which computer is able to connect to this WiFi network), and you plug in network cable into the Pi and into this computer, then your are be able to use Internet on the Pi.


Headless setup (+static IP) on Windows:
I. write Raspbian image to SD card
II. find out IP address of the Pi
III. configure static IP
IV. set up network Bridge on Windows

==========================================


I. write Raspbian image to SD card

1. download and unzip Raspbian: https://www.raspberrypi.org/downloads/raspbian/
(After unzipping, an .img file should be there.)

2. If needed format SD card, I used: https://www.sdcard.org/downloads/formatter_4/index.html
(If SD card was partitioned before, and you cannot see its full size, start SD Card Formatter, choose Option and "Format Size Adjustment: On", which will bring back the original capacity of the card.)

3. Write image file to the SD card, I used: https://sourceforge.net/projects/win32diskimager/
(Start "Win32 Disk Imager", select .img file and the drive where the SD card is, and then "Write")
(After finished, from Windows you will see just a small partition (~60MB), the rest is hidden from Windows.(it is a Linux EXT4 partition).)

4. Create a file, and name as "ssh" on SD card
(On this Raspbian version, ssh server is not enabled by default, but if an empty file, named as "ssh" (without quotes) has been created, ssh login will be possible after boot.)
(So put SD card on a Windows, and create a new file with name: ssh)

==========================================


II. find out the IP address of the Pi (Pi is not powered on yet)

In order to login to the Pi (after it is powered on, which will happen later), we need to know its IP address.

There are more possibilities to find out IP:
- connect the Pi to the router directly with a cable, and after login to the admin page of the router
- "arp -a" or IP scanner tools, which will show the IP address, but those did not work for me
- install a DHCP server on windows, which will assign a specified IP to the Pi

I did not have access to the router, and those arp things also did not work for me, so I tried dhcp server which worked very well. (I did not have any prior knowledge about DHCP servers, and how to configure those, but luckily there are some really easy applications for this purpose.)

1. install a DHCP server on Windows, I used: http://www.dhcpserver.de/cms/
(It is a portable application, after unzipping and reading the manual, start the wizard: dhcpwiz.exe)
(choose a network card (where your cable is plugged in), protocol (enable HTTP too), a pool of IP addresses (I used range 192.168.137.1 -254)...., then start dhcpsrv.exe, run as a tray app., right click on the tray, and choose open, this will show in browser when an IP address has been assigned to the Pi.)

2. plug in network cable (to the computer and to the Pi) and power on the Raspberry Pi
(leds should start blinking, and about 2 minutes later, if you refresh the dhcp browser window, the Pi IP address should show up)

3. ssh to the Pi from Windows, with an SSH tool, I used: http://mobaxterm.mobatek.net/
(putty is also a good to use ssh; for ssh use the IP address found out with the dhcp server above.)

4. login to the pi
(user: pi, and password: raspberry)

==========================================


III. configure static IP

With headless setup on the Pi, it is probably easier to use a static IP address (not a DHCP assigned changing IP address), so every time Pi is booted up, login is possible with the same IP address. To achieve this some preparation is needed.

1. collect network details of Wifi adapter, with command on Windows: ipconfig /all
For the Wifi (wireless) adapter it will show these details:
IPv4 Address. . . . . . . . . . . : 192.168.1.112(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
DNS Servers . . . . . . . . . . . : 192.168.1.1

The IP address of the router (which is the gateway/DNS server as well) is 192.168.1.1, IP of the Wifi adapter is 192.168.1.112, and subnet mask: 255.255.255.0. Based on these values, I decided to use the static IP for the Pi 192.168.1.113, which fits to the above network range.

2. edit /etc/dhcpcd.conf on the Pi
Originally I thought /etc/network/interfaces file needs to be modified, but in interfaces file this is written:
pi@raspberrypi:/ $ cat /etc/network/interfaces
...
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

So I added this at the end of /etc/dhcpcd.conf:

interface eth0
static ip_address=192.168.1.113/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

more details: https://www.modmypi.com/blog/how-to-give-your-raspberry-pi-a-static-ip-address-update


3. shutdown the Pi
Or reboot if you want to login to the Pi on the new static IP (192.168.1.113). I did shutdown and went to the next step (IV. network Bridge).

If you want to login to the Pi without network Bridge (without internet) the network adapter on the Windows needs to be configured, to have a static IP from the same subnet as the Pi. For example on Windows configure a static IP: 192.168.1.115, for the network adapter where the cable is plugged in (not the WiFi adapter).

On Windows: Control Panel --> Network --> Devices, and at the properties of the Network adapter: choose Internet Protocol version 4 and then properties. (Fill in IP address (192.168.1.115), subnet mask (255.255.255.0), gateway (192.168.1.1) and DNS server (192.168.1.1)


==========================================

IV. set up network Bridge on Windows

In order to be able to use Internet on the Pi, we need to create network Bridge on the Windows.
(It means the Wifi adapter and the Ethernet adapter on the Windows will be connected (bridged), so these devices are joined to the same network.)


Based on the "ipconfig /all" command this is the final setup, what we want to achieve:






1. Create a network Bridge
(Control Panel --> Network --> Devices, then choose both the Wireless and Ethernet adapter --> Properties --> Bridge Connections)



This will create a new device there, with the name "Network Bridge". At this point the Pi (if the Pi would have been turned on, but for me it was not), connected to the bridge port should have access to the network and internet, but the computer hosting the bridge won't be able to access the internet unless a static IP address  is configured on the Bridge Device.

2. add static IP on the Bridge device
To regain internet on the computer hosting the Bridge add a static IP there.
(Control Panel --> Network --> Devices, then choose Network Bridge --> Properties --> Inernet Protocol version 4, then Properties)



(I have addedd the Wireless IP address (192.168.1.115), subnet mask (255.255.255.0), gateway (192.168.1.1) and DNS server (192.168.1.1)


3. Reboot Windows + Power On Raspberry Pi
At this point SSH should work, and also Internet should be available on the Pi and on the Windows.

More details about Network Bridge on Windows: http://www.windowscentral.com/how-set-and-manage-network-bridge-connection-windows-10


No comments:

Post a Comment