hostapd+dhcp配置AP,手机能连接上但是不能上网

笔记本/便携移动设备,手机平板等软硬件
回复
头像
aphase
帖子: 20
注册时间: 2012-10-21 18:04
系统: Win7

hostapd+dhcp配置AP,手机能连接上但是不能上网

#1

帖子 aphase » 2012-11-19 23:32

ifconfig的应答

代码: 全选

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 16436
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 11  bytes 940 (940.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11  bytes 940 (940.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

mon.wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        unspec 78-E4-00-A2-80-BA-9D-CD-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
        RX packets 468  bytes 81515 (79.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

p7p1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 222.20.14.175  netmask 255.255.255.0  broadcast 222.20.14.255
        inet6 2001:250:4000:81a8:226:2dff:fea5:eb44  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::226:2dff:fea5:eb44  prefixlen 64  scopeid 0x20<link>
        ether 00:26:2d:a5:eb:44  txqueuelen 1000  (Ethernet)
        RX packets 5861  bytes 1389219 (1.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 415  bytes 109938 (107.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.123.1  netmask 255.255.255.0  broadcast 192.168.123.255
        inet6 fe80::7ae4:ff:fea2:80ba  prefixlen 64  scopeid 0x20<link>
        ether 78:e4:00:a2:80:ba  txqueuelen 1000  (Ethernet)
        RX packets 10  bytes 2187 (2.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 83  bytes 16196 (15.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
启动过程

代码: 全选

hostapd /etc/hostapd/hostapd.conf
ifconfig wlan0 192.168.123.1 netmask 255.255.255.0 up
dhcpd -q -cf /etc/dhcp/dhcpd.conf wlan0
iptables -t nat -A POSTROUTING -o p7p1 -s 192.168.123.0/24 -j MASQUERADE
hostapd配置

代码: 全选

#
# This will give you a minimal, insecure wireless network.
# 
# DO NOT BE SATISFIED WITH THAT!!!
#
# A complete, well commented example configuration file is
# available here:
#
#	/usr/share/doc/hostapd-0.7.3/hostapd.conf
#
# For more information, look here:
#
#	http://wireless.kernel.org/en/users/Documentation/hostapd
#

ctrl_interface=/var/run/hostapd
ctrl_interface_group=wheel

# Some usable default settings...
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0

# Uncomment these for base WPA & WPA2 support with a pre-shared key
wpa=3
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

# DO NOT FORGET TO SET A WPA PASSPHRASE!!
#wpa_passphrase=YourPassPhrase
wpa_passphrase=password

# Most modern wireless drivers in the kernel need driver=nl80211
driver=nl80211

# Customize these for your local configuration...
interface=wlan0
hw_mode=g
channel=7
ssid=SphericalCow

手机能连接上,我想dhcp应该没有问题,但是不知到为什么上不了网,不是手机DNS的问题(直接输入了一个ip访问不了)

不知道问题出在哪里? :em20
头像
lxr1234
帖子: 721
注册时间: 2009-04-10 11:15
来自: 三民主义国国民权利省我的选择市中共下台镇

Re: hostapd+dhcp配置AP,手机能连接上但是不能上网

#2

帖子 lxr1234 » 2012-11-20 9:53

nat没做
强烈反对M$的ARM Secure Boot 锁定要求,大家请签名反对
http://www.fsf.org/campaigns/secure-boo ... cted-boot/
头像
aphase
帖子: 20
注册时间: 2012-10-21 18:04
系统: Win7

Re: hostapd+dhcp配置AP,手机能连接上但是不能上网

#4

帖子 aphase » 2012-11-20 11:53

lxr1234 写了:nat没做
我iptables里面只加了一条 -o 输出的,刚才把 -i的也加上了,

代码: 全选

iptables -t nat -A POSTROUTING -o p7p1 -s 192.168.123.0/24 -j MASQUERADE
iptables --append FORWARD --in-interface wlan0 -j ACCEPT
还是不行,能连接上,不能上网,不是hostapd里DNS问题
很疑惑啊。NAT这里怎么设置才算正确?
头像
aphase
帖子: 20
注册时间: 2012-10-21 18:04
系统: Win7

Re: hostapd+dhcp配置AP,手机能连接上但是不能上网

#5

帖子 aphase » 2012-11-20 12:32

代码: 全选

sysctl net.ipv4.conf.all.forwarding=1
加了这个解决了~ :em05 好开心
lovetide
帖子: 4
注册时间: 2007-02-04 2:29

Re: hostapd+dhcp配置AP,手机能连接上但是不能上网

#6

帖子 lovetide » 2014-12-03 15:55

aphase 写了:

代码: 全选

sysctl net.ipv4.conf.all.forwarding=1
加了这个解决了~ :em05 好开心
谢谢,遇到同样的问题,的确用这个命令解决了
Joseph DH.F
帖子: 5
注册时间: 2017-03-24 23:15
系统: ubuntu

Re: hostapd+dhcp配置AP,手机能连接上但是不能上网

#7

帖子 Joseph DH.F » 2017-03-24 23:17

sysctl: error: 'net.ipv4.conf.all.forwarding=1' is an unknown key
要怎么解决哦
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: hostapd+dhcp配置AP,手机能连接上但是不能上网

#8

帖子 poloshiao » 2017-03-25 6:54

sysctl: error: 'net.ipv4.conf.all.forwarding=1' is an unknown key
要怎么解决哦
把下面指令 複製 貼進終端機 執行
1. sudo sysctl -a | grep net.ipv4.conf.all.forwarding
2. sudo cat /proc/sys/net/ipv4/conf/all/forwarding
把結果直接複製 貼上來
Joseph DH.F
帖子: 5
注册时间: 2017-03-24 23:15
系统: ubuntu

Re: hostapd+dhcp配置AP,手机能连接上但是不能上网

#9

帖子 Joseph DH.F » 2017-03-25 11:16

poloshiao 写了:
sysctl: error: 'net.ipv4.conf.all.forwarding=1' is an unknown key
要怎么解决哦
把下面指令 複製 貼進終端機 執行
1. sudo sysctl -a | grep net.ipv4.conf.all.forwarding
2. sudo cat /proc/sys/net/ipv4/conf/all/forwarding
把結果直接複製 貼上來
我是在开发板上执行的,不支持sudo,结果如下:
~ # sudo sysctl -a | grep net.ipv4.conf.all.forwarding
sh: can't execute 'sudo': No such file or directory
~ # sysctl -a | grep net.ipv4.conf.all.forwarding
sysctl: error reading key 'net.ipv4.route.flush': Permission denied
net.ipv4.conf.all.forwarding = 1
sysctl: error reading key 'net.ipv6.route.flush': Permission denied
~ # cat /proc/sys/net/ipv4/conf/all/forwarding
1
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: hostapd+dhcp配置AP,手机能连接上但是不能上网

#10

帖子 poloshiao » 2017-03-25 15:06

我是在开发板上执行的,不支持sudo,结果如下:
可以使用 root 登入嗎
~ # sysctl -a | grep net.ipv4.conf.all.forwarding
sysctl: error reading key 'net.ipv4.route.flush': Permission denied
net.ipv4.conf.all.forwarding = 1
sysctl: error reading key 'net.ipv6.route.flush': Permission denied
可能需要 root 權限
回复