说一下我怎么弄的.dhcp3-server加hostapd,
网上有教程,不过好多说的细节不怎么样.我说一下我的.我是ubuntu 12.04.5 LTS 32bit版
首先,我的笔记本电脑无线网卡是内置的,artheros的ar9285.带ap那种.用ctrl-alt-t呼出控制台,sudo lspci,能看到.ubuntu已经自带驱动了.
安装 iw 命令:sudo apt-get install iw,我的ubuntu 12.04 自己已经有了.
命令iw list 查看是否支持 AP,是可以看到AP模式的支持字样的.
新立得软件包管理器,卸载dnsmasq,好像有个dnsmasq-base,和dnsmasq-utils那2个不用管.之前是过用dnsmasq搭配hostapd,不成功.
安装 hostapd 命令:sudo apt-get install hostapd .
root模式编辑/etc/hostapd.conf
比如sudo gedit /etc/hostapd.conf, 或者sudo nautilus,管理员级文件夹管理器,直接过去找.这个文件不存在,需要自己手动建.
hostapd.conf里头写,注意这个文件不能有注释语句...井号开头那种,自己用时候要删除.
interface=wlan0 #这个是因为我ubuntu无线网卡ifconfig中就是wlan0
driver=nl80211
ssid=abcde12345 #无线登陆帐号和显示名
hw_mode=g #我的无线网卡是802.11 a/b/g模式,这里默认选择g模式.这好像就这么要求的.包括就算实际启用b模式,这个也要写g...不知道怎么搞的.
channel=11
dtim_period=1
rts_threshold=2347
fragm_threshold=2346
macaddr_acl=0 #/etc/下有allow和deny两个表单,0表示deny表单中没写的,就都放行,1表示allow表单中写有的,才放行.实际要手动写参数行,和自己编写2个列表的,accept_mac_file=/etc/hostapd.accept和deny_mac_file=/etc/hostapd.deny我这根本就是偷懒
auth_algs=3 #这是个bit位值,1表示osa,2表示ska,3表示两者都支持
ieee80211n=0 #我那个无线网卡不支持802.11n,所以这里写0
wpa=3 # 这是个bit位值,1表示wpa,2表示wpa2,3表示使用wpa/wpa2双兼容型
wpa_passphrase=fghij67890 #wifi热点登陆密码
wpa_key_mgmt=WPA-PSK #表示使用psk模式
wpa_pairwise=TKIP CCMP #以下两行表示同时兼容wpa2和wpa配对登陆
rsn_pairwise=TKIP CCMP
-=--==--==
安装dhcp3-server 命令:sudo apt-get install dhcp3-server
配置之,sudo gedit /etc/dhcp/dhcpd.conf 需要root级权限编辑,
我用的dhcpd.conf模板:
ddns-update-style none;
option domain-name "example.org";
option domain-name-servers 114.114.114.114, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.6.0 netmask 255.255.255.0 {
range 192.168.6.10 192.168.6.245;
option domain-name-servers 114.114.114.114;
option domain-name "SoftAP";
option routers 192.168.6.1;
option broadcast-address 192.168.6.255;
default-lease-time 600;
max-lease-time 7200;
}
=--=-=模版结束-===--=-=
设置IP转发(连接外网)
命令: Echo "1" >/proc/sys/net/ipv4/ip_forward
可以这样 /etc/sysctl.conf文件.也是root权限级编辑.
其中有1行参数,默认是注释掉的,把那行开头的井号#删除,开启ip转发.
net.ipv4.ip_forward=1
然后 /proc/sys/net/ipv4/ip_forward 文件,也是要root级权限编辑.
默认是0,改成1.但是这个文件渺似不能用文本编辑器改,用控制台命令
sudo su 切入su模式, 然后
echo 1 >/proc/sys/net/ipv4/ip_forward 来做
如果用sudo,提示权限不够
=-=-=---=-=-
最后用一个脚本来启动,保存成myap.sh类似这样,其中192.168.6.x因为我dhcp就那么配置的ip池,所以,这里也是192.168.6.x,我的eth0网卡静态配的192.168.1.x,这里用192.168.6.x以示区别.ppp0是因为我adsl上网的,所以肯定网络流量上internet出口不是eth0...wlan0就是我的atheros的ubuntu无线网卡.
代码: 全选
#!/bin/sh
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t nat -A POSTROUTING -s 192.168.6.0/24 -o ppp0 -j MASQUERADE
iptables -A FORWARD -s 192.168.6.0/24 -o ppp0 -j ACCEPT
iptables -A FORWARD -d 192.168.6.0/24 -m conntrack --ctstate ESTABLISHED,RELATED -i ppp0 -j ACCEPT
ifconfig wlan0 192.168.6.1 netmask 255.255.255.0
dhcpd wlan0 -pf /var/run/dhcp-server/dhcpd.pid
hostapd -B /etc/hostapd.conf
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
之后sudo sh myap.sh
启动脚本.就能手机上网了.ssid的密码就按照上头配置的.就行.
相当于让ubuntu当了softAP软路由wifi热点.
=--=-=-==--=
但是这方法有一个问题,开softAP模式以后ubuntu本身就不能上网了.
我看网上说有一种解决方法,就是说,弄一条全0.0.0.0路由,给ubuntu指一个流量出口,但是配置写在哪儿,在哪儿设置?语法是什么....不懂啊.
所以,求助!!!!