Hostapd on CentOS 6

Posted by jason on Feb. 3, 2012, 6:31 a.m.
Tags: centos config hostapd linux sysadmin

Here's how I got hostapd working on my CentOS 6 box. This article (if you could call it that) is just a running commentary. I wrote it while figuring things out, so all the silly issues I encountered are included here. Yes, I could write this properly so that none of the errors are encountered, but my hope is that others had similar issues and that this article might help.

Edit: First thing you should do is make sure that you have the "bridge-utils" package installed. Thanks to Matt for pointing this out.

[root@jason ~]# yum install bridge-utils

To start, here's the wireless card I have:

[root@jason ~]# lspci
04:00.0 Network controller: Atheros Communications Inc. AR922X Wireless Network Adapter (rev 01)

The ATRpms repo that I use only has hostapd version 0.5, which doesn't include the driver I need--I get an error like this when trying to install and run it: "invalid/unknown driver 'nl80211'".

My workaround: Get and compile the latest stable hostapd version.

[root@jason ~]# cd /usr/local/src
[root@jason src]# wget -c http://w1.fi/releases/hostapd-0.7.3.tar.gz
[root@jason src]# tar xzvf hostapd-0.7.3.tar.gz
[root@jason src]# cd hostapd-0.7.3/hostapd

As always, have a quick glance at the README / INSTALL files, if any.

Now, copy defconfig to .config (yeah, I know, no ./configure for this one). Make sure to uncomment the following line:

CONFIG_DRIVER_NL80211=y

I tried to run make and got an error about the cc command not existing, which means I haven't installed development tools on this box yet. So:

[root@jason hostapd]# yum groupinstall "Development Tools"
...
[root@jason hostapd]# make

Bah! Got a bunch of nl80211 errors...so...

[root@jason hostapd]# yum install libnl-devel
...
[root@jason hostapd]# make

Sigh, got this...

make: *** [../src/crypto/tls_openssl.o] Error 1

So...

[root@jason hostapd]# yum install openssl-devel
...
[root@jason hostapd]# make

Wait--it worked!? It worked! (Anyone who has compiled PHP from source knows that the -devel package errors above can go on for ages.)

[root@jason hostapd]# make install

Now it's time to test. First, create a hostapd.conf file. I put everything in /etc/hostapd/.

[root@jason hostapd]# cd /etc
[root@jason etc]# mkdir hostapd
[root@jason etc]# cd hostapd
[root@jason hostapd]# vi hostapd.conf

Here's what my hostapd.conf file looks like. Notice I haven't enabled wireless n: it gave me an error ("unknown configuration item 'ieee80211n'") and it's more trouble than it's worth since my devices never really get wireless n speeds anyway. My setup uses wireless g with WPA2 and only lets devices connect if their MAC addresses are in the /etc/hostapd/hostapd.accept file. For more information, read the config file that comes with hostapd or check out the software access point page on the Arch Wiki.

interface=wlan0
bridge=br0
driver=nl80211
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
dump_file=/tmp/hostapd.dump
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=wifiname
hw_mode=g
channel=1
beacon_int=100
dtim_period=2
max_num_sta=255
rts_threshold=2347
fragm_threshold=2346
macaddr_acl=1
accept_mac_file=/etc/hostapd/hostapd.accept
deny_mac_file=/etc/hostapd/hostapd.deny
auth_algs=1
ignore_broadcast_ssid=0
wmm_enabled=1
wmm_ac_bk_cwmin=4
wmm_ac_bk_cwmax=10
wmm_ac_bk_aifs=7
wmm_ac_bk_txop_limit=0
wmm_ac_bk_acm=0
wmm_ac_be_aifs=3
wmm_ac_be_cwmin=4
wmm_ac_be_cwmax=10
wmm_ac_be_txop_limit=0
wmm_ac_be_acm=0
wmm_ac_vi_aifs=2
wmm_ac_vi_cwmin=3
wmm_ac_vi_cwmax=4
wmm_ac_vi_txop_limit=94
wmm_ac_vi_acm=0
wmm_ac_vo_aifs=2
wmm_ac_vo_cwmin=2
wmm_ac_vo_cwmax=3
wmm_ac_vo_txop_limit=47
wmm_ac_vo_acm=0
eapol_key_index_workaround=0
eap_server=0
wpa=2
wpa_passphrase=wifipassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
wpa_group_rekey=600
wpa_gmk_rekey=86400

Now, test:

[root@jason hostapd]# /usr/local/bin/hostapd /etc/hostapd/hostapd.conf 
Configuration file: hostapd.conf
MAC list file '/etc/hostapd/hostapd.deny' not found.
Line 183: Failed to read deny_mac_file '/etc/hostapd/hostapd.deny'
1 error found in configuration file 'hostapd.conf'

Oops!

touch /etc/hostapd/hostapd.deny

I just remembered I still need to configure my the network bridge. Here's what things look like:

[root@jason ~]# cd /etc/sysconfig/network-scripts/
[root@jason network-scripts]# cat ifcfg-eth0 
DEVICE="eth0"
BOOTPROTO="static"
HWADDR="AA:BB:CC:DD:EE:FF"
NM_CONTROLLED="yes"
ONBOOT="yes"
BRIDGE=br0

[root@jason network-scripts]# cat ifcfg-br0 
DEVICE="br0"
BOOTPROTO="dhcp"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Bridge"

A simple network restart didn't work for me, but a reboot did.

Hostapd works for me now, but there's no init script for it. I just used this one and it worked beautifully--I just needed to change the path to the hostapd.conf file. Put it in /etc/init.d, chmod / chown it so it looks like the other files ("when in rome!"), and set it up to run at boot.

[root@jason ~]# chkconfig hostapd on

That's it. Feel free to comment and let me know if I've missed anything or committed some sin or other.


6 comments

atlas #1

Thanks for this article (it is), Jason.

I tried to do the same, but in my case it's wlan0 instead of eth0. And when "BRIDGE=br0" is added to ifcfg-wlan0, wifi doesn't work anymore (NetworkManager's wireless networks list is empty).

Do you know, if it works with a wifi connection at all?

jason #2

@atlas:

Does that mean you're trying to use a single wireless card to both listen for connections and to connect to your router / internet? I'm pretty sure wireless cards can only perform one of those tasks at a time.

atlas #3

Yes, exactly.

However, it works this way with "Wireless Hosted Network" in Windows 7, where the wifi adapter is virtualized.

I was looking for the same thing in CentOS.

Matt #4

I'm getting this error when I restart the network. "Bringing up interface br0: Bridge support not available: brctl not found"

FYI, I am on Centos 6.2, 2.6.32-220.17.1.el6.i686 (ath9k)

Matt #5

yum install bridge-utils fixed the issue.

jason #6

Thanks Matt! I added a line to mention that the bridge-utils package is needed.