怎样在Ubuntu中开启Soft AP(虚拟AP)功能

包含网卡/无线网的网络问题和ADSL/校园网/宽带拨号支持及代理/共享等网络使用问题
jintao24828
帖子: 4
注册时间: 2011-05-07 0:04

怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#1

帖子 jintao24828 » 2011-05-07 0:21

2011.5.6 2:45am

计算机环境:
SAMSUNG N148 PLUS
WLAN Chipset Atheros 8295 (对于Linux Kernel有一定的要求)
Ubuntu 11.04 Linux Kernel 2.6.38.9
hostapd 0.8.0

目标
使能Soft AP,在任何只能通过固定以太网口可以上网的地方,使Android/iphone手机通过WiFi上网或者共享信息(部分手机不支持ad-hoc)

背景知识
1.Soft AP/虚拟AP http://www.yesky.com/24/1755024_1.shtml
2.Linux基本目录、操作、sudo、ifconfig Linux入门到精通 http://os.yesky.com/linuxstudy/
3.hostapd需要和驱动协作,以前的驱动是hostap、prism、madwifi三种特别的内核驱动,现在建议使用nl80211用户空间接口驱动,非常通用和普及 http://linuxwireless.org/en/users/Documentation/hostapd

准备
从网上搜集了大量资料,但百度中搜到的往往要么太旧,要么就是抄袭或者臆想,当然也可能是硬件不一致导致无法使用,软件版本更新原有方案过期
从Google和Ubuntu网站,以及Linux Kernel网站获得很多宝贵的第一手资料:
1.Linxu Wireless,有详细的如何在Linux上开启Soft AP的描述 http://wireless.kernel.org/en/users/Doc ... ct=RTFM-AP
2.Hostapd代码和网站 http://hostap.epitest.fi/hostapd/
3.完整的无线路由器改造 HOW TO : Wifi Access Point with hostap + hostapd + freeradius + mysql http://ubuntuforums.org/showthread.php?t=151781
4.MadWiFi Project,一种Atheros的WiFi驱动 http://madwifi-project.org/
5.Network bridge in ubuntu 手工建立桥接(WLAN到Ethernet走二层交换)http://forums.techarena.in/operating-sy ... 272775.htm
6.如何自动建立桥接HowTos/Bridging with Ubuntu http://wiki.openzaurus.org/HowTos/Bridging_with_Ubuntu
7.如何识别网卡是否支持Soft AP
8.Atheros芯片支持情况 Atheros网站
头像
monk
帖子: 19507
注册时间: 2010-01-28 10:45

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#2

帖子 monk » 2011-05-07 0:25

看看这个帖子对你有么有帮助
viewtopic.php?f=15&t=277475

*********宁静致远*********
如果我说的有什么不对,请看签名第一行
jintao24828
帖子: 4
注册时间: 2011-05-07 0:04

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#3

帖子 jintao24828 » 2011-05-07 0:28

计划
1.查看芯片是否支持Soft AP
2.使用或者编译hostapd
3.配置hostapd-minimal.conf(最简选项),使能Soft AP,手机可以WiFi接入
4.打开WLAN和Ethernet的桥接,使得手机可以从网络中获取地址,正常上网
5.提升步骤3中的WLAN的安全性,尝试各种b/g/n和业务

实施:
1.查看Atheros芯片8295是否支持Soft AP,注意,可以看到有AP字样,表明支持
$ sudo apt-get install iw

$ iw list
Wiphy phy0
Band 1:
Capabilities: 0x11ce
HT20/HT40
SM Power Save disabled
RX HT40 SGI
TX STBC
RX STBC 1-stream
Max AMSDU length: 7935 bytes
DSSS/CCK HT40
Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
Minimum RX AMPDU time spacing: 8 usec (0x06)
HT TX/RX MCS rate indexes supported: 0-7
Frequencies:
* 2412 MHz [1] (17.0 dBm)
* 2417 MHz [2] (17.0 dBm)
* 2422 MHz [3] (9.0 dBm)
* 2427 MHz [4] (13.0 dBm)
* 2432 MHz [5] (13.0 dBm)
* 2437 MHz [6] (13.0 dBm)
* 2442 MHz [7] (13.0 dBm)
* 2447 MHz [8] (13.0 dBm)
* 2452 MHz [9] (9.0 dBm)
* 2457 MHz [10] (14.0 dBm)
* 2462 MHz [11] (14.0 dBm)
* 2467 MHz [12] (17.0 dBm) (passive scanning)
* 2472 MHz [13] (17.0 dBm) (passive scanning)
* 2484 MHz [14] (disabled)
Bitrates (non-HT):
* 1.0 Mbps
* 2.0 Mbps (short preamble supported)
* 5.5 Mbps (short preamble supported)
* 11.0 Mbps (short preamble supported)
* 6.0 Mbps
* 9.0 Mbps
* 12.0 Mbps
* 18.0 Mbps
* 24.0 Mbps
* 36.0 Mbps
* 48.0 Mbps
* 54.0 Mbps
max # scan SSIDs: 4
Supported interface modes:
* IBSS
* managed
* AP <---------------硬件芯片支持AP功能
* AP/VLAN
* WDS
* monitor
* mesh point
* Unknown mode (8)
* Unknown mode (9)
Supported commands:
* new_interface
* set_interface
* new_key
* new_beacon
* new_station
* new_mpath
* set_mesh_params
* set_bss
* authenticate
* associate
* deauthenticate
* disassociate
* join_ibss
* Unknown command (68)
* Unknown command (55)
* Unknown command (57)
* Unknown command (59)
* Unknown command (67)
* set_wiphy_netns
* Unknown command (65)
* Unknown command (66)
* connect
* disconnect


2.使用或者编译hostapd
$ sudo apt-get install hostapd

Ubuntu apt-get的版本比较老0.6,我按照资料1尝试失败,自行编译0.8.0版本

找一个目录,我找的是~
$ git clone git://w1.fi/srv/git/hostap.git
$ cd hostap/hostapd

$ cp defconfig .config
$ vi .config
配置#CONFIG_DRIVER_NL80211=y,去掉最前面的#

$ sudo apt-get install libnl1 libnl-dev libnl-doc
$ sudo apt-get install libssl-dev
$ make
生成hostapd hostapd_cli两个可执行文件

3.配置hostapd-minimal.conf(最简选项),使能Soft AP,手机可以WiFi接入
hostapd-minimal.conf内容如下:
interface=wlan0
bridge=br0
driver=nl80211

ssid=myTravel
hw_mode=g
channel=1

然后启动hostapd,手机就搜到可用AP SSID为myTravel,直接连接即可
# ./hostapd ./hostapd-minimal.conf
(注意是#,需要su后操作,或者$ sudo ./hostapd ./hostapd-minimal.conf)

4.打开WLAN和Ethernet的桥接,使得手机可以从网络中获取地址,正常上网

按ctrl-C中断hostapd

$ sudo apt-get install bridge-utils

关闭eth0
$ sudo ifdown eth0

建立br0接口
$ sudo brctl addbr br0

加入第一个成员端口
$ sudo brctl addif br0 eth0

再次在另外一个term中启动hostapd,注意,在conf文件中,已经加入bridge=br0,启动后wlan0自动加入br0
# ./hostapd ./hostapd-minimal.conf
(注意是#,需要su后操作,或者$ sudo ./hostapd ./hostapd-minimal.conf)

查看bridge中是否有eth0和wlan0
$ sudo brctl show
bridge name bridge id STP enabled interfaces
br0 8000.002454cac884 no eth0
wlan0
启动br0
$ sudo ifconfig br0 up
$ sudo ifconfig eth0 up

再次用手机搜索WiFi,可以连接,可以获取本地地址,上网,成功!

收尾
按ctrl-C中断hostapd
$ sudo ifconfig eth0 down
$ sudo ifconfig br0 down
$ sudo brctl delif br0 eth0
$ sudo brctl delbr br0
$ sudo ifconfig eth0 up

计算机上网络恢复正常,如果开启Soft AP前,已经有网络应用程序,可能此时网络并不正常,点击上部工具栏网络的那个图标,再点击“Auto eth0”即可恢复

5.提升步骤3中的WLAN的安全性,尝试各种b/g/n和业务
详见http://wireless.kernel.org/en/users/Documentation/hostapd?action=show&redirect=RTFM-AP的配置,以及hostapd 中自带的hostapd.conf,有详尽的说明

一般建议开启WPA2
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_passphrase=12345678

其他各种认证、快速切换、WDS/MESH等等都可以慢慢玩了

还有,如果长期当作AP使用,br0和eth0的绑定关系可以配置到/etc/network/interfaces
auto lo
iface lo inet loopback

# Configure br0 using ifupdown with dhcp and add eth0 to the bridge
auto br0
iface br0 inet dhcp
bridge_ports eth0

其他当作路由器/NAT(Firestarter),开启RADIUS认证什么的,以后再玩了。
一旦固定以后,要么利用Linux的机制自动化,或者写成脚本一条命令搞定!
jintao24828
帖子: 4
注册时间: 2011-05-07 0:04

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#4

帖子 jintao24828 » 2011-05-07 0:36

6.脚本
启动脚本
softapup.sh

#/bin/bash!
sudo ifdown eth0
sudo brctl addbr br0
sudo brctl addif br0 eth0
sudo hostapd ./hostapd-my.conf -B #注意hostapd程序、conf文件的路径
sudo brctl show
sudo ifconfig br0 up
sudo ifconfig eth0 up


关闭脚本
softapdown.sh

#/bin/bash!
sudo killall hostapd
sudo ifconfig eth0 down
sudo ifconfig br0 down
sudo brctl delif br0 eth0
sudo brctl show
sudo brctl delbr br0
sudo ifconfig eth0 up

典型hostapd-my.conf文件
interface=wlan0
bridge=br0
driver=nl80211

ssid=mySoftAP
hw_mode=g
channel=1

wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_passphrase=iloveyou
tamsun
帖子: 451
注册时间: 2006-07-07 21:07

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#5

帖子 tamsun » 2011-05-07 9:32

这种文章要顶
头像
young40
帖子: 154
注册时间: 2006-10-27 18:15

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#6

帖子 young40 » 2011-05-20 15:16

代码: 全选

young40@ubuntu:~/cpp/hostap/hostap/hostapd$ sudo ./hostapd ./ap.conf
Configuration file: ./ap.conf
Could not set interface wlan0 flags: Input/output error
nl80211 driver initialization failed.
这个是怎么回事???谢谢
Thinkpad X200 7457A78
Intel Core2 Duo(Penryn) P8600(2.4GHz)
3GB RAM
头像
young40
帖子: 154
注册时间: 2006-10-27 18:15

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#7

帖子 young40 » 2011-05-20 23:24

代码: 全选

young40@ubuntu:~$ iw list
Wiphy phy0
	Band 1:
		Capabilities: 0x872
			HT20/HT40
			Static SM Power Save
			RX Greenfield
			RX HT20 SGI
			RX HT40 SGI
			No RX STBC
			Max AMSDU length: 3839 bytes
			No DSSS/CCK HT40
		Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
		Minimum RX AMPDU time spacing: 4 usec (0x05)
		HT RX MCS rate indexes supported: 0-15, 32
		TX unequal modulation not supported
		HT TX Max spatial streams: 1
		HT TX MCS rate indexes supported may differ
		Frequencies:
			* 2412 MHz [1] (15.0 dBm)
			* 2417 MHz [2] (15.0 dBm)
			* 2422 MHz [3] (15.0 dBm)
			* 2427 MHz [4] (15.0 dBm)
			* 2432 MHz [5] (15.0 dBm)
			* 2437 MHz [6] (15.0 dBm)
			* 2442 MHz [7] (15.0 dBm)
			* 2447 MHz [8] (15.0 dBm)
			* 2452 MHz [9] (15.0 dBm)
			* 2457 MHz [10] (15.0 dBm)
			* 2462 MHz [11] (15.0 dBm)
			* 2467 MHz [12] (15.0 dBm) (passive scanning, no IBSS)
			* 2472 MHz [13] (15.0 dBm) (passive scanning, no IBSS)
		Bitrates (non-HT):
			* 1.0 Mbps
			* 2.0 Mbps (short preamble supported)
			* 5.5 Mbps (short preamble supported)
			* 11.0 Mbps (short preamble supported)
			* 6.0 Mbps
			* 9.0 Mbps
			* 12.0 Mbps
			* 18.0 Mbps
			* 24.0 Mbps
			* 36.0 Mbps
			* 48.0 Mbps
			* 54.0 Mbps
	Band 2:
		Capabilities: 0x872
			HT20/HT40
			Static SM Power Save
			RX Greenfield
			RX HT20 SGI
			RX HT40 SGI
			No RX STBC
			Max AMSDU length: 3839 bytes
			No DSSS/CCK HT40
		Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
		Minimum RX AMPDU time spacing: 4 usec (0x05)
		HT RX MCS rate indexes supported: 0-15, 32
		TX unequal modulation not supported
		HT TX Max spatial streams: 1
		HT TX MCS rate indexes supported may differ
		Frequencies:
			* 5180 MHz [36] (14.0 dBm) (passive scanning, no IBSS)
			* 5200 MHz [40] (15.0 dBm) (passive scanning, no IBSS)
			* 5220 MHz [44] (15.0 dBm) (passive scanning, no IBSS)
			* 5240 MHz [48] (15.0 dBm) (passive scanning, no IBSS)
			* 5260 MHz [52] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5280 MHz [56] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5300 MHz [60] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5320 MHz [64] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5500 MHz [100] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5520 MHz [104] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5540 MHz [108] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5560 MHz [112] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5580 MHz [116] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5600 MHz [120] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5620 MHz [124] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5640 MHz [128] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5660 MHz [132] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5680 MHz [136] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5700 MHz [140] (15.0 dBm) (passive scanning, no IBSS, radar detection)
			* 5745 MHz [149] (15.0 dBm) (passive scanning, no IBSS)
			* 5765 MHz [153] (15.0 dBm) (passive scanning, no IBSS)
			* 5785 MHz [157] (15.0 dBm) (passive scanning, no IBSS)
			* 5805 MHz [161] (15.0 dBm) (passive scanning, no IBSS)
			* 5825 MHz [165] (15.0 dBm) (passive scanning, no IBSS)
		Bitrates (non-HT):
			* 6.0 Mbps
			* 9.0 Mbps
			* 12.0 Mbps
			* 18.0 Mbps
			* 24.0 Mbps
			* 36.0 Mbps
			* 48.0 Mbps
			* 54.0 Mbps
	max # scan SSIDs: 20
	Supported interface modes:
		 * IBSS
		 * managed
		 * AP  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<这个支持AP
		 * AP/VLAN
		 * monitor
	Supported commands:
		 * new_interface
		 * set_interface
		 * new_key
		 * new_beacon
		 * new_station
		 * new_mpath
		 * set_mesh_params
		 * set_bss
		 * authenticate
		 * associate
		 * deauthenticate
		 * disassociate
		 * join_ibss
		 * Unknown command (68)
		 * Unknown command (55)
		 * Unknown command (57)
		 * Unknown command (59)
		 * Unknown command (67)
		 * set_wiphy_netns
		 * Unknown command (65)
		 * Unknown command (66)
		 * connect
		 * disconnect

这个Band 是什么?我怎么会有两个?
Thinkpad X200 7457A78
Intel Core2 Duo(Penryn) P8600(2.4GHz)
3GB RAM
wdboss
帖子: 240
注册时间: 2007-09-12 10:30
联系:

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#8

帖子 wdboss » 2011-06-19 0:32

可惜共享了网络后,本机就不能正常上网了。。。
Dell Inspiron 1520
Intel Centrino Duo MTL
Intel 965PM Express
Core 2 Duo T7250 2.0GHz
2GB 667MHz DDR2
NVIDIA GeForce Go 8600M GT
120GB SATA
Intel PRO/Wireless 3945
OS:Ubuntu 8.10 64位
Status:一切正常
whyseu
帖子: 10
注册时间: 2011-07-12 12:16

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#9

帖子 whyseu » 2011-07-12 12:23

请问hostapd虚拟机下的网络配置是怎么操作的?网络怎么配置才能让usb无线网卡通过有线局域网上网?谢谢!
静夜思123
帖子: 4
注册时间: 2011-08-12 11:33

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#10

帖子 静夜思123 » 2011-08-12 18:09

我按命令完成配置,并成功启动,在ubuntu下了实现软AP ,客户端的无线网卡能够找到SSID,但连上就断,断了自动连,反反复复的,
wlan0: STA 08:10:74:d7:e5:81 IEEE 802.11: authenticated
wlan0: STA 08:10:74:d7:e5:81 IEEE 802.11: associated (aid 1)
wlan0: STA f0:7b:cb:9f:c5:e5 IEEE 802.11: authenticated
wlan0: STA f0:7b:cb:9f:c5:e5 IEEE 802.11: associated (aid 2)
wlan0: STA 08:10:74:d7:e5:81 IEEE 802.11: deauthenticated due to local deauth request
wlan0: STA 08:10:74:d7:e5:81 IEEE 802.11: authenticated
wlan0: STA 08:10:74:d7:e5:81 IEEE 802.11: associated (aid 1)
wlan0: STA f0:7b:cb:9f:c5:e5 IEEE 802.11: deauthenticated due to local deauth request
wlan0: STA f0:7b:cb:9f:c5:e5 IEEE 802.11: authenticated
wlan0: STA f0:7b:cb:9f:c5:e5 IEEE 802.11: associated (aid 2)
终端一直这样出现,一直没有成功连接!!!跪求楼主这是为什么!!我之前成功连上过,不知怎的又不行了!!!
chansimtan
帖子: 139
注册时间: 2007-10-20 10:55

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#11

帖子 chansimtan » 2011-08-19 17:21

看着很有技术含量 :em11
头像
yangjinchao
帖子: 119
注册时间: 2006-04-18 21:08
联系:

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#12

帖子 yangjinchao » 2011-09-12 15:38

softap188.jpg
本人有一个无线USB网卡,可以支持软AP,一直以来以为在ubuntu下很难配置,在网上查了资料,不太能搞明白,用gnome自带的网络管理器,看到有一个创建新的无线网络,于是按照提示创建了一个,没想到一试竟然可以用了,挺高兴的,大家也可心试下。我用的是tenda w311a usb外置无线网卡。 :em09
附件
softap1882.jpg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
欢迎光临我的网站 免费软件中国
linux视频教程,免费软件介绍使用
http://freesoftcn.com
bitiwindy
帖子: 3
注册时间: 2009-04-03 9:49

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#13

帖子 bitiwindy » 2011-09-28 17:33

谢谢分享。
看了好多篇相关的帖子,只有这个帖子中的内容有帮助。
头像
速腾1994
论坛版主
帖子: 17379
注册时间: 2008-11-01 20:43
系统: Arch+gnome

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#14

帖子 速腾1994 » 2011-12-12 15:35

有我的牛么?
头像
速腾1994
论坛版主
帖子: 17379
注册时间: 2008-11-01 20:43
系统: Arch+gnome

Re: 怎样在Ubuntu中开启Soft AP(虚拟AP)功能

#15

帖子 速腾1994 » 2011-12-12 15:40

:em04
单网卡共享无线,两不误 :em03
附件
ap.PNG
回复