Linux 环境下开启wifi热点
来源:互联网 发布:vb调用按键精灵脚本 编辑:程序博客网 时间:2024/06/10 05:47
Linux 环境下开启wifi热点
- hostap
- dhcp
- bash
Hostapd
hostapd is a user space daemon for access point and authentication servers.
hostapd是AP和认证服务器的守护进程,使用hostapd可以无网卡调整为maste模式,从模拟一个路由的功能,也就是软AP(soft AP)。
简单来讲,hostapd可以通过配置创建一个软AP,下面具体介绍一下配置过程。
环境要求
-网卡支持master模式 -linux(debian, ubuntu, archlinx) -Linux mac80211 驱动
安装 HOSTAPD
$: sudo apt-get install hostapd
或者下载安装。
配置 HOSTAPD
在 * /etc/hostapd/hostapd.conf * 文件内写入如下内容
#sets the wifi interface to use, is wlan0 in most casesinterface=wlan0#driver to use, nl80211 works in most casesdriver=nl80211#sets the ssid of the virtual wifi access pointssid=ff#sets the mode of wifi, depends upon the devices you will be using. It can be a,b,g,n. Setting to g ensures backward compatiblity.hw_mode=g#sets the channel for your wifichannel=6#macaddr_acl sets options for mac address filtering. 0 means “accept unless in deny list”macaddr_acl=0#setting ignore_broadcast_ssid to 1 will disable the broadcasting of ssidignore_broadcast_ssid=0#Sets authentication algorithm#1 - only open system authentication#2 - both open system authentication and shared key authenticationauth_algs=1#####Sets WPA and WPA2 authentication######wpa option sets which wpa implementation to use#1 - wpa only#2 - wpa2 only#3 - bothwpa=3#sets wpa passphrase required by the clients to authenticate themselves on the networkwpa_passphrase=KeePGuessinG#sets wpa key managementwpa_key_mgmt=WPA-PSK#sets encryption used by WPAwpa_pairwise=TKIP#sets encryption used by WPA2rsn_pairwise=CCMP
执行命令
$:sudo hostapd /etc/hostapd/hostapd.conf
现在hostapd的配置已经完成,手机已经可以搜索到一个名为ff的wifi。但是还连不上这个wifi,因为现在还没有配置dhcp服务器。
DHCP
现在HOSTAPD已经可以正确运行了,只需要配置好DHCP服务器就可以用移动设备接入wifi上网了。DHCP用来给连如的移动设备分配ip地址,首先安装DHCP服务器。
$:sudo apt-get install isc-dhcp-server
编辑* /etc/dhcp/dhcpd.conf *文件,内容如下:
ddns-update-style none;ignore client-updates;authoritative;option local-wpad code 252 = text; subnet 10.0.0.0 netmask 255.255.255.0 { # --- default gateway option routers 10.0.0.1; # --- Netmask option subnet-mask 255.255.255.0; # --- Broadcast Address option broadcast-address 10.0.0.255; # --- Domain name servers, tells the clients which DNS servers to use. option domain-name-servers 10.0.0.1, 8.8.8.8, 8.8.4.4; option time-offset 0; range 10.0.0.3 10.0.0.13; default-lease-time 1209600; max-lease-time 1814400; }
BASH脚本
配置一个用来上网的简单bash脚本就可以了。假设命名为wifi.sh,写入如下内容。
#!/bin/bash#Initial wifi interface configurationifconfig $1 up 10.0.0.1 netmask 255.255.255.0sleep 2###########Start DHCP, comment out / add relevant section###########Thanks to Panji#Doesn’t try to run dhcpd when already runningif [ “$(ps -e | grep dhcpd)” == “” ]; then dhcpd $1 &fi############Enable NATiptables --flushiptables --table nat --flushiptables --delete-chainiptables --table nat --delete-chainiptables --table nat --append POSTROUTING --out-interface $2 -j MASQUERADEiptables --append FORWARD --in-interface $1 -j ACCEPT#Thanks to lorenzo#Uncomment the line below if facing problems while sharing PPPoE, see lorenzo’s comment for more details#iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtusysctl -w net.ipv4.ip_forward=1#start hostapdhostapd /etc/hostapd/hostapd.conf
使用格式为
./wifi.sh wifi_card_interface interface_with_internet
查看自己电脑的无线网卡和有线网卡的名字,比如我的是** wlan0 *, * eth0 **。
$:ifconfig -a
执行
chmod a+x wifi.shsudo ./wifi.sh wlan0 eth0
参考:·The Linux Way to create Virtual Wifi Access Point
- Linux 环境下开启wifi热点
- Win7开启wifi热点
- 电脑开启wifi热点
- win10开启wifi热点
- WIFI开启扫描热点
- 笔记本开启wifi热点
- Ubuntu开启wifi热点
- win10开启wifi热点
- win7下开启wifi热点共享网络的方法
- Win7下开启wifi热点少见的常用注意事项
- linux命令行模式下配置wifi热点
- Linux:Ubuntu16.04下创建Wifi热点
- 9615 wifi热点调试记录----开启热点
- win7笔记本开启wifi热点
- ubuntu14.04开启wifi热点
- ubuntu14.04开启wifi热点
- deepin15.1 开启wifi热点
- windows DOS开启wifi热点
- socket编程原理
- Codeforces Round #357 (Div. 2) E 计算几何
- 基于Reactor模式的HBase服务端请求处理分析
- windows+nginx+php运行环境部署
- Hbase-0.98.6源码分析--RegionServer宕机处理
- Linux 环境下开启wifi热点
- 01-Opencv-图像显示
- CSS选择器
- WebService学习总结二 使用JDK开发WebService
- 随机数产生代码的区别
- Redis 和 Memcached 的区别详解
- js学习及兼容性整理(一)
- USB-SERIAL / PL2303 工作流程
- 醉逍遥天龙