linux下利用hostapd发射wifi热点(亲测debian)

2025-10-07 23:47:07

1、首先呢,把三个工具安进去,iptables我的本机自带了,不知道什么情况。

dnsmasq可能会提示port:53的fail,那个不用管。

2、准备配置文件

hostapd的配置文件在/usr/share/doc/hostapd/examples下,解压出hostapd.conf,为了方便cp到/etc下。里面的内容不必像网上乱飞的文章上改那么多,直接把interface=wlan0改成你要用作发射wifi的网卡(网卡要支持ap模式wilist查看),其他的看着改吧,都不是必须的,只有这个非常重要。

dnsmasq的新建吧。内容如下

interface=wlan0 #你猜dhcp-range=192.168.123.100,192.168.123.199,12h #分配地址的

这些就够了,不用像乱飞的文章里改那么多,需求另类的当我白说。

3、哈哈  下面的我就懒一些了直接复制朋友的代码了,每次想开启的时候 sh ×× start

下面有解释,自己看吧

#!/bin/sh

#Clean things upinit() { 

#Stop NetworkManager, if already running (it will disturb you) 

/usr/sbin/service network-manager stop

#Stop named, if already running. dnsmasq cannot run because it take up port 53 

killall named 

#Stop dnsmasq, if already running 

/usr/sbin/service dnsmasq stop 

#Stop hostapd, if already running 

/usr/bin/pkill hostapd 

#Bring down wlan0 

/sbin/ip link set down dev wlan0

}

start() { 

#First clean things up 

init 

#Start hostapd, and it will automatically be bringed up 

/usr/sbin/hostapd -B /etc/hostapd.conf 

#Set ip on wlan0 

/sbin/ip addr add 192.168.123.1/24 dev wlan0 

#Start dnsmasq 

/usr/sbin/service dnsmasq start

#Start ip_forward 

echo 1 > /proc/sys/net/ipv4/ip_forward 

#add iptables rule for NAT 

/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

}

stop() { 

#Remove iptables rule 

/sbin/iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE 

#Stop dnsmasq 

/usr/sbin/service dnsmasq stop 

#Stop hostapd 

/usr/bin/pkill hostapd 

#bring down wlan0, and its ip address will automatically be removed 

/sbin/ip link set down dev wlan0

}

case "$1" in

'start') 

  start 

  ;;

'stop') 

  stop 

  ;;

*) 

echo "usage $0 start|stop"

esac

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:69
  • 阅读量:162
  • 阅读量:159
  • 阅读量:79
  • 阅读量:77
  • 猜你喜欢