Headless Raspberry Pi

Step 1. Download a lite Raspbian image

Download the version you need. As we want to install a headless version download the Raspian XXXXX Lite version.

Step 2. Copy the image

From a Linux terminal use the following command to find your SD Card:

sudo fdisk -l

This will show you something like

Disk /dev/sdc 14.86 Gib ......

Ensure you select here the correct disk.

Afterwards copy the image with the following comand. Replace /dev/sdX by the correct path.

sudo dd bs=4M if=2019-07-10-raspbian-buster.img of=/dev/sdX conv=fsync

Step 3. Enable ssh

To activate ssh at the first start you just have to create a file ssh in the boot folder.

touch /run/media/your_username/boot/ssh

The path above might be different on your system.

Step 4. Add network info

Create a file in /run/media/your_username/boot/ called: wpa_supplicant.conf.

sudo nano /run/media/your_username/boot/wpa_supplicant.conf

Then paste the following into it (replace your country code, SSID and Password):

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev 
update_config=1 
ap_scan=1 
fast_reauth=1 
country=JP 
network=
{ ssid="network SSID" 
  psk="network password" 
  id_str="0" 
  priority=100 
}

Step 5. Find your Raspberry Pi in your network

One solution is to login to your router.

In case you do not have access to your router you can scan your ip range with nmap. Use the following command and search for your Raspberry Pi:

sudo nmap -sP 192.168.0.0/24

Adjust 192.168.0.0 to your ip range. In many cases it is 192.168.1.0 or 192.168.100.0

Step 6. Login to your Raspberry Pi

Use the following command to login:

ssh pi@192.168.0.150

Password by default: raspberry

 

ip route for wifi

In case you want to route the traffic of your linux machine of a specific IP through a specific interface ip routecommand should be used.

One example below asuming wlp2s0 is your wifi.

sudo ip route add 155.100.200.0/24 via 192.168.1.1 dev wlp2s0

This will lead all the traffic with target ip range 155.100.200.0/24 trough the interface of your wifi (assuming 192.168.1.1 is the wifi router).

I did not yet found a solution to route the traffic of a target “domain” through a specific interface. Happy for any input.