我正在设置无线 ap没有网络连接。客户端可以连接到主机服务器并获取IP地址感谢域名解析。问题是客户端无法ping通服务器,服务器也无法ping通客户端。我的服务器是树莓派3。
当对服务器主机上的客户端执行 ping 操作时,我得到ping: connect: Network is unreachable
.尽管客户端已连接并具有 IP 地址(使用 测试$ ip a
)。
我不需要互联网接入,也不想设置它。因此我没有建立一座桥梁。
这是我的hostapd.conf
:
# the interface used by the AP
interface=wlan0
# "g" simply means 2.4GHz band
hw_mode=g
# the channel to use
channel=10
# limit the frequencies used to those allowed in the country
ieee80211d=1
# the country code
country_code=SE
# 802.11n support
ieee80211n=1
# QoS support, also required for full speed on 802.11n/ac/ax
wmm_enabled=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=raspi
wpa_passphrase=********
这是我的/etc/dnsmasq.conf
:
interface=wlan0
dhcp-range=192.168.10.2,192.168.10.30,255.255.255.0,12h
dhcp-option=3,192.168.10.1
dhcp-option=6,192.168.10.1
server=8.8.8.8
log-queries
log-dhcp
listen-address=127.0.0.1
要启动 ap,我运行:
wpa_cli terminate;
systemctl stop dhcpcd;
systemctl start hostapd;
systemctl start dnsmasq;
停止我运行的应用程序
systemctl stop dnsmasq;
systemctl stop hostapd;
systemctl restart dhcpcd;
我尝试过nmap -sn 192.168.10.0/24
网络,只有一个结果,即客户端,仅在路由器上进行nmaping 192.168.10.1
,即使ssh正在pi上工作(当ap关闭并且pi连接到另一个wifi时),也没有给出任何结果。
当$ ip a
在服务器上执行操作时,它仍然具有与启动 ap 之前相同的 IP 地址,当它连接到 wifi 时,但是,无法通过“老的”无线上网。
综上所述,看起来 rpi 可以创建一个 AP 并给出 IP 地址。它说它与一个IP地址连接,但是当ping rpi时,它在任何地方都没有连接。操作系统是新安装的。我该如何解决这个问题?
编辑:
从服务器视角:
$ ping 192.168.10.10 # same for x.x.x.1 and x.x.x.0
ping: connect: Network is unreachable
$ ip route
# No output
$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether b8:27:eb:42:db:a0 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:17:8e:f5 brd ff:ff:ff:ff:ff:ff
来自客户视角:
$ ping 192.168.10.1 ## same output for x.x.x.0 too
ping 192.168.10.1
PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
From 192.168.10.10 icmp_seq=1 Destination Host Unreachable
From 192.168.10.10 icmp_seq=2 Destination Host Unreachable
From 192.168.10.10 icmp_seq=3 Destination Host Unreachable
^C
--- 192.168.10.1 ping statistics ---
6 packets transmitted, 0 received, +3 errors, 100% packet loss, time 5054ms
pipe 3
$ ping 192.168.10.10 ## pinging the client itself
ping 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.031 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.122 ms
64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.042 ms
64 bytes from 192.168.10.10: icmp_seq=4 ttl=64 time=0.040 ms
^C
--- 192.168.10.10 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3039ms
rtt min/avg/max/mdev = 0.031/0.058/0.122/0.036 ms
$ ip route
default via 192.168.10.1 dev wlan0 proto dhcp metric 302
192.168.10.0/24 dev wlan0 proto dhcp scope link src 192.168.10.10
$ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether d4:61:9d:1b:3f:78 brd ff:ff:ff:ff:ff:ff
inet 192.168.10.10/24 brd 192.168.10.255 scope global noprefixroute wlan0
valid_lft forever preferred_lft forever
在我上次的测试中可能出了点问题,因为我说服务器显示了它拥有的旧IP地址,当我重新启动应用程序时,它时不时地会这样做。
答案1
如果将来有人遇到这种情况,请在启动 AP 和 dhcp 服务器后运行以下命令即可完成此任务:
ifconfig wlan0 192.168.2.1 netmask 255.255.255.0 up
route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1
这是因为我需要为 wlan0 接口设置一个 IP 地址,然后将其路由到网络。这样,rpi 连接到网络,因为所有网络请求都会路由到正确的地址。