本文由LinuxProbe.Com团队成员魏丽猿整理发布,原文来自:Linux就该这么学。
操作系统:Debian Gnu/Linux 8.3
内核: linux-image-4.3.0-0.bpo.1-amd64
网卡:腾达(Tenda) W311M 150M Mini无线USB网卡
执行vi /etc/apt/sources.list,并添加如下源地址:
deb http://ftp.cn.debian.org/debian/ jessie-backports main contrib non-free
安装最新内核及相关软件组件包,避免编译Hostapd出错,依次执行如下命令:
apt-get update apt-get install linux-image-4.3.0-0.bpo.1-amd64 apt-get install linux-headers-4.3.0-0.bpo.1-all-amd64 apt-get install pkg-config apt-get install libssl-dev apt-get install gettext apt-get install openssl apt-get install libnl-genl-3-dev apt-get install libnl-genl-3-200 apt-get install libnl-3-dev apt-get install libnl-3-200 apt-get install hostapd
进入http://w1.fi/hostapd/网站下载hostapd-2.5.tar.gz文件
wget http://w1.fi/releases/hostapd-2.5.tar.gz
解压并复制配置文件
tar -zxvf hostapd-2.5.tar.gz cd hostapd-2.5 cp defconfig .config
使用vi .config命令对该文件进行修改,修改内容如下:
# Use libnl v2.0 (or 3.0) libraries. CONFIG_LIBNL20=y # Use libnl 3.2 libraries (if this is selected, CONFIG_LIBNL20 is ignored) CONFIG_LIBNL32=y # IEEE 802.11n (High Throughput) support CONFIG_IEEE80211N=y
保存退出,编译安装:
make make install
系统将在/usr/local/bin目录下生成两个文件名为hostapd、hostapd_cli的可执行文件。
将hostapd配置文件复制到/etc/hostapd/文件夹下,并将相关字段修改为如下内容:
cp hostapd.conf /etc/hostapd/ vi /etc/hostapd/hostapd.conf interface=wlan1 driver=nl80211 ssid=LONUXPROBE hw_mode=g channel=7 macaddr_acl=0 auth_algs=3 ignore_broadcast_ssid=0 wmm_enabled=1 ieee80211n=1 ht_capab=[HT40-][SHORT-GI-20][SHORT-GI-40] wpa=2 wpa_passphrase=linuxprobe macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
使用vi对该文件进行编辑,修改内容如下:
vi /etc/default/hostapd DAEMON_CONF="/etc/hostapd/hostapd.conf"
对hostapd服务脚本进行编辑,修改内容如下:
vi /etc/init.d/hostapd DAEMON_SBIN=/usr/local/bin/hostapd
并在start)下一行添加如下内容:
sed -i '/\[keyfile\]/a unmanaged-devices=mac:c8:3a:35:cb:18:e0' /etc/NetworkManager/NetworkManager.conf ip addr add 192.168.11.1/24 dev wlan1 echo "1" >/proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE sleep 2
在stop)下一行添加如下内容:
sed -i '/^unmanaged-devices=mac:c8:3a:35:cb:18:e0/d' /etc/NetworkManager/NetworkManager.conf echo "0" >/proc/sys/net/ipv4/ip_forward ip addr del 192.168.11.1/24 dev wlan1 iptables -t nat -D POSTROUTING -o wlan0 -j MASQUERADE sleep 2
在reload)下一行添加如下内容:
sed -i '/^unmanaged-devices=mac:c8:3a:35:cb:18:e0/d' /etc/NetworkManager/NetworkManager.conf echo "0" >/proc/sys/net/ipv4/ip_forward ip addr del 192.168.11.1/24 dev wlan1 iptables -t nat -D POSTROUTING -o wlan0 -j MASQUERADE sed -i '/\[keyfile\]/a unmanaged-devices=mac:c8:3a:35:cb:18:e0' /etc/NetworkManager/NetworkManager.conf ip addr add 192.168.11.1/24 dev wlan1 echo "1" >/proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE sleep 2
保存退出,(根据自己情况设定参数mac和ip)对脚本文件进行重新配置:
systemctl daemon-reload
apt-get install dnsmasq
vi /etc/dnsmasq.conf resolv-file=/etc/resolv.dnsmasq.conf server=/cn/114.114.114.114 server=/taobao.com/114.114.114.114 server=/google.com/8.8.8.8 listen-address=127.0.0.1,192.168.11.1 dhcp-range=192.168.11.50,192.168.11.150,12h dhcp-option=3,192.168.11.1 dhcp-option=6,192.168.11.1 cache-size=1024 conf-dir=/etc/dnsmasq.d
vi /etc/resolv.dnsmasq.conf nameserver 114.114.114.114 nameserver 223.5.5.5 nameserver 223.6.6.6
vi /etc/resolv.conf nameserver 127.0.0.1
分别使用命令:
systemctl enable dnsmasq.service systemctl disable hostapd.service
开启和关闭两项服务,之后在需要使用热点模式时使用命令:
systemctl start hostpad.serive
用户即可使用热点名为LINUXPROBE,密码为linuxprobe,网关地址和DNS均为192.168.11.1的80211N协议无限热点进行上网连接啦!
本文地址:https://www.linuxprobe.com/debian-wifi.html编辑:魏丽猿,审核员:逄增宝
本文原创地址:https://www.linuxprobe.com/debian-wifi.html编辑:逄增宝,审核员:暂无