Wifi acces point on Beaglebone with DHCP

With the OS of Debian new opportunities have come. The Angstrom distribution did not meet our requirements because conman and ROS was not supported well yet, while Ubuntu didn’t have PWM, so that’s how Debian came into picture. The idea of connecting to the BeagleBone directly is better then connecting through some middle layer (like a router). To be this simple we need to config an acces point on the BeagleBone.
Step Zero: ifconfig
You need to config the network interfaces. Here you can see my case:

root@beaglebone:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback

# The primary network interface
auto eth1
iface eth1 inet dhcp

# WiFi
auto wlan1
iface wlan1 inet static
        address 192.168.4.1
        network 192.168.4.0
        netmask 255.255.255.0
        broadcast 192.168.4.255
#       hostapd /etc/hostapd/hostapd.conf

To restart the network use command:

/etc/init.d/networking restart

Step One: Hostapd
I used this package for setting the wifi accespoint. Install the package:

apt-get install hostapd

Next you have to edit the /etc/default/hostapd .

vi /etc/default/hostapd

set the

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Save and close. Create the file:

touch /etc/hostapd/hostapd.conf

Then edit the file like that:

vi /etc/hostapd/hostapd.conf

Add these lines:

### Wireless network name ###
interface=wlan1
#
### Set your bridge name ###
#bridge=br0

#driver
driver=nl80211

country_code=HU

ssid=beaglebone

channel=7

hw_mode=g

# # Static WPA2 key configuration
# #1=wpa1, 2=wpa2, 3=both
wpa=2

wpa_passphrase=yourpassword

## Key management algorithms ##
wpa_key_mgmt=WPA-PSK
#
## Set cipher suites (encryption algorithms) ##
## TKIP = Temporal Key Integrity Protocol
## CCMP = AES in Counter mode with CBC-MAC
wpa_pairwise=TKIP
#rsn_pairwise=CCMP
#
## Shared Key Authentication ##
auth_algs=1
## Accept all MAC address ###
macaddr_acl=0
#enables/disables broadcasting the ssid
ignore_broadcast_ssid=0
# Needed for Windows clients
eapol_key_index_workaround=0

To debug that you have wrote everything good use:

hostapd /etc/hostapd/hostapd.conf

Note: if you receive some errors like this, delete those empty lines

Configuration file: /etc/hostapd/hostapd.conf
Line 3: invalid line ' '
Line 24: invalid line ' '
Line 30: invalid line ' '
Line 34: invalid line ' '
4 errors found in configuration file '/etc/hostapd/hostapd.conf'

Now you have to restart it to get it work.

/etc/init.d/hostapd restart

At this point you may see the Beaglebone along the connectable wifi network. You can connect to it, but you have to set your IP to be in the same network. Or you can use DHCP that will be explained below.

References:
http://users.utu.fi/sjsepp/hostapd/hostap.html
http://www.cyberciti.biz/faq/debian-ubuntu-linux-setting-wireless-access-point/#s1
http://www.peregrin.hu/wifi-accesspoint-to-debian

Step Two: DHCP server
This is optional, you can connect to the Beaglebone, but you won’t get an Ip. Either you config staticly your ip to be in same network as your Beaglebone or you can use dhcp. Install it by:

apt-get update
apt-get install isc-dhcp-server

Edit the config file:

vi /etc/dhcp/dhcpd.conf

I only added this to it:

subnet 192.168.4.0 netmask 255.255.255.0 {
  range 192.168.4.2 192.168.4.10;
}

And didn’t touch the other parts of the file. You can see many hints inside the dhcpd.conf how to config it better. Then restart:

/etc/init.d/isc-dhcp-server restart

If everything went good, now you can connect to the Beaglebone via wifi. The beaglebone’s IP will be 192.168.4.1 .

References:

http://wiki.debian.org/DHCP_Server
http://www.cyberciti.biz/faq/debian-ubuntu-linux-setting-wireless-access-point/
http://www.debianhelp.co.uk/dhcp.htm

Step Two alternative: Dnsmasq

As STrRedWolf mentioned in his comment, you can use an alternative dhcp and dns server for small networks the Dnsmasq.

apt-get update
apt-get install dnsmasq

Edit the config file:

vi /etc/dnsmasq.conf

I added that two lines:

interface=wlan1
dhcp-range=wlan1,192.168.4.2,192.168.4.10,4h

