HostAPd,WiFi热点的Linux实现,hostapd基本配置(转)
Tofloor
poster avatar
inspiron458
deepin
2012-11-11 22:27
Author
在UBUNTU系统或者其他类似linux系统上,使用hostapd,可以实现WIFI的无线接入热点(AP)
以便提供给其他需要无线接入联网的设备,如笔记本,手机实现无线上网功能。也即是无线路由的功能。
什么是hostapd
hostapd 是用户控件的守护进程用于无线接入点(AP)和授权服务器(authentication servers).
她实现了IEEE802.11的AP管理,IEEE802.1X/WPA/WPA2/EAP授权,RADIUS 客户端,EAP服务器和RADIUS 授权服务器,目前最新版本支持Linux系统(HOST AP,madwifi,mac80211-based驱动)和FreeBSD(net80211)。
hostapd设计为一个守护程序(进程),后台运行,进行一些相关控制授权的操作。属于一个开源项目。
相关链接:
http://w1.fi/hostapd/
http://linuxwireless.org/en/users/Documentation/hostapd
查看自己的无线网卡信息:
[cpp] view plaincopy
  1. wsn@wsn-laptop:~$ hwinfo --netcard  
Copy the Code
...  
28: PCI e00.0: 0282 WLAN controller  
  [Created at pci.318]  
  UDI: /org/freedesktop/Hal/devices/pci_14e4_4315  
  Unique ID: y9sn.reAAs+k0MA5  
  Parent ID: hoOk.F8Gordq8HH2  
  SysFS ID: /devices/pci0000:00/0000:00:1c.2/0000:0e:00.0  
  SysFS BusID: 0000:0e:00.0  
  Hardware Class: network  
  Model: "Dell Wireless 1397 WLAN Mini-Card"  
  Vendor: pci 0x14e4 "Broadcom"  
  Device: pci 0x4315 "BCM4312 802.11b/g"  
  SubVendor: pci 0x1028 "Dell"  
  SubDevice: pci 0x000c "Wireless 1397 WLAN Mini-Card"  
  Revision: 0x01  
  Driver: "b43-pci-bridge"  
  Driver Modules: "ssb"  
  Device File: wlan0  
  Features: WLAN  
  Memory Range: 0xf3000000-0xf3003fff (rw,non-prefetchable)  
  IRQ: 18 (557260 events)  
  HW Address: 00:22:5f:85:e7:a7  
  Link detected: yes  
  WLAN channels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14  
  WLAN frequencies: 2.412 2.417 2.422 2.427 2.432 2.437 2.442 2.447 2.452 2.457 2.462 2.467 2.472 2.484  
  WLAN encryption modes: WEP40 WEP104 TKIP CCMP  
  WLAN authentication modes: open sharedkey wpa-psk wpa-eap  
  Module Alias: "pci:v000014E4d00004315sv00001028sd0000000Cbc02sc80i00"  
  Driver Info #0:  
    Driver Status: ssb is active  
    Driver Activation Cmd: "modprobe ssb"  
  Config Status: cfg=new, avail=yes, need=no, active=unknown  
  Attached to: #16 (PCI bridge)  
Ubuntu下,如何获取hostapd?
1. 终端输入命
[cpp] view plaincopy
sudo apt-get install hostapd  
2. 最新版本可以通过git命令
[cpp] view plaincopy
sudo apt-get install git-core  
git clone git://w1.fi/srv/git/hostap.git  
3. 选择自己所需版本
[cpp] view plaincopy
http://w1.fi/hostapd/  
如何使用hostapd
将获取到的包解压,进入hostapd.
  1. [cpp] view plaincopy
  2. tar xzvf hostapd-x.y.z.tar.gz  
  3. cd hostapd-x.y.z/hostapd  
Copy the Code
复制一份默认的配置文件
[cpp] view plaincopy
cp defconfig .config  
编辑.config文件,找到
#CONFIG_DRIVER_NL80211=y
修改为
CONFIG——DIRVIERNL80211
最后编译:
sudo make
如果编译报错,原因多是libnl库出错,通过安装或升级libnl库即可
该库主要提供基于LINUX内核的netlink protocol相关APs函数。
这里下载获取,要求版本0.8以上
[cpp] view plaincopy
http://www.infradead.org/~tgr/libnl/  
如果还出错,那么需要安装libssl-dev:
该库提供ssl开发库
[cpp] view plaincopy
  1. sudo apt-get install libssl-dev  
