1. 开启 telnet 客户端
2. ping 自己的服务
ping 192.168.xxx.xxx
3. curl 检查自己的服务是否可用
curl http://localhost:3000
4. 对外暴露防火墙端口
5. 用 Windows 自带的 Test-NetConnection 测试端口连通
在 Windows PowerShell(Win+X,选择 Windows PowerShell )(注意不是 cmd),执行:
Test-NetConnection -ComputerName 192.168.xxx.xxx -Port 3000
如果显示 TcpTestSucceeded : True,说明端口可达。
如果显示 TcpTestSucceeded : False,说明连接失败。
6. 检测服务是否监听所有IP网卡
执行如下命令:
netstat -ano | findstr 3000
返回,表示只监听了本地回环地址
TCP 192.168.xxx.xxx:49718 103.212.xxx.xxx:3000 ESTABLISHED 2452
TCP [::1]:3000 [::]:0 LISTENING 14748
TCP [::1]:3000 [::1]:63834 TIME_WAIT 0
返回 0.0.0.0:3000 表示监听了所有网卡
TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 17936
7. 配置自己的服务监听所有IP网卡
Vue 服务,进行如下配置:
export default defineConfig({
plugins: [vue()],
server: {
host: '0.0.0.0', // 监听所有网卡,允许局域网访问
port: 3000, // 端口号
},
})
SpringBoot 服务,进行如下配置:
server.address=0.0.0.0 // 监听所有网卡,允许局域网访问
server.port=3000 // 端口号
Node 服务,进行如下配置:
const PORT = 3000 // 端口号
const HOST = '0.0.0.0' // 监听所有接口
app.listen(PORT, HOST, () => {
console.log(`Server running at http://${HOST}:${PORT}`)
})
8. 测试 telnet 是否正常
正常进入