脚本宝典收集整理的这篇文章主要介绍了使用hostapd和dhcpd来在Ubuntu上开启无线热点,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
Hostapd简介:
简单说,hostapd能够使得无线网卡切换为master模式,模拟AP(通常可以认为是路由器)功能,也就是我们说的软AP(Soft AP)。
Hostapd的功能就是作为AP的认证服务器,负责控制管理stations(通常可以认为带无线网卡的PC)的接入和认证。
通过Hostapd可以将无线网卡切换为AP/Master模式,通过修改配置文件,可以建立一个开放式的(不加密)的,WEP,WPA或WPA2的无线网络。并且通过修改配置文件可以设置无线网卡的各种参数,包括频率,信号,beacon包时间间隔,是否发送beacon包,如果响应探针请求等等。还可以设置mac地址过滤条件等。具体可以参考它的配置文件说明。
下面就从官网上摘下的部分原因及翻译。翻译的不好请见谅。
hostapd is an IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator.
Hostapd是IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP/RADIUS的认证器
hostapd is a user space daemon for access point and authentication servers. IT implements IEEE 802.11 access point management, IEEE 802.1X/WPA/WPA2/EAP Authenticators, RADIUS client, EAP server, and RADIUS authentication server. The current version supports Linux (Host AP, madwifi, mac80211-based drivers) and FreeBSD (net80211).
Hostapd是一个访问点以及认证服务器的运行于用户空间的守护程序。它实现了IEEE 802.11接入带你(Access Point)的管理功能,是IEEE 802.1X/WPA/WPA2/EAP的认证器,是 RADIUS client, EAP server, and RADIUS认证服务器。当前版本的hostapd支持linux上Host AP,madwifi和基于mac80211协议栈的驱动程序,以及FreeBSD上net80211协议栈的驱动程序。
hostapd is designed to be a “daemon” PRogram that runs in the background and acts as the backend component controlling authentication. hostapd supports separate frontend programs and an example text-based frontend, hostapd_cli, is included with hostapd.
Hostapd是一个后台守护进程,作为后台组件来控制和管理认证功能。Hostapd支持多个前台程序。hostapd_cli,就是一个跟hostapd一起的命令行前台程序。
下面我们来看一下利用hostapd和dhcpd在ubuntu系统上建立无线热点的方法:
执行 iwlist 如果 Supported interface modes 的下有 AP 的话表示该网卡支持AP模式,可以创建无线热点。
比如我的无线网卡是Qualcomm Atheros AR9485 Wireless Network Adapter,Linux内核自带了驱动ath9k,支持创建AP无线热点。
1. 安装hostapd和dhcpd
开机不需要启动这两个服务,建议把它们关掉:
sudo update-rc.d -f hostapd remove
注释掉下面两个文件start on那一行:
sudo nano /etc/init/isc-dhcp-server.conf
sudo nano /etc/init/isc-dhcp-server6.conf
2. 配置hostapd和dhcpd
sudo nano /etc/hostapd/hostapd.conf
注意自己设置其中的无线热点名称ssid和认证密码wpa_passp
hrase.
interface=wlan0
driver=nl80211
ssid=YOUR_AP_NAME
hw_mode=g
channel=10
ma
CADdr_acl=0
auth_algs=3
wpa=2
wpa_passphrase=YOUR_AP_PASSWORD
wpa_key_mgmt=WPA-PSK
wpa_p
airwise=TKIP CCMP
rsn_pairwise=TKIP CCMP
sudo nano /etc/dhcp/dhcpd.conf
在末尾加入以下内容:
subnet 192.168.0.0
netmask 255.255.255.0
{
range 192.16
8.0.2 192.168.0.10;
option routers 192.168.0.1;
option domain-name-servers 192.168.0.1,180.76.76.76,8.8.8.8;
}
其中180.76.76.76是
百度公共DNS服务器,8.8.8.8则是
GOOGLE的DNS服务器.
在自己的家目录下创建一个hostapd目录,里面新建启动和关闭脚本,比如我这样写(注意把里面eechen换成你的用户名):
nano /home/eechen/hostapd/ap-start.sh</p>
<p>
#!/bin/bash
# 开启内核IP转发
bash -c "echo 1 > /proc/
Sys/net/
ipv4/ip_forward"
# 开启
防火墙NAT转发(如果本机使用eth0上网,则把ppp0
改为eth0)
iptables
-t nat -A POSTROUTING -o ppp0 -j MASQUERADE
# 关闭NetworkManager对无线网卡的控制
nmcli nm wifi off
# 设置并启动无线网卡
if
config wlan0 192.168.0.1 netmask 255.255.255.0
# 解锁无线设备,可以用rfkill list查看解锁结果.
rfkill unblock wlan
#
睡眠6秒,待rfkill解锁
生效sleep 6s
# 启动dhcpd和hostapd,如果hostapd无法启动请查看日志hostapd.
LOG,查看这两个进程ps -ef|egrep "dhcpd|hostapd"
nohup hostapd /etc/hostapd/hostapd.conf >/home/eechen/hostapd/hostapd.log 2>&1 &
dhcpd wlan0 -pf /
VAR/run/dhcpd.pid
ps -ef|head -
n1 && ps -ef|egrep "dhcpd|hostapd"
nano /home/eechen/hostapd/ap-stop.sh</p>
<p>#!/bin/bash
killall hostapd dhcpd
bash -c "echo 0 > /proc/sys/net/i
pv4/ip_forward"
i
fconfig wlan0 down
3. 启动hostapd和dhcpd
在桌面新建两个启动器(快捷方式),里面分别填入:
gksu /home/eechen/hostapd/ap-start.sh
gksu /home/eechen/hostapd/ap-stop.sh
因为脚本需要
root用户身份执行,所以需要用gksu运行。
注意:如果你开启了ufw防火墙,ufw默认是禁止转发的,这会导致防火墙NAT转发失效,这时应该设置允许转发:
sudo nano /etc/default/ufw 将 DEFAULT_FORWARD_
policy 设为 ACCEPT
然后重启ufw即可:
sudo service ufw restart
之后运行启动器即可启动和关闭AP无线热点。
4. 用Wireshark监控经过wlan0的通信
安装wireshark(其中 eechen改为你的用户名):
sudo apt-get install wireshark
sudo chgrp eechen /usr/bin/dumpcap
sudo chmod 750 /usr/bin/dumpcap
sudo setcap cap_net_raw,cap_net_admin+
eip /usr/bin/dumpcap
Alt+
f2运行wireshark,选择
网络接口wlan0,Filter里输入http.cookie contains mail.
QQ.COM然后手机端登录网页QQ邮箱,在WireShark即可查看和获取QQ邮箱登录的Cookie,如图所示:
右键点击Cookie项把Value复制出来,然后用Firefox访问站点https://w.mail.qq.com/,Alt+C激活 Ori
ginal Cookie Injector( Grea
SEMonkey),弹出输入框Wireshark Cookie Dump,把Cookie项的Value粘贴到里面,然后点OK确定并刷新页面即可登录QQ邮箱。
或者你使用Tam
PEr Data这个Firefox扩展在提交时修改Cookie值也是可以的。
附:
查看连接wlan0网络的客户端:
sudo arp
返回IP地址和MAC
硬件地址和无线接口名.
iw dev wlan0 station dump
能显示收发包和
字节数等.
查看网络接口速度:
sar -n DEV 1
脚本宝典总结
以上是脚本宝典为你收集整理的使用hostapd和dhcpd来在Ubuntu上开启无线热点全部内容,希望文章能够帮你解决使用hostapd和dhcpd来在Ubuntu上开启无线热点所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。