Vast.ai port forwarding

Vast.ai port forwarding: make GPU host ports publicly reachable

Troubleshoot Vast.ai port forwarding, CGNAT, SSH timeouts, blocked ports, and public endpoints. Includes commands, tests, and NeedPorts setup examples.

Quick diagnosis checklist

  1. Confirm the service is listening locally.
  2. Confirm the service responds from the host itself.
  3. Check host firewall rules before changing router rules.
  4. Compare the host/router WAN address with the public IP seen by the internet.
  5. Test from a different network, not from the same LAN.
  6. If inbound traffic still times out, use a public forwarded endpoint instead of relying on upstream NAT.

Commands to run first

# What public IPv4 does the internet see?
curl -4 ifconfig.me

# What is listening locally?
ss -tulpen
sudo ss -tulpen

# Test a local web/API service
curl -v http://127.0.0.1:8080
curl -v http://127.0.0.1:8000/health

# Check common Linux firewalls
sudo ufw status verbose
sudo iptables -S
sudo nft list ruleset

Symptoms this guide solves

Vast.ai reports a port is closed even though the service is running.
SSH times out or works only locally.
An inference API, Docker dashboard, or web UI responds on localhost but not from the internet.
The router rule looks correct but the public test still fails.

Why this happens on GPU hosts

Vast.ai-style hosts often sit behind more than one layer of networking: Docker publish rules, host firewall rules, provider firewalls, router NAT, CGNAT, and sometimes shared datacenter or residential links. A service can be healthy locally while the public internet has no route to reach it.

Router port forwarding only helps when the router itself owns the public IP. If the upstream provider uses CGNAT or a locked firewall, packets never reach your router rule.

Test public reachability from outside

# TCP test from another machine or VPS
nc -vz your-public-host.example 30000

# HTTP/API test
curl -v http://your-public-host.example:30001/health

# SSH test using a public forwarded port
ssh -vvv -p 30000 [email protected]

Expose SSH with NeedPorts

After your NeedPorts account has an assigned endpoint and port range, map one public port to local SSH. YOUR_SETUP_TOKEN is shown after signup/trial checkout and binds the client to your assigned endpoint.

curl -fsSL https://api.needports.com/install | sudo bash -s YOUR_SETUP_TOKEN --accept-tos
sudo needports setup --dry-run
sudo needports use ssh 30000
sudo needports restart
ssh -p 30000 user@your-needports-endpoint

Security note: expose SSH intentionally. Prefer key-only auth, disable password login where appropriate, and keep a private fallback access path.

Expose a Docker API or dashboard

docker ps
ss -tulpen | grep 8080
curl -v http://127.0.0.1:8080
sudo needports expose custom --public-port 30001 --local-port 8080 --name "Inference API" --confirm --restart
curl -v http://your-needports-endpoint:30001/health

Common fixes by cause

FAQ

Why is my Vast.ai host online but not reachable?
The host may be able to make outbound connections while inbound traffic is blocked by CGNAT, upstream firewalling, Docker bind settings, or a local firewall.
Does Vast.ai always provide public inbound ports?
Not always. Your machine, ISP, datacenter, or rented network path may still prevent unsolicited inbound connections.
Can NeedPorts expose SSH for a Vast.ai host?
Yes, map an assigned public port to local SSH, then connect with ssh -p. Use SSH keys and avoid password-exposed root login.
Can I expose Docker services or APIs?
Yes. Expose the host port that Docker publishes locally, then test the public NeedPorts endpoint from outside.
Do I need router access?
No. NeedPorts uses an outbound tunnel, so it can work when router access or ISP port forwarding is unavailable.

Deep troubleshooting examples

Example 1: SSH works locally but public SSH times out

This usually means the SSH daemon is healthy but the public network path is blocked. Confirm the daemon first, then test the public path from outside the host.

# On the host
sudo ss -tulpen | grep ':22'
systemctl status ssh || systemctl status sshd

# From another machine, not the same LAN
nc -vz your-public-host.example 22
ssh -vvv [email protected]

If local SSH is listening but the outside test times out, changing SSH keys will not fix the network path. Use a public forwarded port or fix the upstream firewall/NAT.

Example 2: Docker publishes a port but renters cannot reach it

Docker port publishing creates a host listener; it does not guarantee public internet reachability. Check the published host port, then map that host port to an assigned NeedPorts public port.

docker ps --format 'table {{.Names}}	{{.Ports}}'
ss -tulpen | grep 8080
curl -v http://127.0.0.1:8080
sudo needports expose custom --public-port 30001 --local-port 8080 --name "Docker Web UI" --confirm --restart
curl -v http://your-needports-endpoint:30001

Example 3: API binds to 127.0.0.1

Binding to localhost is not always a problem if the NeedPorts client runs on the same host and forwards to 127.0.0.1. It is a problem if Docker, the tunnel client, or another network namespace cannot reach the service.

# Local process bind check
ss -tulpen | grep 8000
curl -v http://127.0.0.1:8000/health
curl -v http://$(hostname -I | awk '{print $1}'):8000/health

If only localhost works, expose from the same host or adjust the service bind address intentionally. Do not bind sensitive admin panels publicly unless they have strong authentication.

Before/after connection examples

Before NeedPorts

$ nc -vz public-ip 8000
nc: connect to public-ip port 8000 (tcp) failed: timed out

$ curl http://127.0.0.1:8000/health
ok

After public forwarding

$ nc -vz your-needports-endpoint 30001
Connection to your-needports-endpoint 30001 port [tcp/*] succeeded!

$ curl http://your-needports-endpoint:30001/health
ok

When NeedPorts is not the right fix

Ready for a stable public endpoint?

Start with a NeedPorts trial, map one service, and test the public port from another network before depending on it for production traffic.

Start a trialRead more guides