How-to: Raspberry Pi Hosting an AdHoc Network

w/ the Inexpensive Edimax EW-7811Un Wifi Dongle

Pi-Adhoc

Materials used: 

Step 1: Terminal access

Plug the Raspberry Pi into your existing network through a wired connection. Use Adafruit’s Pi Finder to locate and access the terminal of your Pi.

Step 2: Install required packages

  • hostapd is a wireless access point manager
  • udhcpd is a dhcp server that will assign IPs for connected clients
sudo apt-get install  hostapd udhcpd

The version of hostapd that we just installed does not support the Edimax dongle’s hardware. We need to replace some files, to make it compatible.

wget http://www.daveconroy.com/wp3/wp-content/uploads/2013/07/hostapd.zip
unzip hostapd.zip 
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.bak
sudo mv hostapd /usr/sbin/hostapd.edimax 
sudo ln -sf /usr/sbin/hostapd.edimax /usr/sbin/hostapd 
sudo chown root.root /usr/sbin/hostapd 
sudo chmod 755 /usr/sbin/hostapd

Step 3: Configure hostapd

sudo nano /etc/hostapd/hostapd.conf

Edit the file so that it contains the following text:

interface=wlan0
driver=rtl871xdrv
ssid=Raspi_wifi
hw_mode=g
channel=11
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=somepassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Hit Control-X to exit. You will be prompted to save changes.

Step 4: Configure udhcpd

sudo nano /etc/udhcpd.conf

Edit the file so that it contains the following text:

start 192.168.0.2 # This is the range of IPs that the hotspot will give to client devices.
end 192.168.0.20
interface wlan0 # The device udhcp listens on.
remaining yes
opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use.
opt subnet 255.255.255.0
opt router 192.168.0.1 # The Pi’s IP address on wlan0 which we will set up shortly.
opt lease 864000 # 10 day DHCP lease time in seconds

Hit Control-X to exit. You will be prompted to save changes.

sudo nano /etc/default/udhcpd

Find the following line:
DHCPD_ENABLED=”no”And prepend it with a pound symbol, like this:
#DHCPD_ENABLED=”no”

Hit Control-X to exit. You will be prompted to save changes.

References: