Method 1: netstat
Install netstat
apt-get update apt-get install -y net-tools
netstat -tuln
-t
: Shows TCP connection.-u
: Shows UDP connection.-l
: Only the ports that monitor the status are displayed.-n
: Display address and port number in digital form.
Method 2: telnet
Install telnet
apt-get update apt-get install -y telnet
telnet localhost 8080
usetelnet
Sending HTTP requests is a great way to test and debug a web server. Here's how to passtelnet
Steps to send an HTTP request.
Connect to the server:usetelnet
Connect to the target server and port (usually port 80 for HTTP and port 443 for HTTPS, but HTTPS requires SSL, so it is usually not passedtelnet
to test).
telnet 80
Send HTTP request: After the connection is successful, you can manually enter an HTTP request. The basic format of HTTP requests is as follows:
GET / HTTP/1.1 Host:
Note that each request line needs a blank line after it to indicate the end of the request.
Examples are as follows:
root@9c2b177de1f5:/demo# telnet localhost 8080 Trying ::1... Connected to localhost. Escape character is '^]'. GET /hello HTTP/1.1 Host:localhost HTTP/1.1 200 OK Content-Type: text/plain; charset=utf-8 Date: Wed, 16 Oct 2024 07:19:36 GMT Content-Length: 11 OK service2
Method 3: curl
Install curl
apt-get update apt-get install -y curl
curl -I http://localhost:8080
If the service is running on that port, you should receive an HTTP response header.
Method 4: lsof
Install lsof
apt-get update apt-get install -y lsof
lsof
Commands can be used to view files opened in the current system and network ports used. First, you need to make sure that the container is installedlsof
。
root@9c2b177de1f5:/demo# lsof -i :8080 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME main 444 root 4u IPv6 182989 0t0 TCP *:http-alt (LISTEN) main 444 root 8u IPv6 182998 0t0 TCP 9c2b177de1f5:http-alt->172.17.0.1:37130 (ESTABLISHED) main 444 root 9u IPv6 195023 0t0 TCP 9c2b177de1f5:http-alt->172.17.0.1:40346 (ESTABLISHED)
This is the article about how to determine whether the specified port is enabled in Linux. For more related contents for determining whether the specified port is enabled, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!