Restart the dnsmasq

/etc/init.d/dnsmasq restart

In that way the beaglebone’s IP will be 192.168.4.1 .
For debugging you can see that the service is running:

service --status-all

[ + ]  dnsmasq

References:
http://www.thekelleys.org.uk/dnsmasq/doc.html
http://wiki.debian.org/HowTo/dnsmasq#Basic_DHCP_Setup

Advertisements

14 thoughts on “Wifi acces point on Beaglebone with DHCP

  1. Why not use dnsmasq instead of the full DHCP server? Not only do you get an easier DHCP server to configure, you also get a DNS server as well.

    1. dnsmask will not give you a DHCP server if you are not connected to the network. There are applications for the Beaglebone Black as a router that include controlling remote devices through a tablet while not necessarily connected to the Internet. A standalone DHCP server is not that heavy and will always work.

  2. Hi,
    I have been trying to do just that with the Angstrom distro with no success. I have not gotten a single Wifi dongle to work with it (tried 3).
    Could you share the Debian version you used (and where I could get it from) and the type of WiFi dongle you used?
    Also, did you have to install any drivers for the Wifi dongle that did not come with the distro?
    Thanks in advance!

  3. Hi there,

    I would like to set up my beaglebone black, so that it starts up as an access point. I would then use my phone, to connect to the access point. I would have a simple web page that allows the user to configure the beaglebone black to connect to home router. After a reboot the BBB is connected the home network.

    I guess what I am looking for is two discrete configurations. My current configuration allows me to connect to my home router.

    1. Hi Andrew,

      Yes, they are two separate configuration. As far as I know, you can only use one WIFI port for one purpose at the time, it is either AP or you set that it connects to another AP. What I explained in this post is how to connect to BBB and use it as an AP. For the other configuration(to make the BBB connect to the router) you could check this if you haven’t already:
      https://askubuntu.com/questions/138472/how-do-i-connect-to-a-wpa-wifi-network-using-the-command-line

      Your project sounds fun, when you are finished with it please send me a link to it! 🙂

  4. Both isc-dhcp-server and dnsmasq failed to start for me. (dnsmasq worked the first time but didn’t work later). Turns out udhcpd was already bound to port 67 so that it can hand out addresses on interface usb0.

    Furthermore, udhcpd has a bug where it ignores the interface option and binds to all addresses. So I don’t think it’s actually possible to have udhcpd serve for both USB and WLAN.

    But if I change the /opt/scripts/boot/autoconfigure_usb0.sh to make the /etc/udhcpd.conf file like this, it works on the wifi side:

    # Managed by /opt/scripts/boot/autoconfigure_usb0.sh – Do not modify unless you know what you are doing!
    start 192.168.4.2
    end 192.168.4.10
    interface wlan2
    max_leases 9
    option subnet 255.255.255.0

    I think a better answer is to remove udhcpd and use one of the other two dhcp servers for both usb and wifi interfaces.

  5. Aloha,

    Thanks for this organized tutorial. I just started and have run into a few issues / questions because I’m admittedly a super rookie. I also know it’s been awhile since someone has posted on here so I’ll keep my fingers crossed:
    1) For step zero (ifconfig) … should we make our file match yours? I’m working on a 2014 Mac and it doesn’t have an ethernet port (not sure if that matters or not)
    2) I started on step one and I’m getting errors like this:
    Configuration file: /etc/hostapd/hostapd.conf
    nl80211: ‘nl80211’ generic netlink not found
    Failed to initialize driver ‘nl80211’
    Segmentation fault
    ….. has anyone else experienced this? I’ve read in some places that it’s wifi hardware issues and in some places that it’s a debian / linux issue.

    Any help would be greatly appreciated. Thank you so much!
    -Jessie

    1. Hi Jessica,

      This tutorial was for BeagleBone, so you don’t have to copy exactly the file content in step zero. Only part is neccessary is the wlan part and feel free to modify it according to your needs.
      For the second question, if I understand you correctly you would like to setup your 2014 Mac as wifi hotspot machine. In that case I would recommend to check your issue on Debian forums. Since I only have done the tutorial for Beaglebone, and so far I haven’t hit those issues. For me your issue sounds like your system have some problems with your wifi drivers. If your wifi works normally it is high chance that is the case. I hope this helps you.

      Br,
      Arpad

Leave a Reply to STrRedWolf Cancel reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s