Port Forwarding and NAT on VPS: How to Configure

Port forwarding and NAT (Network Address Translation) allow traffic to be redirected from one port or IP address to another. This is essential if you host multiple services on a single VPS, want to access an internal machine, or use your server as a gateway. This guide explains how to configure these functions on Linux and Windows servers.

What Are Port Forwarding and NAT?

  • Port Forwarding — redirecting incoming traffic to another IP/port inside the network;
  • NAT — translating IP addresses and ports between external and internal networks;
  • Useful for isolation, proxying, tunneling, or exposing internal services to the internet.

Port Forwarding on Linux (via iptables)

Example: redirect external port 8080 to local port 80.

sudo iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80

To forward to another internal IP:

sudo iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to-destination 192.168.0.10:22
sudo iptables -A FORWARD -p tcp -d 192.168.0.10 --dport 22 -j ACCEPT

Enable IP forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward

Saving iptables Rules

On Debian/Ubuntu:

sudo apt install iptables-persistent
sudo netfilter-persistent save

NAT and Port Forwarding on Windows Server

1. Install the Remote Access role → NAT via Server Manager.
2. Launch Routing and Remote Access (RRAS).
3. Configure the network interface as NAT-enabled.
4. Add a Port Redirection rule to forward traffic to the target IP/port.

⚠ Ensure the firewall allows the connection and the port isn’t already in use.

Bit.Hosting Tips

  • Don’t expose unnecessary ports — it weakens security;
  • Test routing using tools like ping and traceroute;
  • Use a firewall (UFW, Windows Firewall) to control connections;
  • For complex setups, consider a proxy or VPN (e.g., WireGuard);
  • Monitor traffic on forwarded ports using tools like lsof or netstat.

← Back to Network section

If you're having trouble with NAT or port forwarding — contact Bit.Hosting support. We’ll help you set it up properly and securely. 🧩

← Network and DNS on VPS

Bit.Hosting

Compare plans

Pricing is calculated for the selected billing period.