Editing
網路服務連線測試
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
如何測試與排除網路服務連線問題。找出問題發生的地方:(1) 伺服器上的本地服務 (localhost) (2) 從區域網路到伺服器 (3) 從廣域網路到伺服器 {{LanguageSwitcher | content = [[Test connectivity for the web service | EN]], [[網路服務連線測試 | 漢字]] }} === 如何連線到網路服務 (Web 服務) === 如果服務是網站伺服器 (web service): * (1) 打開瀏覽器,(2) 輸入地址:{{kbd | key = <nowiki>http://127.0.0.1</nowiki> }} 或 {{kbd | key =<nowiki>http://the.domain</nowiki>}} * Linux Lynx 指令: *# (如果尚未安裝lynx,則為可選操作) {{kbd | key = <nowiki>yum install lynx</nowiki>}} 適用於CentOS / {{kbd | key = <nowiki>sudo apt-get install lynx</nowiki>}} 適用於Ubuntu<ref>[http://www.addictivetips.com/ubuntu-linux-tips/install-and-use-lynx-on-ubuntu/ 在Ubuntu上安裝和使用Lynx瀏覽器]</ref> *# {{kbd | key = <nowiki>lynx http://127.0.0.1</nowiki>}} <ref>[http://lynx.isc.org/lynx2.8.7/lynx2-8-7/lynx_help/Lynx_users_guide.html Lynx使用者指南 v2.8.7]</ref> 適用於{{Linux}} * telnet 指令 *# {{kbd | key = telnet 127.0.0.1 <PORT>}} 例如 {{kbd | key = telnet 127.0.0.1 80}} 或 {{kbd | key = telnet the.domain 80}} *# (在telnet連接80埠後,輸入) {{kbd_plus | key1 = get | key2 = SPACE}}<ref>[http://www.simplescripts.de/http-check-port-80-telnet-command.htm 使用Telnet指令檢查HTTP埠口80]</ref> * curl<ref>[https://curl.se/docs/manpage.html curl - 使用方法]</ref>: {{kbd | key = <nowiki>curl -vL http://IP:Port</nowiki>}} ** (如果尚未安裝curl指令,則為可選操作) [https://help.ubidots.com/en/articles/2165289-learn-how-to-install-run-curl-on-windows-macosx-linux 在Windows/MacOSX/Linux上安裝和運行cURL | Ubidots幫助中心] ** 指令範例: *** (1) 使用 {{kbd | key = <nowiki>curl -voL https://www.google.com</nowiki>}} 將輸出寫入<file>而非stdout *** (2) 使用 {{kbd | key = <nowiki>curl -vL https://www.google.com</nowiki>}} 或 {{kbd | key = <nowiki>curl -voL /dev/null https://www.google.com</nowiki>}} 將輸出寫入stdout *** (3) 使用 {{kbd | key = <nowiki>curl -vOL https://www.google.com/index.html</nowiki>}} 將輸出寫入<file>並使用遠程檔案名 ** 如果失敗,將顯示消息:"failed: Connection refused" * Linux [https://www.gnu.org/software/wget/ wget] 軟體例如 {{kbd | key = <nowiki>wget https://www.google.com</nowiki>}} * 使用第三方網站監控服務:[[Web Ping]] 如果服務不是網站伺服器,則使用telnet # (可選) [https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc771275(v=ws.10) 在{{Win}}上安裝Telnet用戶端 | Microsoft文件]。[https://medium.com/@blackSource/bring-telnet-back-on-macos-high-sierra-11de98de1544 在macOS high Sierra上重啟telnet – Ayuth Mangmesap (blackSource) – Medium] 在{{Mac}} # {{kbd | key = telnet 127.0.0.1 <PORT>}} 如果連接網頁服務失敗。它將顯示消息:"telnet: 無法連接到遠程主機:連接被拒絕" 如果安裝了 Python 或 Node.js,則可使用替代網站服務 * (適用 python 3.x) {{kbd | key=<nowiki>python -m http.server <port></nowiki>}} (預設 port: 8000)<ref>[https://docs.python.org/3/library/http.server.html http.server — HTTP servers — Python 3.13.2 documentation]</ref> * (適用 Node.js) {{kbd | key=<nowiki>npx http-server -p <port></nowiki>}} (預設 port: 8080)<ref>[https://github.com/http-party/http-server http-server: a simple static HTTP server]</ref> == 測試本地網路服務的連接性 == WAN ○ -------> ○ LAN -------> <span style="color:red">● 伺服器</span> {{Tips}} 如果您有管理權限通過SSH或遠程桌面服務登錄伺服器。 === 檢查您的電腦/伺服器是否被指派了IP位址 === * {{Linux}}:(1) 檢查IP位址。{{kbd | key = ifconfig}}。 (2) 重新分配IP位址並重新啟動網路服務。{{kbd | key = service network restart}} 用於CentOS<ref>[http://askubuntu.com/questions/230698/how-to-restart-the-networking-service 如何重新啟動網路服務? - Ask Ubuntu]</ref> * {{Win}}:檢查IP位址。{{kbd | key = ifconfig/all}} * 更多關於[[網路問題]] === 檢查網路服務是否已成功啟動? === * Apache {{kbd | key = /etc/init.d/httpd status}} 在CentOS7上 <ref>[https://www.e2enetworks.com/help/knowledge-base/how-to-check-running-status-of-lamp-stack/ 如何檢查LAMP堆棧的運行狀態 | E2E Networks知識庫]</ref> * nginx {{kbd | key = sudo service nginx status}} 在CentOS7上 * Docker容器 {{kbd | key = docker ps}} 檢查容器是否在運行和暴露埠口<ref>[https://docs.docker.com/engine/reference/commandline/ps/ docker ps | Docker文件]</ref> === 檢查MySQL是否已成功啟動? === ==== 使用lsof指令 ==== {{kbd | key = lsof -i:3306}} 在{{Mac}}或{{Linux}} 在Unix類操作系統中用於列出打開的文件及打開它們的進程。 * lsof:這代表"列出打開的文件"。它是一個命令行工具,顯示有關由進程打開的文件的資訊。在Unix和Linux中,一切都被視為文件(包括硬體設備、套接字和目錄),因此lsof是系統管理員監控和排除系統行為問題的強大工具。 * -i:這個選項告訴lsof僅顯示網絡文件。在Unix和Linux中,網絡連接被視為文件。-i選項可用於根據互聯網地址或網絡協議過濾連接。 * :3306:這指定了埠號。埠3306通常被MySQL使用,這是一個流行的數據庫管理系統。通過包括:3306,您要求lsof列出所有與埠3306相關的網絡文件(包括套接字連接)。 輸出範例:localhost:mysql (LISTEN) 意味著MySQL已成功啟動 <pre> COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 93034 account 29u IPv4 0xxxx 0t0 TCP localhost:mysql (LISTEN) </pre> ==== 使用ps指令 ==== {{kbd | key = <nowiki>ps aux | grep mysql</nowiki>}} 在{{Mac}} 如果MySQL已成功啟動的輸出範例: <pre> _mysql 11083 0.3 0.2 409657280 31424 ?? Ss 2:12下午 0:01.07 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid --keyring-file-data=/usr/local/mysql/keyring/keyring --early-plugin-load=keyring_file=keyring_file.so ACCOUNT 12349 0.0 0.0 408645328 1648 s011 S+ 2:14下午 0:00.00 grep mysql </pre> 如果MySQL沒有成功啟動的示例輸出: <pre> ACCOUNT 12349 0.0 0.0 408645328 1648 s011 S+ 2:14下午 0:00.00 grep mysql </pre> === 檢查埠是否被其他進程佔用? === 檢查埠是否被其他協議使用 [https://www.speedguide.net/ports.php SG TCP/IP埠數據庫] [https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers 維基百科 - TCP和UDP埠號列表] Example output of netstat command, more on [[Find process running on port]] <pre> $ netstat -tulpn | grep LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN - // means the 80 port service is running </pre> === Check if a port is blocked by browser === Check if a port is blocked by browser<ref>[https://blog.miniasp.com/post/2022/05/02/Dont-use-ERR_UNSAFE_PORT-for-your-website?fbclid=IwAR2y9D60H-j8-5T1zJixTU-L2ydbn7LgnWpG1v53fyaKCyuuqx2MqfU80fI 開發與部署網站時需注意不要使用到 ERR_UNSAFE_PORT 不安全的埠號 | The Will Will Web]</ref> * {{Chrome}} [https://chromium.googlesource.com/chromium/src.git/+/refs/heads/master/net/base/port_util.cc#52 net/base/port_util.cc - chromium/src.git - Git at Google] * [https://fetch.spec.whatwg.org/#port-blocking Fetch Standard] 2.9. Port blocking === Is the port opened for external users? === Check the OS firewall or protected by antivirus software ** {{Linux}} *** [http://linux.die.net/man/8/iptables iptables]: (1) {{kbd | key = iptables -L}} to list all rules<ref>[http://wiki.centos.org/HowTos/Network/IPTables HowTos/Network/IPTables - CentOS Wiki]</ref> (2) rule with smaller line-number will override the rule with larger line-number<ref>[https://fedoraproject.org/wiki/How_to_edit_iptables_rules?rd=User_talk:Rforlot How to edit iptables rules - FedoraProject]</ref> *** [https://fedoraproject.org/wiki/FirewallD FirewallD] rules: (1) {{kbd | key = <nowiki>sudo firewall-cmd --get-default-zone</nowiki>}} return 'public' (2) {{kbd | key = <nowiki>sudo firewall-cmd --list-all --zone=public</nowiki>}}<ref>[https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7 How To Set Up a Firewall Using FirewallD on CentOS 7 | DigitalOcean]</ref> (3) Allow port with FirewallD *** [http://linux.die.net/man/8/semanage SELinux Policy Management]: (1) After installed {{kbd | key =policycoreutils-python}}<ref>[http://sharadchhetri.com/2014/10/07/semanage-command-found-centos-7-rhel-7/ semanage command not found on CentOS 7 and RHEL 7]</ref>, input {{kbd | key = <nowiki>semanage port -l</nowiki>}} to list open ports. (2) Allow port with semanage. ** {{Win}} [https://technet.microsoft.com/en-us/library/cc754274.aspx?f=255&MSPPError=-2147217396 Windows Firewall with Advanced Security] -> configure firewall rules ** protected by antivirus software? * connect to localhost ex: {{kbd | key= telnet 127.0.0.1 23}} where 23 is the port number where the service running ** [https://technet.microsoft.com/en-us/library/cc771275(v=ws.10).aspx Install Telnet Client] on {{Win}} ** if the local service is web server, you can also try {{kbd | key = <nowiki>lynx http://127.0.0.1</nowiki>}} for {{Linux}} * double [[Testing#check_the_server.2Fservice_logs | check the server/service logs]] == Test connectivity from LAN to the server == WAN ○ -------> <span style="color:red">● LAN -------> ● server</span> Testing on LAN (local network, subnet scope): The different servers between LAN or with the same ip class (ex: 1.2.3.*) and may not have the firewall limit. [https://en.wikipedia.org/wiki/Private_network Private network] / Private IP address * Is the service alive? * Connect to the internal IP eg: {{kbd | key= telnet 172.18.0.1 23}} (1) IP start with 172.18... is [http://www.itcom.itd.umich.edu/backbone/umnet/privateIP.html Private IP Network Numbers] (2) where 23 is the port number where the service running * If the local service is web server, you can also try to connect the internal IP e.g. {{kbd | key = <nowiki>lynx http://172.18.0.1</nowiki>}} for {{Linux}} * Double [[Testing#check_the_server.2Fservice_logs | check the server/service logs]] * Is the internal IP correct? == Test connectivity from WAN to the remote server == <span style="color:red">WAN ● -------> ● LAN -------> ● server</span> We met the trouble on WAN (wide area network). If we do no have the administrative permission, the tests we can do as follows: * [http://downforeveryoneorjustme.com/ Down for everyone or just me?] more on [[Web_Ping#同時從世界各處測試網站連線 | Web Ping]] * Switch to different ISP? Is hardware firewall enabled? * Is gateway alive? * Is DNS alive? * Is the external IP correct? ** If the firewall rule is IP specified, verify the IP if correct from [http://whatismyipaddress.com/ What Is My IP Address?] or web access log. ** Query the [http://ipinfo.io/ IP Address Details - ipinfo.io]. e.g. Input the command {{kbd | key = <nowiki>curl ipinfo.io/ip</nowiki>}}<ref>[https://askubuntu.com/questions/95910/command-for-determining-my-public-ip#comment1318649_95910 networking - Command for determining my public IP? - Ask Ubuntu]</ref> for {{Mac}} & {{Linux}} * Is the port was opened for external users? [http://www.portchecktool.com/ Open Port Check Tool - Port Forwarding Port Check Tool] * Is institutional/ISP firewall enabled? Contact your MIS. ([https://en.wikipedia.org/wiki/Management_information_system Management information system]) of your company or ISP? other issue: * bandwidth cost too much by certain users * exceed the request limit of (hardware) firewall * the external connection of updated Windows was down until reboot {{Win}} * Amazon EC2 security group * refresh browser cache: [http://refreshyourcache.com/en/cache/ Refresh your cache - When hitting F5 just isn't enough!] == Tools == # {{Gd}} [http://www.nirsoft.net/utils/cports.html CurrPorts: Monitoring TCP/IP network connections on Windows] # [http://portforward.com/help/portcheck.htm PFPortCheck Program]: check TCP/UDP port from localhost(where you installed the program) to portforward.com # [http://technet.microsoft.com/en-us/sysinternals/bb897437 TCPView for Windows] # [http://check-host.net/ Check server: Check host - online website monitoring, Check IP] "checks the possibility of a TCP connection to host's specified port from different locations around the world." quoted from website. {{access | date=2015-08-02}} == 相關文章 == * [https://errerrors.blogspot.com/2022/07/blog-post.html 怎樣排除網路連線逾時 (network connection timed out) 問題] == References == <references /> {{Template:Troubleshooting}} [[Category:Software]] [[Category:Programming]] [[Category:Web_Dev]] [[Category:MySQL]] [[Category:Linux]] [[Category:Testing]]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Access
(
view source
) (protected)
Template:Chrome
(
edit
)
Template:Gd
(
edit
)
Template:Kbd
(
edit
)
Template:Kbd plus
(
edit
)
Template:LanguageSwitcher
(
edit
)
Template:Linux
(
edit
)
Template:Mac
(
edit
)
Template:Tips
(
edit
)
Template:Troubleshooting
(
edit
)
Template:Win
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information