Copy the Code
编译好后,得到hostapd执行文件
如何使用hostapd?
hostapd的功能,也就是笔记本通过有线网口介入,hostapd利用笔记本的无线网卡,实现无线路由。
编辑hostapd.conf文件
可以根据自己的网卡,参照这里
[cpp] view plaincopy
http://linuxwireless.org/en/users/Documentation/hostap  
一个简单的配置文件:
[cpp] view plaincopy
interface=wlan0  
bridge=br0  
driver=nl80211  
ssid=ssa  
hw_mode=g  
channel=11  
dtim_period=1  
rts_threshold=2347  
fragm_threshold=2346  
auth_algs=3  
wpa=1  
wpa_passphrase=12345678  
wpa_key_mgmt=WPA-PSK  
wpa_pairwise=TKIP CCMP  
rsn_pairwise=CCMP  
搭建网桥:
[cpp] view plaincopy
sudo apt-get install bridge-utils  
建立网桥:
[cpp] view plaincopy
sudo brctl adbr br0  
sudo ifconfig br0 192.168.2.236 netmask 255.255.255.0  
sudo route add default gw 192.168.2.254  
连接网桥两端:
[cpp] view plaincopy
  1. sudo brctl addif br0 eth0  
  2. sudo brctl addif br0 wlan0  
Copy the Code
最后:
[cpp] view plaincopy
  1. sudo ./hostapd hostapd.conf  
Copy the Code
如果一切顺利,将在终端看到一下类似字样:
[cpp] view plaincopy
  1. root@wsn-laptop:/home/wsn/Desktop/hostapd-0.7.3/hostapd# ./hostapd hostapd.conf   
  2. Configuration file: hostapd.conf  
  3. Using interface wlan0 with hwaddr 00:22:5f:85:e7:a7 and ssid 'ubuntu-502d'  
Copy the Code
android手机打开wifi并且设置静态ip
如ip:192.168.3.75
掩码: 255.255.255.0  
网关: 192.168.3.1

即可以连接到名为ubuntu-502的无线热点了
Reply Favorite View the author
All Replies
cxbii
deepin
2012-11-11 22:36
#1
制作wifi热点对吧?
Reply View the author
4***[email protected]
deepin
2012-11-11 23:43
#2
我直接用我的中兴V880通过USB线连接deepin,打开WIFI开关搜到我同学的路由连上,然后在设置>系统〉无线和网络>绑定与便携式热点>哪项打开,就可以无线上网啦,省得我无线网卡啦,在这断网的几天里都是这么干的,其他的安卓机应该也行吧,没试过!
Reply View the author
ldthereisaway
deepin
2012-11-14 02:58
#3
执行sudo brctl addif br0 wlan0时出现错误:
can't add wlan0 to bridge br0: Operation not supported
如何解决?
Reply View the author
pmirhs0
deepin
2012-11-14 05:14
#4
也可以这样
无线网络共享上网需要几个条件:
    1)建立一个Ad-hoc模式无线网络(Ad-hoc是专用的用于桥接之类的模式)
    2)设置ip转接允许
    3)设置iptables转送,用于把共享用户的ip请求转换成主机请求
    4)设置共享机器的路由,DNS
具体步骤:

1)
iwconfig wlan0 essid "***" key s:"***" mode ad-hoc
ifconfig wlan0 192.168.0.1 up
2)
sudo vi /etc/sysctl.conf
取消注释net.ipv4.ip_forward = 1
3)
sudo iptables -F
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
4)
使用静态地址:192.168.0.*
网关:192.168.0.1
dns:和你的电脑上的一样
Reply View the author
woxinfeixiang
deepin
2013-10-12 06:12
#5
执行sudo brctl addif br0 wlan0时出现错误:
can't add wlan0 to bridge br0: Operation not supported
如何解决?
sudo iw dev wlan0 set 4addr on
就可以了
Reply View the author