When you take your headless Pi outside into the real world, chances are you'll want to communicate with it from a netbook or laptop from time to time. Since you won't be bringing your router or access point along, we need a way to make a direct point-to-point connection between your Pi and the other computer.
As there won't be a DHCP server to hand out IP addresses to our two network devices, what we want to do is assign static IP addresses on both Pi and laptop. We can pick any two addresses from the private IPv4 address space we saw in the Mapping out your network with Nmap section in Chapter 4, Wi-Fi Pranks – Exploring your Network. In the following example, we'll use 192.168.10.1
for the Pi and 192.168.10.2
for the laptop.
pi@raspberrypi ~ $ sudo nano /etc/network/interfaces
iface eth0 inet dhcp
and put a #
character in front of the line to temporarily disable requesting an IP address from a DHCP server. Then add the following three lines beneath:iface eth0 inet static address 192.168.10.1 netmask 255.255.255.0
y
when prompted to save the modified buffer, then press the Enter key to confirm the filename to write to. You can now reboot the Pi and shift the focus to your laptop.If your direct wired connection seems unstable or outright refuses to work, your laptop might require a special crossover cable made specifically for direct connections between two computers. You can read more about it at http://wikipedia.org/wiki/Ethernet_crossover_cable.
Let's set up the other end of the direct wired connection:
adapter
using the search box.192.168.10.2
for the IP address and 255.255.255.0
for the Subnet mask, then click on the OK button.Let's set up the other end of the direct wired connection:
192.168.10.2
for IP Address and 255.255.255.0
for Subnet Mask, then click on the Apply button.If your Linux distribution is based on Debian, you should be able to assign static addressing using the same method as we used for the Raspberry Pi. However, you can try the following command sequence to assign a static IP address to a running system:
$ sudo ip addr add 192.168.10.2/24 dev eth0 $ sudo ip route del default
Since there won't be a DHCP server to hand out IP addresses to our two network devices, what we want to do is assign static IP addresses on both Pi and laptop. We can pick any two addresses from the private IPv4 address space we saw in the Mapping out your network with Nmap section in Chapter 4, Wi-Fi Pranks – Exploring your Network. In the following example, we'll use 192.168.10.1
for the Pi and 192.168.10.2
for the laptop:
pi@raspberrypi ~ $ sudo nano /etc/network/interfaces
iface default inet dhcp
and put a #
character in front of the line to temporarily disable requesting an IP address from a DHCP server. Then add the following three lines beneath:iface default inet static address 192.168.10.1 netmask 255.255.255.0
y
when prompted to save the modified buffer, then press the Enter key to confirm the filename to write to.pi@raspberrypi ~ $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
#
character in front of every line of the block. Then add an entry for your new ad hoc network to the end of the file, as follows:ap_scan=2 network={ ssid="MyHoc" mode=1 proto=WPA key_mgmt=WPA-NONE pairwise=NONE group=CCMP psk="CaptainHoc!" }
The extra ap_scan
directive is necessary for proper ad hoc support. Change ssid
to the name you'd like for your ad hoc network and change psk
to a passphrase that connecting computers would have to supply.
nano
, then reboot your Pi.Let's set up the other end of the ad hoc Wi-Fi connection:
wireless
using the search box.192.168.10.2
for the IP address and 255.255.255.0
for the Subnet mask, then click on the OK button.Let's set up the other end of the ad hoc Wi-Fi connection:
192.168.10.2
for the IP Address and 255.255.255.0
for the Subnet Mask, then click the OK button.3.138.37.191