cjdns on Raspberry Pi

Documenting my attempt to set up my raspberry pi as a CJDNS node. I use a Macbook as my main workstation.

Materials #

Setup #

Installing Raspbian on the SDcard (credit to raspberrypi.org) #

  1. [Download a copy of raspbian](downloads.raspberrypi.org/raspbian_latest), this is the OS of choice for the raspberry pi.

  2. Unzip the file into your root directory.

  3. After the download is complete, open a new Terminal session. Run

df -h

and take note of the listed devices.

  1. Connect the SD card reader with the SD card inside. Be sure the SD card is formatted as FAT32.

  2. Run df -h again and look for the newly added device. Record the device name of the SD card’s partition, for example, mine was /dev/disk3s1.

  3. To overwrite the disk, you must unmount the partition:

sudo diskutil unmount /dev/disk3s1
  1. Determine what the raw device name is with this formula: add ‘r’ onto the front of the device name and remove the partition qualifier (ie. s1) from the end. For example if the name of the partition you saw in step 5 was ‘/dev/disk3s1’, then the name of the raw disk will be ‘/dev/rdisk3’. Be very careful with this step. Accidentally choosing the wrong device name will result in you overwriting that device… like your computer’s hard drive.

  2. Use the following command to write the disk image to your SD card. Read the above step carefully to be sure you use the correct rdisk number here:

sudo dd bs=1m if=2015-05-05-raspbian-wheezy.img of=/dev/rdisk3

If the above command reports an error (dd: bs: illegal numeric value), please change bs=1m to bs=1M.

If the above command reports an error dd: /dev/rdisk3: Permission denied then that is because the partition table of the SD card is being protected against being overwritten by MacOS. Erase the SD card’s partition table using this command:

sudo diskutil partitionDisk /dev/disk3 1 MBR "Free Space" "%noformat%" 100%

That command will also set the permissions on the device to allow writing. Now try the dd command again.

Note that dd will not feedback any information until there is an error or it is finished; information will be shown and the disk will re-mount when complete. However if you wish to view the progress you can use ‘ctrl-T’; this generates SIGINFO, the status argument of your tty, and will display information on the process.

After the dd command finishes, eject the card:

sudo diskutil eject /dev/rdisk3

(or: open Disk Utility and eject the SD card)

Getting into your Raspberry Pi #

I was doing this while on vacation and therefore didn’t have a spare keyboard or mouse lying around. As a result I had to hook up the Raspberry Pi to my router and ssh into it.

  1. Plug your raspberry pi into a power source. The red power LED should turn on immediately and the the green disk health LED should turn on and then start flickering as the bootcode executes Troubleshooting help here.

  2. Before connecting your raspberry pi to the network run

sudo nmap -sP 192.168.1.0/24

to list all the devices connected to your local network.

  1. Use an ethernet cable to connect your raspberry pi to your local router and run the command again. This time you should see the raspberry pi in the list of devices. To output only the IP of the raspberry pi, use the following command:
sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'

This takes advantage of your raspberry pi’s MAC address which always starts with B8:27:EB:. (Thank you to J. Costa on Stack Exchange)

  1. Now that you know your raspberry pi’s IP address, you can ssh into it from your Macbook with (using the IP you found above):
ssh pi@192.168.1.11

when prompted for a password for the default user, pi, use the default password, raspberry.

  1. Once you’re in, it’s a good idea to change the password off of the default. Do this with:
sudo passwd

You’ll be prompted for your old password and then the new one. Find more information on user management here.

Getting cjdns on your Raspberry Pi (a la cjdns readme) #

  1. Install dependencies with
sudo apt-get install nodejs git build-essential
  1. Download source with
git clone https://github.com/cjdelisle/cjdns.git cjdns
  1. Build cjdns
cd cjdns
./do

Setting up cjdns (a la cjdns readme) #

To print setup steps, you can always run ./cjdroute

  1. Ensure dependencies are met:
cat /dev/net/tun

cat: /dev/net/tun: File descriptor in bad state is good

cat: /dev/net/tun: No such file or directory is bad, if this is this is the case, run:

sudo mkdir /dev/net &&
sudo mknod /dev/net/tun c 10 200 &&
sudo chmod 0666 /dev/net/tun
  1. Create your cjdns configuration file
./cjdroute --genconf >> cjdroute.conf

Alternatively, create the file such that only the current user can read and write to it.

(umask 077 && ./cjdroute --genconf > cjdroute.conf)

Configuring Ad Hoc Wifi (a la Jordan Schaenzle) #

  1. Be safe- back up your network interfaces file before modifying it:
sudo cp /etc/network/interfaces /etc/network/interfaces_backup
  1. Now let’s edit your network interface:
sudo nano /etc/network/interfaces

Replace it’s contents with:

auto lo
iface lo inet loopback
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet static
  address 192.168.1.1
  netmask 255.255.255.0
  wireless-channel 1
  wireless-essid RPiAdHocNetwork
  wireless-mode ad-hoc

Installing the DHCP server #

  1. Install the dhcp server.
sudo apt-get install dhcp3-server
  1. Edit the dhcp daemon config:
sudo nano /etc/dhcp/dhcpd.conf

and add the following:

ddns-update-style interim;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.5 192.168.1.150;
}
 
21
Kudos
 
21
Kudos

Now read this

Backing Up a Raspberry Pi Image to a Compressed Format on a Mac

Quick steps for backing up and zipping your Raspberry Pi image onto a Mac OS. There is a TL;DR at the bottom if you’re just looking for the commands. Having spent considerable time setting up and installing new software on my raspberry... Continue →