ubuntu下发射wifi热点

本文介绍了在Ubuntu操作系统中创建WiFi热点的一种简便方法,主要涉及NAT网络地址转换,使用dnsmasq和hostapd软件包。适合atheros系列网卡,对于realtek网卡未做测试。

为了能尽早摆脱windows系统,不得不进行ubuntu下的wifi热点创建的探索。根据网上许多帖子并不断进行试验,终于得到一种较为简单的wifi热点创建方法。网上在ubuntu下发射wifi热点的方法无非就是两种:桥接和NAT网络地址转换。经过本人的实验,桥接网卡真心不容易,单单是找那些资源包都找的辛苦,况且到最后居然得到无法将无线网卡桥接过去的结果。NAT网络地址转换还是比较容易实现的,只需要两个软件包:dnsmasq.deb和hostapd.deb。这两个软件包会在文章最后给出链接。
注意,此方法只在atheros系列的网卡上通过,realtek没尝试过,不过realtek的网卡真心觉得不咋的,还是atheros的比较靠谱。

1、安装dnsmasq和hostapd

sudo apt-get install hostapd dnsmasq
这是最直接简单的方法,同时apt-get还会检测安装软件所需要的依赖包。但是,不保证能在资源列表中找到所要资源,如果无法找到资源,可到此文章尾部提供的链接下载


2、停止dnsmasq和hostapd的服务,防止开机自启

sudo service hostapd stop
sudo service dnsmasq stop
sudo update-rc.d hostapd disable
sudo update-rc.d dnsmasq disable

3、配置dnsmasq
打开dnsmasq的配置文件
sudo gedit /etc/dnsmasq.conf
往此配置文件添加以下内容,保存并退出:
# Bind to only one interface
bind-interfaces
# Choose interface for binding
interface=wlan0
# Specify range of IP addresses for DHCP leasses
dhcp-range=192.168.1.2,192.168.1.255

其中,interface根据你的实际网卡的系统编号来填写,只有一张无线网卡的一般都是wlan0;dhcp-range按你的需要来填写,开始地址必须从2开始,因为1是分配给无线网卡的ip。


4、配置hostapd
sudo gedit /etc/hostapd.conf
往此配置文件添加以下内容,保存并退出:
# Define interface
interface=wlan0
# Select driver
driver=nl80211
# Set access point name
ssid=myhotspot
# Set access point harware mode to 802.11g
hw_mode=g
# Set WIFI channel (can be easily changed)
channel=6
# Enable WPA2 only (1 for WPA, 2 for WPA2, 3 for WPA + WPA2)
wpa=2
wpa_passphrase=mypassword

myhotspot为你的wifi热点名称,mypassword为你的wifi热点密码


5、编写wifi热点启动脚本
随便一个地方,新建一个文件,如MyAP 然后添加以下内容,保存并退出
#!/bin/bash
# Start
# Configure IP address for WLAN
sudo ifconfig wlan0 192.168.1.1
# Start DHCP/DNS server
sudo service dnsmasq restart
# Enable routing
sudo sysctl net.ipv4.ip_forward=1
# Enable NAT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -o eth0 -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -i eth0 -j ACCEPT
# Run access point daemon
sudo hostapd /etc/hostapd.conf
# Stop
# Disable NAT
sudo iptables -D POSTROUTING -t nat -o eth0 -j MASQUERADE
# Disable routing
sudo sysctl net.ipv4.ip_forward=0
# Disable DHCP/DNS server
sudo service dnsmasq stop
sudo service hostapd stop


第四行的ip地址必须和你之前设置的dns地址在同一个区段;第10~12行用来启用NAT网络地址转换和数据转发


6、用终端运行MyAP
sudo sh MyAP
然后就可以兴高采烈地的用手机连上ubuntu的wifi热点啦~温馨提示:由于电脑端WPA密匙组会更新,手机和电脑的握手包收发不同步,此时手机和电脑的连接会出现短暂中断。解决这个问题的方法,就是强制使电脑端WPA密匙不更新,具体怎么实现,靠大家自己去琢磨啦


7、下载链接 
dnsmasq.deb
hostapd.deb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值