1. curl

curl:该命令可视为不带参数的GET请求。

  • 命令格式
1
curl 服务地址
  • 操作示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@VM-0-9-centos tmp]# curl http://localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@VM-0-9-centos tmp]#

1
2
[root@VM-0-9-centos tmp]# curl http://localhost:8080
curl: (7) Failed connect to localhost:8080; Connection refused

2. netstat

netstat :监听端口状态

  • 命令格式
1
netstat 参数 | grep 端口号
  • 参数说明

-a:显示所有socket

-l:显示所有处于监听中的端口

-n:显示本地的IP地址

-p:显示pid及进程名称

-t:只显示tcp端口

-u:只显示udp端口

  • 操作示例

netstat -ltnp:查询所有处于监听状态的tcp端口

1
2
3
4
5
6
[root@VM-0-9-centos tmp]# netstat -ltnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3781/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1457/sshd
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 1455/python

netstat -anp | grep 80:查询所有处于监听状态的tcp端口

1
2
3
4
5
6
7
8
9
10
11
[root@VM-0-9-centos tmp]# netstat -anp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3781/nginx: master
tcp 0 0 10.0.0.9:42842 169.254.0.55:8080 TIME_WAIT -
tcp 0 0 10.0.0.9:80 170.64.161.204:38658 TIME_WAIT -
tcp 0 0 10.0.0.9:35380 169.254.0.55:5574 ESTABLISHED 5133/YDService
tcp 0 0 10.0.0.9:80 170.64.161.204:38694 TIME_WAIT -
tcp 0 0 10.0.0.9:80 170.64.161.204:38660 TIME_WAIT -
udp6 0 0 fe80::5054:ff:fead::123 :::* 657/ntpd
unix 2 [ ACC ] STREAM LISTENING 8005 1/systemd /run/systemd/journal/stdout
unix 5 [ ] DGRAM 8008 1/systemd /run/systemd/journal/socket
unix 12 [ ] DGRAM 8010 1/systemd /dev/log

3. telnet

telnet:用来探测指定 ip 是否开放指定端口。

在 Linux 环境下 Telnet 是需要安装的。 安装命令:yum install telnet

  • 命令格式
1
telnet IP 端口
  • 操作示例
1
2
3
4
[root@VM-0-9-centos tmp]# telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
1
2
3
[root@VM-0-9-centos tmp]# telnet 127.0.0.1 8080
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused