
有時,我的客戶端無法存取我的伺服器。當它發生時,然後在我的伺服器上,我可以手動ping
客戶端,現在客戶端可以看到伺服器。
我的問題:不使用 可以做什麼來修復它ping
?
我真的希望你能幫忙解決這個偶發的問題。在糟糕的一天,這種情況最多會發生 5 次。天氣好的時候也許 1 次。天氣好的時候不會有任何問題,但這種情況很少見。
我正在開發我的業餘項目,這是一個帶有 C++ 伺服器的 iOS 應用程式。這將在某個時候開源。
關於我的設置
伺服器和客戶端都在同一個wifi上。
兩種設備都可以www.google.com
在瀏覽器中打開,因此它們可以存取互聯網。
伺服器
macOS version 10.11.6 - El Capitan
NGINX version 1.10.0
IP address: 192.168.0.13 (proxy disabled)
The server is not connected to the router via cable.
The NGINX server is running on port 12345 and controls a FastCGI script.
連結到我的NGINX 配置和主機名稱、ifconfig、解析。
客戶
iPad Pro (I'm also experiencing the same problem with my iPhone)
iOS 9.3.5 (13G36)
IP address: 192.168.0.18 (proxy disabled)
The client is not connected to the server via cable.
路由器
Netgear CG3000, hardware version 1.04, software version 3.9.21.13.mp3.V1.32.02
I'm experiencing the same problem with other routers, can't remember which ones.
路由器事件日誌中沒有寫入任何內容。
重現步驟
我會經歷這些步驟。
第 1 步:客戶端無法存取伺服器
在客戶端:
在瀏覽器中輸入伺服器 IP 和連接埠:http://192.168.0.13:12345/status
但沒有任何反應。客戶端無法到達伺服器。
客戶端可以正常存取互聯網。
步驟 2:伺服器 ping 用戶端 - 讓事情正常運作
在伺服器上:
我ping
透過其 IP 位址作為客戶端,如下所示
PROMPT> ping 192.168.0.18
PING 192.168.0.18 (192.168.0.18): 56 data bytes
64 bytes from 192.168.0.18: icmp_seq=0 ttl=64 time=102.210 ms
64 bytes from 192.168.0.18: icmp_seq=1 ttl=64 time=102.966 ms
64 bytes from 192.168.0.18: icmp_seq=2 ttl=64 time=21.176 ms
^C
--- 192.168.0.18 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 21.176/75.451/102.966/38.379 ms
PROMPT>
此ping
命令使客戶端能夠存取伺服器。為什麼ping
讓它發揮作用?
步驟 3:客戶端現在可以存取伺服器
在客戶端:
在瀏覽器中輸入伺服器 IP 和連接埠:http://192.168.0.13:12345/status
現在我收到伺服器的回應。有用。
如果我啟動代理並攔截流量,則請求/回應如下所示:
要求
GET /status HTTP/1.1
Host: 192.168.0.13:12345
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (iPad; CPU OS 9_3_5 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13G36 Safari/601.1
Accept-Language: da-dk
Cache-Control: max-age=0
Connection: keep-alive
回覆
HTTP/1.1 200 OK
Server: nginx/1.10.0
Date: Sun, 04 Sep 2016 16:11:39 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
{
"request_index": 1047,
"time": "1473005499"
}
答案1
ping 會發出 ARP 請求,這會突然修復您的路由。它將使用伺服器或客戶端的 MAC 位址和 IP 更新您的 ARP 表。
聽起來您的網路上可能有 IP 衝突。
修復它的方法:
當問題發生時,發出 a
arp -a
來列印 ARP 表。然後儲存該清單的副本。透過發出以下命令刪除伺服器(或客戶端)的 IP 條目:
arp -d ipaddress-of-server-or-client
ping 伺服器(或客戶端)
再次發出
arp -a
命令並檢查該 IP 現在顯示的 MAC 位址。如果不同,則表示某個地方存在 IP 衝突。
回顧一下 ARP:https://www.tummy.com/articles/networking-basics-how-arp-works/