服务器端cURL调用公网IP失败求助:本地正常但连接超时
Got it, let's figure out why your connection to 95.97.124.124:23 is timing out on your server but working perfectly locally. Here’s a step-by-step breakdown of the most likely issues and fixes:
1. Check your server’s firewall/security group rules
Port 23 is the default Telnet port, and many hosting providers block outgoing traffic to well-known "high-risk" ports like this by default.
- If you’re on a Linux server, run these commands to check your local firewall:
- For UFW:
ufw status - For firewalld:
firewall-cmd --list-all
Make sure there’s an outbound rule allowing traffic to port 23 (or specifically to 95.97.124.124:23).
- For UFW:
- If you’re using a cloud provider (AWS, GCP, Azure), don’t forget to check the security group attached to your server instance—outbound rules need to explicitly permit connections to that IP and port.
2. Test the connection directly from your server
Isolate whether this is a network issue or a code issue by running a raw cURL command on your server via SSH:
curl -v telnet://95.97.124.124:23
- If this also times out, the problem is definitely network-related (not your code).
- If this works, then the issue lies in how you’ve adapted the Postman code for your server environment.
3. Check if your server’s ISP blocks port 23
Some ISPs restrict outgoing traffic to port 23 because Telnet is unencrypted and often associated with security risks.
- Reach out to your hosting provider to confirm if port 23 is blocked for outbound connections.
- If possible, test connecting to a different port on the same target IP to rule out ISP restrictions.
4. Audit your Postman-derived code for misconfigurations
When copying code from Postman, it’s easy to miss local-specific settings that don’t translate to a server environment. Look for these common pitfalls:
- Did you accidentally leave a local proxy configured in your code? Postman sometimes auto-injects proxy settings that only work on your machine.
- Is the
CURLOPT_CONNECTTIMEOUTvalue set too low? Try increasing it to 15 or 30 seconds to rule out slow network latency. - Double-check that you’re using the correct protocol—since port 23 is Telnet, make sure your cURL code isn’t trying to use HTTP/S by mistake.
- If you’re still stuck, share a snippet of your cURL code—small oversights like missing
CURLOPT_PORTor incorrect target formatting can cause timeouts.
5. Verify the target server allows connections from your server’s IP
It’s possible the target IP’s port 23 is whitelisted only for certain IP ranges (like your local network). Use nmap on your server to check if the port is accessible:
nmap -p 23 95.97.124.124
- If the result shows "filtered", that means traffic is being blocked by the target server’s firewall or a network router between you and them.
内容的提问来源于stack exchange,提问作者Stan van Heertum

