Self-hosting: How to get multiple static IPs for your services using a single VPS

Why a Static IP Rocks:

VPS on your own turf:

  • Self-hosted web server: Host your own website or blog, showcasing your work and ideas to the world. Customize it to your liking and have complete control over its content and functionality.
  • Personal mail server: Break free from the limitations of email providers and manage your own domain. Enjoy greater control over privacy, security, and customization.
  • Development playground: Experiment with various web applications, databases, and other technologies without relying on external services. A perfect environment to learn and test new ideas.
  • Media server: Stream your music, movies, and other media content across various devices within your home network or even remotely.

Master of your emails:

  • Increased privacy: Avoid data collection and targeted advertising practices of major email providers. Maintain complete control over your emails and ensure their privacy.
  • Enhanced security: Implement stronger authentication measures and encryption protocols to protect your email communications from unauthorized access.
  • Customizable experience: Tailor your mail server to your specific needs and preferences. Configure custom domains, aliases, filters, and other features.
  • Reduced reliance on third-party services: Eliminate the need for external email providers, potentially leading to cost savings and greater independence.

Power Up with Cloudflare:

  • Improved website loading times: Cloudflare’s global network of caching servers delivers content closer to your visitors, significantly reducing loading times.
  • Enhanced security: Cloudflare protects your website from common web attacks like DDoS and brute force attempts, ensuring its stability and uptime.
  • Advanced traffic management: Cloudflare offers various features like load balancing and traffic routing to optimize your website’s performance and availability.
  • Customizable security rules: Fine-tune your website’s security settings with Cloudflare’s powerful rules engine, blocking unwanted traffic and protecting sensitive information.

Port Party:

  • Run multiple services simultaneously: Utilize different ports for web servers, game servers, communication software, and other applications, all operating concurrently on your machine.
  • Experiment with diverse technologies: Explore various applications and services that require specific ports, expanding your technical knowledge and capabilities.
  • Increased flexibility and control: Choose the ports you want to expose and configure them according to your specific needs and security considerations.
  • Greater potential for customization and automation: Develop customized scripts and tools that leverage specific ports for automated tasks and workflows.

Privacy Ninja:

  • Shield your home network: Avoid exposing your home network devices and their IP addresses to the public internet, enhancing your online privacy and security.
  • Reduce unwanted traffic: By hiding your home IP, you can minimize spam, phishing attempts, and other malicious activities targeting your network.
  • Maintain anonymity: Keep your online activities and personal information private by using a static IP that doesn’t directly link back to your home network.
  • Gain peace of mind: Enjoy the comfort of knowing your home network is secure and shielded from potential vulnerabilities associated with a public IP address.

The ISP Struggle: IPv4 Exhaustion

Unfortunately, some ISPs are stingy with those static IPs. They might even restrict the ports you can use (like for email) or make port forwarding a real pain (especially with those CG-NAT things). No problem, we have workarounds!


IPv6: The Potential Solution for Static IP Scarcity

The world of self-hosting faces a significant challenge: the limited availability of static IPv4 addresses. With the explosive growth of internet users and devices, the pool of these addresses is rapidly depleting, forcing many individuals to rely on dynamic IPs or complex workarounds. This is where IPv6 comes in, offering a potential solution to this growing problem.

Why IPv6 is the Answer:

  • Vast Address Space: IPv6 boasts a massive address space, offering 340 undecillion addresses compared to the mere 4 billion of its predecessor. This vast pool ensures sufficient addresses for every device on the planet, eliminating the need for static IP allocation.
  • Automatic Configuration: Unlike IPv4, which often requires manual configuration, IPv6 utilizes a stateless address autoconfiguration (SLAAC) mechanism. Devices automatically generate their own IPv6 addresses, simplifying network setup and maintenance.
  • Enhanced Security: IPv6 incorporates various security features, such as built-in IPsec support, offering a more robust framework for protecting devices and data on the network.
  • Improved Routing Efficiency: IPv6 utilizes a hierarchical addressing scheme that optimizes routing efficiency, leading to improved network performance and reliability.

Workaround #1: Dynamic DNS (Effortless! )

Many routers have this built-in feature that keeps your DNS records in sync with your ever-changing public IP. Pretty cool, right?

Pros:

  • Easy-peasy, no effort needed.
  • UPnP makes exposing services a breeze.

Cons:

  • Not a true static IP solution.
  • Your home IP is exposed.
  • Port forwarding on your router is required.
  • ISP restrictions might still apply.

Workaround #2: Tunneling Services (Easy Setup! )

Cloud services like Cloudflare and Ngrok can create tunnels to your local machine, making your services accessible from the internet. They even give you a fancy URL or CNAME record to access them.

Pros:

  • Quick and simple to set up.
  • No need for a domain or VPS.

Cons:

  • Limited customization and protocol support.
  • Costly and restricted by SaaS limitations.
  • One URL per tunnel, not very flexible.
  • Not ideal for mail servers or specific needs.
  • Still no static IP.

Workaround #3: VPS – SSH Port Forwarding (Quick & Dirty! ⚡️)

Got a VPS with a public IP? Use SSH port forwarding to create a tunnel between your local machine and the VPS. This is great for short-term testing, but not ideal for long-term use due to performance limitations of SSH over TCP. Plus, getting UDP traffic to work can be tricky.

Pros:

  • No additional setup needed.

Cons:

  • Requires running the SSH tunnel continuously.
  • Performance suffers due to TCP over TCP.
  • UDP traffic management is a hassle.

Workaround #4: VPS – SSHesque Tools (Similar to #3, but… ️)

Tools like sshuttle offer improvements over basic SSH port forwarding.

Pros:

  • No additional setup needed.

Cons:

  • Only supports TCP traffic.
  • Performance might be impacted (as it’s often Python-based).

Workaround #5: VPS – VPN Forwarding (Advanced & Powerful! ‍♂️)

Connect your local machine to your VPS via a VPN service (Tailscale, ZeroTier, etc.) or self-hosted options (SoftEther, WireGuard, etc.). This allows you to route all traffic through your VPS, including any protocol and port. Solutions like Mistborn for WireGuard and Pritunl for OpenVPN make it even easier.

Pros:

  • Advanced mesh networking and fine-grained control.
  • All your traffic goes through one exit (both upload and download).
  • Route all IP traffic to your local server.

Cons:

  • Complex setup requiring networking knowledge (iptables magic).
  • May need to adjust MTUs with some providers.

Workaround #6: Self-Hosted Tunnels (Customizable & Fast! ️)

This combines elements of workarounds #3 and #4. Set up a client-server model on your VPS and create tunnels for specific ports. Popular options include Go-based FRP and Rust-based Rathole. Unlike cloud-based solutions, you have complete control over the server, avoiding endpoint restrictions.

Pros:

  • Moderate initial setup, then smooth sailing.
  • Highly customizable and fast.

Cons:

  • Requires configuring both client and server settings.
  • Each port needs to be manually mapped.

My Choice:

I went with option #6 using Rathole. While option #5 was tempting, the complexity of iptables NAT forwarding with multiple IPs on the same interface was too much of a headache.