linux 发无线 软AP hostapd+dnsmasq

本文介绍如何在校园网环境下使用Linux系统搭建无线接入点(AP),包括安装所需软件、配置hostapd和dnsmasq服务、设置路由规则等步骤,实现为安卓设备提供无线网络。
AI助手已提取文章相关产品:

取自http://blog.youkuaiyun.com/q1302182594/article/details/8689603,博主的情况和我基本一样,都是校园网玩linux想给安卓发无线,配置信息基本不用改,只是他命令里一些空格不清楚,而且我所需要的只是这篇博文的一部分,另外还是想自己记录一下,所以转过来。

1.安装软件:sudo apt-getinstall hostapd dnsmasq 

2.配置hostapd:配置文件是/etc/hostapd.conf,如果装了以后没有就自己新建一个,写入:

interface=wlan0
driver=nl80211
ssid=gilzhyWifi #wifi名
hw_mode=g
channel=11
dtim_period=1
rts_threshold=2347
fragm_threshold=2346
macaddr_acl=0
auth_algs=3
ieee80211n=0
wpa=3
wpa_passphrase=12345678 #密码,行末不要有空格
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

3.配置dnsmasq:配置文件是/etc/dnsmasq.conf,同样的,没有就自己新建一个,写入:

interface=wlan0
bind-interfaces #这个是只监听wlan0,没有之会检测所有卡
except-interface=lo
dhcp-range=192.168.1.100,192.168.1.254,12h #设置dhcp地址范围,即租借时间6小时
dhcp-option=3,192.168.1.1 #为手机配置网关,要和dhcp-arange对应,这涉及网络的知识,不详细介绍。
dhcp-option=6,202.114.128.2 #为手机配置dns,你可以根据实际情况去修改

写入前配置文件应该是只有注释的,如果是这样就只要写入这几行,如果有非注释的address=/#/10.0.0.1,把它注释掉

4.写个脚本添加路由规则,新建myap,写入:

#!/bin/sh
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t nat -APOSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE
iptables -A FORWARD -s 192.168.1.0/24 -o eth0 -j ACCEPT
iptables -A FORWARD -d 192.168.1.0/24 -m conntrack --ctstate ESTABLISHED,RELATED -i eth0 -j ACCEPT

5.确保打开转发功能:/etc/sysctl.conf找到net.ipv4.ip_forward=1,如果被注释了,取消注释

6.启动AP:

su
killall named
killall hostapd
ifconfig wlan0 192.168.1.1
hostapd -B /etc/hostapd.conf
/etc/init.d/dnsmasq restart
echo 1 >/proc/sys/net/ipv4/ip_forward
./myap

7.以后用时,每次都需要输:

ifconfig wlan0 192.168.1.1
hostapd -B /etc/hostapd.conf
/etc/init.d/dnsmasq restart

比较麻烦,修改myaq:

#!/bin/sh
ifconfig wlan0 192.168.1.1
hostapd -B /etc/hostapd.conf
/etc/init.d/dnsmasq restart
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t nat -APOSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE
iptables -A FORWARD -s 192.168.1.0/24 -o eth0 -j ACCEPT
iptables -A FORWARD -d 192.168.1.0/24 -m conntrack --ctstate ESTABLISHED,RELATED -i eth0 -j ACCEPT

每次使用时,切换到root然后运行myap



您可能感兴趣的与本文相关内容

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值