ubuntu11.10安装hostapd

1、从apt-get install hostapd安装之后,用hostapd会提示以下错误:

root@skyi:/media/Loondisk/hostapd/hostapd-git/hostap/hostapd# hostapd -d /etc/hostapd/hostapd.conf 
Configuration file: /etc/hostapd/hostapd.conf
nl80211: Register Action command failed: ret=-19 (No such device)
nl80211: Register Action match - hexdump(len=1): 06
nl80211: Failed to register Action frame processing - ignore for now
nl80211: Add own interface ifindex 0
Could not read interface wlan0  flags: No such device
nl80211 driver initialization failed.
ELOOP: remaining socket: sock=4 eloop_data=0x933ca68 user_data=0x933d008 handler=0x807c670
ELOOP: remaining socket: sock=6 eloop_data=0x933e828 user_data=(nil) handler=0x8086770
root@skyi:/media/Loondisk/hostapd/hostapd-git/hostap/hostapd# 

可能是因为它没有支持nl80211的驱动,所以要从hostapd的官网下载源码包安装。

2、从官网上下载的hostapd-1.0版本编译的时候会出错,从git clone git://w1.fi/srv/git/hostap.git这里下载编译才没有错误。

(../src/drivers/driver_nl80211.c:95:9: error: too few arguments to function ‘genl_ctrl_alloc_cache’)

编译之前先在hostapd目录下执行cp defconfig .config,而配置文件默认只支持nl80211的驱动(CONFIG_DRIVER_NL80211=y)。

make

make install

3、新建/etc/hostapd/hostapd.conf 

interface=wlan0
#interface=wlan0
driver=nl80211
#driver=madwifi
ssid=YOUR_SSID
channel=9
hw_mode=g
macaddr_acl=0
ignore_broadcast_ssid=0
auth_algs=1
wpa=3
wpa_passphrase=YOUR_PASSPHRASE
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

最后执行:hostapd -d /etc/hostapd/hostapd.conf 

4、安装dhcpd

apt-get install dhcp3-server

echo "1" > /proc/sys/net/ipv4/ip_forward
hostapd -B /etc/hostapd/hostapd.conf

/etc/dhcp/dhcpd.conf:
subnet 192.168.0.0 netmask 255.255.255.0
{
 range 192.168.0.2 192.168.0.10;
 option routers 192.168.0.1;
}

wlan0配置地址:
ifconfig wlan0 192.168.0.1 netmask 255.255.255.0
开启dhcp:
dhcpd wlan0 -pf /var/run/dhcp-server/dhcpd.pid

现在无线网卡就可以当成ap了。


5、把无线网卡的ap继续扩展为连接到外网

网上有很多资料,一般有2种方法:一种是bridge(桥接),另一种是nat方式,这里只介绍nat的方式。

经过前面4个步骤,无线网卡已经可以自动分配IP,现在只需要把无线网卡的数据都经过eth0(有线网络)发到外网去,这就需要IP转发了。

# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

还需要修改/etc/dhcp/dhcpd.conf,添加dns:
subnet 192.168.0.0 netmask 255.255.255.0
{
 range 192.168.0.2 192.168.0.10;
 option domain-name-servers 221.5.88.88;
 option routers 192.168.0.1;
}


6、嵌入式开发板上设置内核支持iptabel的设置如下:

内核需要对iptables的支持并加上nat功能

Networking support --->

              Networking options --->

                   Network packet filtering framework (Netfilter)

│ │    --- Network packet filtering framework (Netfilter)               │ │ 

  │ │    [*]   Network packet filtering debugging                         │ │ 

  │ │    [*]   Advanced netfilter configuration                           │ │ 

  │ │          Core Netfilter Configuration  --->                         │ │ 

  │ │    < >   IP virtual server support  --->                            │ │ 

  │ │          IP: Netfilter Configuration  --->

 

Core Netfilter Configuration里面的配置如下:

<*> Netfilter connection tracking support

-*- Netfilter Xtables support (required for ip_tables)

IP: Netfilter Configuration里面的配置如下:

[*]   proc/sysctl compatibility with old connection tracking

<*> IP tables support (required for filtering/masq/NAT)

   <*>   Packet filtering           

   <*>     REJECT target support      

   < >   LOG target support  

   < >   ULOG target support     

  <*>   Full NAT      

  <*>     MASQUERADE target support 

  <*>     NETMAP target support    

  <*>     REDIRECT target support

  <*>     Basic SNMP-ALG support


你可能感兴趣的:(linux,hostapd)