Blog / Others/ Server Security Guide: How to Hide Your Real IP and Prevent Network Attacks

Server Security Guide: How to Hide Your Real IP and Prevent Network Attacks

服务器安全指南:如何有效隐藏真实 IP 并防止网络攻击

Introduction

Exposing your server's real IP address on the internet makes it directly vulnerable to network scanning, DDoS attacks, and targeted intrusions. Hiding the real IP is a fundamental measure in server security. This guide outlines several effective methods to protect your server's true IP address.

1. Bind Services to Localhost

Configure your web service (e.g., Apache, Nginx) to listen only on the local loopback address (127.0.0.1), not on the public IP or 0.0.0.0. This prevents direct external access, forcing all traffic through a front-end reverse proxy like a CDN or Nginx proxy.

Apache Configuration

Edit /etc/apache2/ports.conf or the relevant configuration file:

Listen 127.0.0.1:80

Nginx Configuration

Edit the server block in /etc/nginx/nginx.conf or your site configuration:

listen 127.0.0.1:80;

2. Disable Directory Listing

Prevent attackers from discovering your website structure and sensitive files through directory traversal.

Apache Configuration

<Directory /var/www/>
    Options -Indexes
</Directory>

Nginx Configuration

location / {
    autoindex off;
}

3. Minimize Server Fingerprinting

Reduce information leakage that reveals software versions and operating system details.

Disable Apache Server Info & Status Pages

Apache may have /server-info and /server-status pages enabled by default. Comment out or remove the following module lines in httpd.conf:

# LoadModule info_module modules/mod_info.so
# LoadModule status_module modules/mod_status.so

Also ensure no <Location> directives exist for these paths.

Remove Server Signature Headers

Apache (in httpd.conf or security.conf):

ServerSignature Off
ServerTokens Prod

Nginx (in the http block of nginx.conf):

server_tokens off;

Disable Detailed Application Error Reporting

In production, turn off verbose error display for your application backend (PHP, Node.js, Python, etc.) to avoid leaking server paths or IPs in stack traces. For PHP:

display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
log_errors = On

4. Patch Vulnerabilities and Maintain Updates

  • Keep Software Updated: Regularly update the OS, web server software (Apache/Nginx), and all applications (e.g., WordPress, databases) to their latest secure versions.
  • Security Audits: Periodically review code for vulnerabilities like SQL injection, XSS, and file inclusion.
  • Principle of Least Privilege: Run services under non-root users and enforce strict file and directory permissions.
  • Service Isolation: Deploy databases, caches, and other services in separate containers or on an internal network, isolated from the web server.

5. Avoid Direct Server Mail Delivery

Prevent web applications from using the server's local mail service (e.g., sendmail/postfix) to send emails (like user registration confirmations), as email headers can expose the server's real IP. Use a third-party SMTP service (e.g., SendGrid, Mailgun) instead.

6. Use a CDN and Enforce SSL

This is the most effective and common method for hiding your server's real IP.

  • Use a Content Delivery Network (CDN): Point your domain's DNS to a CDN provider (e.g., Cloudflare) using a CNAME record. All user requests first hit the CDN edge, which then forwards them to your origin server. Attackers only see the CDN's IP addresses.
  • Protect the Origin Server: Configure your server firewall or security group to allow traffic only from your CDN provider's IP ranges on ports 80 and 443, blocking all other sources.
  • Enforce SSL/TLS Encryption: Use HTTPS for all connections, both between users and the CDN and between the CDN and your origin server, to prevent eavesdropping and tampering.

Important Note: Hiding your IP is one layer of a defense-in-depth strategy, not absolute security. Combine it with firewall rules (iptables, cloud security groups), a Web Application Firewall (WAF), Intrusion Detection Systems (IDS), and regular security scans to build a comprehensive protection system.

Post a Comment

Your email will not be published. Required fields are marked with *.