Test connectivity for the web service: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
 
(35 intermediate revisions by the same user not shown)
Line 1: Line 1:
find the problem occurred: (1) local service at the server (localhost) (2) from LAN to server (3) from WAN to server
Find the problem occurred: (1) local service at the server (localhost) (2) from LAN to server (3) from WAN to server


{{LanguageSwitcher | content = [[Test connectivity for the web service | EN]], [[網路服務連線測試 | 漢字]] }}


== Connecting from the local machine to web service at the same server ==
=== How to connect to the web service ===
 
If the service is the web server:
* (1) Open the browser, (2) Type the address: {{kbd | key = <nowiki>http://127.0.0.1</nowiki> }} or {{kbd | key =<nowiki>http://the.domain</nowiki>}}
 
* Linux lynx command:
*# (optional if lynx was not installed) {{kbd | key = <nowiki>yum install lynx</nowiki>}} for CentOS / {{kbd | key = <nowiki>sudo apt-get install lynx</nowiki>}} for Ubuntu<ref>[http://www.addictivetips.com/ubuntu-linux-tips/install-and-use-lynx-on-ubuntu/ Install and Use Lynx Browser on Ubuntu]</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 Users Guide v2.8.7]</ref> for {{Linux}}
 
* telnet command
*# {{kbd | key = telnet 127.0.0.1 <PORT>}} e.g. {{kbd | key = telnet 127.0.0.1 80}} or {{kbd | key = telnet the.domain 80}}
*# (after telnet-ed the web 80 port, key in) {{kbd_plus | key1 = get | key2 = SPACE}}<ref>[http://www.simplescripts.de/http-check-port-80-telnet-command.htm HTTP Check Port 80 with the Telnet Command]</ref>
 
* curl<ref>[https://curl.se/docs/manpage.html curl - How To Use]</ref>: {{kbd | key = <nowiki>curl -vL http://IP:Port</nowiki>}}
** (optional if curl command was not installed) [https://help.ubidots.com/en/articles/2165289-learn-how-to-install-run-curl-on-windows-macosx-linux Learn how to install & run cURL on Windows/MacOSX/Linux | Ubidots Help Center]
** commands e.g.
*** (1) Write output to <file> instead of stdout using {{kbd | key = <nowiki>curl -voL https://www.google.com</nowiki>}}
*** (2) Write output to stdout using {{kbd | key = <nowiki>curl -vL https://www.google.com</nowiki>}} or {{kbd | key = <nowiki>curl -voL /dev/null https://www.google.com</nowiki>}}
*** (3) Write output to <file> with the remote file name using {{kbd | key = <nowiki>curl -vOL https://www.google.com/index.html</nowiki>}}
** If failed. It will show the message: "failed: Connection refused"
 
* Linux [https://www.gnu.org/software/wget/ wget] software e.g. {{kbd | key = <nowiki>wget https://www.google.com</nowiki>}}
 
* use the third-party website monitoring the services: [[Web Ping]]
 
If the service is not the web server, use telnet instead
# (optional) [https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc771275(v=ws.10) Install Telnet Client | Microsoft Docs] on {{Win}}. [https://medium.com/@blackSource/bring-telnet-back-on-macos-high-sierra-11de98de1544 Bring telnet back on macOS high Sierra – Ayuth Mangmesap (blackSource) – Medium] on {{Mac}}
# {{kbd | key = telnet 127.0.0.1 <PORT>}} If failed to connect the web service. It will show the message: "telnet: Unable to connect to remote host: Connection refused"
 
Using alternative web services if the Python or Node.js was installed
 
* (for python 3.x) {{kbd | key=<nowiki>python -m http.server [port]</nowiki>}} (default port: 8000)<ref>[https://docs.python.org/3.8/library/http.server.html?highlight=http%20server#module-http.server http.server — HTTP servers — Python 3.8.1 documentation]</ref>
* (for Node.js) {{kbd | key=<nowiki>npx http-server [-p port]</nowiki>}} (default port: 8080)<ref>[https://github.com/http-party/http-server http-server: a simple static HTTP server]</ref>
 
== Test connectivity for the local web service ==
WAN &#9675; -------&gt; &#9675; LAN -------&gt; <span style="color:red">&#9679; server</span>
WAN &#9675; -------&gt; &#9675; LAN -------&gt; <span style="color:red">&#9679; server</span>


Testing on localhost if you have the administrative permission to manage the server.
{{Tips}} If you has administrative permission to log into the server via SSH or Remote desktop service.
 
=== Check if your computer/server Is being assigned the IP Address ===
 
* {{Linux}}: (1) Check the IP Address. {{kbd | key = ifconfig}}. (2) Re-assign the IP Address and restart the networking service. {{kbd | key = service network restart}} for CentOS<ref>[http://askubuntu.com/questions/230698/how-to-restart-the-networking-service How to restart the networking service? - Ask Ubuntu]</ref>
* {{Win}}: Check the IP Address. {{kbd | key = ifconfig/all}}
* More on [[Network problem]]
 
=== Check if web service has started successfully? ===
* Apache {{kbd | key = /etc/init.d/httpd status}} on CentOS7 <ref>[https://www.e2enetworks.com/help/knowledge-base/how-to-check-running-status-of-lamp-stack/ How to check running status of LAMP stack | E2E Networks Knowledgebase]</ref>
* nginx {{kbd | key = sudo service nginx status}} on CentOS7
* Docker container {{kbd | key = docker ps}} to check if the container is running & expose the port<ref>[https://docs.docker.com/engine/reference/commandline/ps/ docker ps | Docker Documentation]</ref>
 
=== Check if MySQL has started successfully? ===
==== Using lsof command ====
* {{kbd | key = lsof -i:3306}} on {{Mac}} or {{Linux}}
 
The command lsof -i:3306 is used in Unix-like operating systems to list open files and the processes that opened them. Let's break down the command:
 
lsof: This stands for "List Open Files". It's a command-line utility that displays information about files opened by processes. In Unix and Linux, everything is treated as a file (including hardware devices, sockets, and directories), so lsof is a powerful tool for system administrators to monitor and troubleshoot system behavior.
 
-i: This option tells lsof to show only network files. In Unix and Linux, network connections are treated as files. The -i option can be used to filter connections based on the Internet address or network protocol.
 
:3306: This specifies the port number. Port 3306 is commonly used by MySQL, a popular database management system. By including :3306, you are asking lsof to list all network files (which includes socket connections) that are associated with port 3306.
 
Example output: localhost:mysql (LISTEN) means the MySQL has started successfully
<pre>
COMMAND    PID      USER  FD  TYPE            DEVICE SIZE/OFF NODE NAME
mysqld    93034 account  29u  IPv4 0xxxx      0t0  TCP localhost:mysql (LISTEN)
</pre>
 
==== Using ps command ====
* {{kbd | key = <nowiki>ps aux | grep mysql</nowiki>}} on {{Mac}}
 
Example output if MySQL has started successfully:
<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>


Example output if MySQL has NOT started successfully:
<pre>
ACCOUNT        12349  0.0  0.0 408645328  1648 s011  S+    2:14下午  0:00.00 grep mysql
</pre>


=== Check if your computer/server Is being assigned the IP Address ===
=== Check if a port was occupied by other process? ===
** {{Linux}}: (1) Check the IP Address. {{kbd | key = ifconfig}}. (2) Re-assign the IP Address and restart the networking service. {{kbd | key = service network restart}} for CentOS<ref>[http://askubuntu.com/questions/230698/how-to-restart-the-networking-service How to restart the networking service? - Ask Ubuntu]</ref>
Check the port if used by other protocol
** {{Win}}: Check the IP Address. {{kbd | key = ifconfig/all}}
* [https://www.speedguide.net/ports.php SG TCP/IP Ports Database]
** More on [[Network problem]]
* [https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers List of TCP and UDP port numbers - Wikipedia]
 
[[Find process running on port]]


=== Is the service alive or the port was occupied by other process? ===
* {{Linux}}  
** {{Linux}}  
** [http://linux.die.net/man/1/nmap nmap] "Network exploration tool and security / port scanner." e.g. {{kbd | key = <nowiki>nmap -p 80,443 ip</nowiki>}}
*** [http://linux.die.net/man/1/nmap nmap] "Network exploration tool and security / port scanner." e.g. {{kbd | key = <nowiki>nmap -p 80,443 ip</nowiki>}}
** [http://linux.die.net/man/8/ss ss] "utility to investigate sockets" e.g. {{kbd | key = <nowiki>ss -tnlp | grep 80</nowiki>}} or using OR operator<ref>[http://www.thegeekstuff.com/2011/10/grep-or-and-not-operators/ 7 Linux Grep OR, Grep AND, Grep NOT Operator Examples]</ref> {{kbd | key = <nowiki>ss -tnlp | grep '80\|443'</nowiki>}}
*** [http://linux.die.net/man/8/ss ss] "utility to investigate sockets" e.g. {{kbd | key = <nowiki>ss -tnlp | grep 80</nowiki>}} or using OR operator<ref>[http://www.thegeekstuff.com/2011/10/grep-or-and-not-operators/ 7 Linux Grep OR, Grep AND, Grep NOT Operator Examples]</ref> {{kbd | key = <nowiki>ss -tnlp | grep '80\|443'</nowiki>}}
** [http://linuxcommand.org/man_pages/ps1.html ps] List the current processes. Input {{kbd | key = <nowiki>ps -aux | grep "PORT_NUMBER"</nowiki>}} e.g. {{kbd | key = <nowiki>ps -aux | grep 443</nowiki>}}
*** [http://linuxcommand.org/man_pages/ps1.html ps] List the current processes. Input {{kbd | key = <nowiki>ps -aux | grep "PORT_NUMBER"</nowiki>}} e.g. {{kbd | key = <nowiki>ps -aux | grep 443</nowiki>}}
** [https://docs.oracle.com/cd/E19504-01/802-5753/6i9g71m3i/index.html netstat Command] {{kbd | key=<nowiki>netstat -tulpn | grep LISTEN</nowiki>}} e.g.  
*** [https://docs.oracle.com/cd/E19504-01/802-5753/6i9g71m3i/index.html netstat Command] {{kbd | key=<nowiki>netstat -tulpn | grep LISTEN</nowiki>}} e.g.  
** [https://docs.docker.com/engine/reference/commandline/port/ docker port | Docker Documentation]
** {{Win}} Using the software [http://www.nirsoft.net/utils/cports.html CurrPorts] to check the process and port. e.g. Apache will not running if the 80 port was occupied by skype<ref>[http://stackoverflow.com/questions/4705005/how-to-solve-wamp-and-skype-conflict-on-windows-7 How to solve WAMP and Skype conflict on Windows 7? - Stack Overflow]</ref>.


Example output of netstat command
<pre>
<pre>
$ netstat -tulpn | grep LISTEN
$ netstat -tulpn | grep LISTEN
Line 28: Line 107:
// means the 80 port service is running
// means the 80 port service is running
</pre>
</pre>
* more on [[Find process running on port]]
 
* {{Win}}
** Using the software [http://www.nirsoft.net/utils/cports.html CurrPorts] to check the process and port. e.g. Apache will not running if the 80 port was occupied by skype<ref>[http://stackoverflow.com/questions/4705005/how-to-solve-wamp-and-skype-conflict-on-windows-7 How to solve WAMP and Skype conflict on Windows 7? - Stack Overflow]</ref>.
 
=== 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? ===
=== Is the port opened for external users? ===
Line 44: Line 131:
* double [[Testing#check_the_server.2Fservice_logs | check the server/service logs]]
* double [[Testing#check_the_server.2Fservice_logs | check the server/service logs]]


== Connecting from LAN to the server ==
== Test connectivity from LAN to the server ==
WAN &#9675; -------&gt; <span style="color:red">&#9679; LAN -------&gt; &#9679; server</span>
WAN &#9675; -------&gt; <span style="color:red">&#9679; LAN -------&gt; &#9679; server</span>


Testing on LAN (local network, subnet scope): The different servers between LAN or with the same ip class (ex: 1.2.3.*) may not have the firewall limit.
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?  
* Is the service alive?  
Line 55: Line 142:
* Is the internal IP correct?
* Is the internal IP correct?


== Connecting from WAN to the server ==
== Test connectivity from WAN to the remote server ==
<span style="color:red">WAN &#9679; -------&gt; &#9679; LAN -------&gt; &#9679; server</span>
<span style="color:red">WAN &#9679; -------&gt; &#9679; LAN -------&gt; &#9679; server</span>


Line 75: Line 162:
* Amazon EC2 security group
* Amazon EC2 security group
* refresh browser cache: [http://refreshyourcache.com/en/cache/ Refresh your cache - When hitting F5 just isn't enough!]
* 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}}
== Related articles ==
* [https://errerrors.blogspot.com/2022/07/blog-post.html 怎樣排除網路連線逾時 (network connection timed out) 問題]
== References ==
<references />
{{Template:Troubleshooting}}


[[Category:Software]]
[[Category:Software]]
Line 81: Line 183:
[[Category:MySQL]]
[[Category:MySQL]]
[[Category:Linux]]
[[Category:Linux]]
[[Category:Testing]]

Latest revision as of 17:41, 28 January 2025

Find the problem occurred: (1) local service at the server (localhost) (2) from LAN to server (3) from WAN to server

🌐 Switch language: EN, 漢字


How to connect to the web service[edit]

If the service is the web server:

  • (1) Open the browser, (2) Type the address: http://127.0.0.1 or http://the.domain
  • Linux lynx command:
    1. (optional if lynx was not installed) yum install lynx for CentOS / sudo apt-get install lynx for Ubuntu[1]
    2. lynx http://127.0.0.1 [2] for Linux Os linux.png
  • telnet command
    1. telnet 127.0.0.1 <PORT> e.g. telnet 127.0.0.1 80 or telnet the.domain 80
    2. (after telnet-ed the web 80 port, key in) get + SPACE[3]
  • curl[4]: curl -vL http://IP:Port
    • (optional if curl command was not installed) Learn how to install & run cURL on Windows/MacOSX/Linux | Ubidots Help Center
    • commands e.g.
      • (1) Write output to <file> instead of stdout using curl -voL https://www.google.com
      • (2) Write output to stdout using curl -vL https://www.google.com or curl -voL /dev/null https://www.google.com
      • (3) Write output to <file> with the remote file name using curl -vOL https://www.google.com/index.html
    • If failed. It will show the message: "failed: Connection refused"
  • Linux wget software e.g. wget https://www.google.com
  • use the third-party website monitoring the services: Web Ping

If the service is not the web server, use telnet instead

  1. (optional) Install Telnet Client | Microsoft Docs on Win Os windows.png . Bring telnet back on macOS high Sierra – Ayuth Mangmesap (blackSource) – Medium on macOS icon_os_mac.png
  2. telnet 127.0.0.1 <PORT> If failed to connect the web service. It will show the message: "telnet: Unable to connect to remote host: Connection refused"

Using alternative web services if the Python or Node.js was installed

  • (for python 3.x) python -m http.server [port] (default port: 8000)[5]
  • (for Node.js) npx http-server [-p port] (default port: 8080)[6]

Test connectivity for the local web service[edit]

WAN ○ -------> ○ LAN -------> ● server

Owl icon.jpg If you has administrative permission to log into the server via SSH or Remote desktop service.

Check if your computer/server Is being assigned the IP Address[edit]

  • Linux Os linux.png : (1) Check the IP Address. ifconfig. (2) Re-assign the IP Address and restart the networking service. service network restart for CentOS[7]
  • Win Os windows.png : Check the IP Address. ifconfig/all
  • More on Network problem

Check if web service has started successfully?[edit]

  • Apache /etc/init.d/httpd status on CentOS7 [8]
  • nginx sudo service nginx status on CentOS7
  • Docker container docker ps to check if the container is running & expose the port[9]

Check if MySQL has started successfully?[edit]

Using lsof command[edit]

  • lsof -i:3306 on macOS icon_os_mac.png or Linux Os linux.png

The command lsof -i:3306 is used in Unix-like operating systems to list open files and the processes that opened them. Let's break down the command:

lsof: This stands for "List Open Files". It's a command-line utility that displays information about files opened by processes. In Unix and Linux, everything is treated as a file (including hardware devices, sockets, and directories), so lsof is a powerful tool for system administrators to monitor and troubleshoot system behavior.

-i: This option tells lsof to show only network files. In Unix and Linux, network connections are treated as files. The -i option can be used to filter connections based on the Internet address or network protocol.

3306: This specifies the port number. Port 3306 is commonly used by MySQL, a popular database management system. By including :3306, you are asking lsof to list all network files (which includes socket connections) that are associated with port 3306.

Example output: localhost:mysql (LISTEN) means the MySQL has started successfully

COMMAND     PID      USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mysqld    93034 account   29u  IPv4 0xxxx      0t0  TCP localhost:mysql (LISTEN)

Using ps command[edit]

  • ps aux | grep mysql on macOS icon_os_mac.png

Example output if MySQL has started successfully:

_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

Example output if MySQL has NOT started successfully:

ACCOUNT        12349   0.0  0.0 408645328   1648 s011  S+    2:14下午   0:00.00 grep mysql

Check if a port was occupied by other process?[edit]

Check the port if used by other protocol

Find process running on port

  • Linux Os linux.png
    • nmap "Network exploration tool and security / port scanner." e.g. nmap -p 80,443 ip
    • ss "utility to investigate sockets" e.g. ss -tnlp | grep 80 or using OR operator[10] ss -tnlp | grep '80\|443'
    • ps List the current processes. Input ps -aux | grep "PORT_NUMBER" e.g. ps -aux | grep 443
    • netstat Command netstat -tulpn | grep LISTEN e.g.
    • docker port | Docker Documentation

Example output of netstat command

$ netstat -tulpn | grep LISTEN

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      - 

// means the 80 port service is running
  • Win Os windows.png
    • Using the software CurrPorts to check the process and port. e.g. Apache will not running if the 80 port was occupied by skype[11].

Check if a port is blocked by browser[edit]

Check if a port is blocked by browser[12]


Is the port opened for external users?[edit]

Check the OS firewall or protected by antivirus software

    • Linux Os linux.png
      • iptables: (1) iptables -L to list all rules[13] (2) rule with smaller line-number will override the rule with larger line-number[14]
      • FirewallD rules: (1) sudo firewall-cmd --get-default-zone return 'public' (2) sudo firewall-cmd --list-all --zone=public[15] (3) Allow port with FirewallD
      • SELinux Policy Management: (1) After installed policycoreutils-python[16], input semanage port -l to list open ports. (2) Allow port with semanage.
    • Win Os windows.png Windows Firewall with Advanced Security -> configure firewall rules
    • protected by antivirus software?
  • connect to localhost ex: telnet 127.0.0.1 23 where 23 is the port number where the service running
    • Install Telnet Client on Win Os windows.png
    • if the local service is web server, you can also try lynx http://127.0.0.1 for Linux Os linux.png
  • double check the server/service logs

Test connectivity from LAN to the server[edit]

WAN ○ -------> ● LAN -------> ● server

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. Private network / Private IP address

  • Is the service alive?
  • Connect to the internal IP eg: telnet 172.18.0.1 23 (1) IP start with 172.18... is 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. lynx http://172.18.0.1 for Linux Os linux.png
  • Double check the server/service logs
  • Is the internal IP correct?

Test connectivity from WAN to the remote server[edit]

WAN ● -------> ● LAN -------> ● server

We met the trouble on WAN (wide area network). If we do no have the administrative permission, the tests we can do as follows:

other issue:

Tools[edit]

  1. Good.gif CurrPorts: Monitoring TCP/IP network connections on Windows
  2. PFPortCheck Program: check TCP/UDP port from localhost(where you installed the program) to portforward.com
  3. TCPView for Windows
  4. 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. [Last visited: 2015-08-02]

Related articles[edit]

References[edit]


Troubleshooting of ...

Template