Editing
Test connectivity for the web service
(section)
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!
== Test connectivity for the local web service == WAN ○ -------> ○ LAN -------> <span style="color:red">● server</span> {{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 a port was occupied by other process? === Check the port if used by other protocol * [https://www.speedguide.net/ports.php SG TCP/IP Ports Database] * [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]] * {{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/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>}} ** [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] Example output of netstat command <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> * {{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? === 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]]
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)
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