1配置hostapd.conf:sudo gedit /etc/hostapd.conf、
Code:# 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
2.配置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,你可以根据实际情况去修改
3为了确保打开了转发的功能,还要修改一个文件/etc/sysctl.conf。打开文件/etc/sysctl.conf,找到net.ipv4.ip_forward=1,如果被注释了,要将其前面的注释去掉,以便使其生效。如图所示:
4建立一个start.sh文档就可以以后sudo sh satrt.sh
#!/bin/bash
# Start
# Configure IP address for WLAN
sudo ifconfig wlan0 192.168.150.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 ppp0 -j MASQUERADE
# Run access point daemonsudo hostapd /etc/hostapd.conf
# Stop
# Disable NAT
sudo iptables -D POSTROUTING -t nat -o ppp0 -j MASQUERADE
# Disable routing
sudo sysctl net.ipv4.ip_forward=0
# Disable DHCP/DNS server
sudo service dnsmasq stop
sudo service hostapd stop
记得将ppp0替换成eth0或者别的你要分享的上网端口
享受wifi吧!