# Static IP for Railway

Source: https://prontaro.com/docs/integrations/railway/

Share one fixed outbound IPv4 across multiple Railway services, CI runners, and your local machine — on any Railway plan.

Railway services exit from shared rotating addresses by default, while Railway’s native static IPs require the Pro tier and stay locked to the platform. Prontaro routes selected traffic through an HTTP/SOCKS5 proxy, a Relay URL, or `prontaro forward`, depending on whether you are calling REST APIs or connecting to an external database.

## Which method to choose

| Destination | Prontaro method | Best for |
| --- | --- | --- |
| **Partner REST/GraphQL APIs** | HTTPS proxy (`PRONTARO_PROXY_URL`) | End-to-end TLS and mTLS via HTTP CONNECT; works in Node.js, Python, Go, PHP, Ruby |
| **Single-host REST API without proxy code** | Relay URL (`PRONTARO_RELAY_URL`) | Swap the base URL in built-in `fetch`; no proxy dependencies |
| **External databases (MongoDB Atlas, Postgres, MySQL)** | SOCKS5 (`socks5h://`) or `prontaro forward` | Forwards database TCP connections from your dedicated IP |

A Relay URL decrypts TLS on the Prontaro server and opens a new HTTPS connection to the target API. Use HTTPS proxy when a partner requires end-to-end TLS or mTLS — see [Relay URLs](https://prontaro.com/docs/outbound/relay.md).

## Prerequisites

- A Prontaro account on Dedicated or Pro ([plans](https://prontaro.com/docs/billing/plans.md)). Open [my.prontaro.com/ips](https://my.prontaro.com/ips), pick a location near your Railway region, and click **Add IP**.
- A Railway project and service.
- You do not need `prontaro CLI` for HTTP proxy, SOCKS5, or Relay URLs — create credentials directly in the dashboard. The CLI is only needed inside your container for `prontaro forward`.

## Step 1. Create credentials and allowlist your IP

Add your dedicated IPv4 (`/32`) to the partner API or database allowlist, then create dedicated credentials for your Railway service in the dashboard.

1. Open **IP addresses** in [my.prontaro.com](https://my.prontaro.com/ips), select your IP, and click **Create proxy credentials** (for example, `railway-api`).
2. Copy the `HTTPS` URL (`https://u_rail:s3cr3t@<entry>.prontaro.io:443`), or `SOCKS5` (`socks5h://...`) for external databases.
3. If you prefer a Relay URL for a single REST API, click **Add relay address** and enter `api.example.com`.

IP addresses Proxy credentials [Open in dashboard](https://my.prontaro.com/ips)

Leave the **To** destination list unrestricted until Step 5 so the `api.ipify.org` check in Step 4 works.

## Step 2. Add environment variables in Railway

Open your service in Railway and go to **Service → Variables**. If multiple services share settings, use **Project → Shared Variables** or paste them in **Raw Editor**.

**Service → Variables**

- `PRONTARO_PROXY_URL`: `https://u_rail:s3cr3t@<entry>.prontaro.io:443`
- `NO_PROXY`: `localhost,127.0.0.1,.railway.internal`

Click **Apply Changes** / **Deploy** so Railway redeploys the service with the new variables. If multiple services share one IP, create separate proxy credentials per service (`railway-worker`) so each can be scoped and revoked independently.

> **Do not proxy *.railway.internal**
>
> If you set global `HTTP_PROXY` / `HTTPS_PROXY` instead of configuring your HTTP client explicitly, always set `NO_PROXY=localhost,127.0.0.1,.railway.internal`. Otherwise traffic to Railway-hosted Postgres, Redis, and internal services hits the external proxy and fails.

## Step 3. Route requests through your static IP

### HTTPS API calls (Node.js with `undici`)

Install `undici` (`npm install undici`), create `ProxyAgent` once at process startup, and reuse it for every request:

```js
// src/partnerClient.mjs
import { fetch, ProxyAgent } from 'undici';

const proxyUrl = process.env.PRONTARO_PROXY_URL;
if (!proxyUrl) {
  throw new Error('PRONTARO_PROXY_URL is not set');
}

const agent = new ProxyAgent({
  uri: proxyUrl,
  connections: 20,
});

export async function getPartnerStatus() {
  const response = await fetch('https://api.example.com/v1/status', {
    dispatcher: agent,
    headers: {
      Authorization: `Bearer ${process.env.PARTNER_API_TOKEN}`,
    },
    signal: AbortSignal.timeout(15_000),
  });

  if (!response.ok) {
    throw new Error(`Partner API returned ${response.status}`);
  }
  return response.json();
}
```

The same proxy URL works in Python, Go, PHP, and Ruby — see [HTTP & SOCKS5 proxy](https://prontaro.com/docs/outbound/proxy.md).

### REST API via Relay URL

Store `PRONTARO_RELAY_URL` in Railway Variables and call built-in `fetch` with no proxy library:

```js
const response = await fetch(new URL('/v1/status', process.env.PRONTARO_RELAY_URL), {
  headers: { Authorization: `Bearer ${process.env.PARTNER_API_TOKEN}` },
  signal: AbortSignal.timeout(15_000),
});
```

### External databases: SOCKS5 and `prontaro forward`

- **Driver with native SOCKS5:** store the `socks5h://` URL in `PRONTARO_SOCKS_URL` and pass it to the driver. See the [MongoDB Atlas guide](https://prontaro.com/docs/integrations/mongodb-atlas.md) for a complete example.
- **Drivers without SOCKS5:** create a CLI token (**CLI → New token**), save it in Railway Variables as `PRONTARO_KEY` (CLI reads it without `prontaro login`), and start `prontaro forward` before your app:

```sh
#!/bin/sh
# start.sh — container entrypoint (with prontaro installed in your Dockerfile)
set -e
prontaro forward 15432 db.example.com:5432 --ip 203.0.113.10 --no-input &
FWD_PID=$!

# Wait for the local port before starting the app
for i in $(seq 1 30); do
  nc -z 127.0.0.1 15432 && break
  kill -0 "$FWD_PID" 2>/dev/null || break
  sleep 0.5
done
nc -z 127.0.0.1 15432 || exit 1

exec node server.mjs
```

Your app connects to `127.0.0.1:15432`, and outbound traffic leaves from your dedicated Prontaro IPv4. With `--no-input`, startup refusals (such as an unpaid or blocked account) exit immediately with a non-zero code instead of waiting; the entrypoint exits `1`, and Railway restarts the service according to its **Restart Policy** in **Service → Settings** (**On Failure** by default, up to 10 retries, or **Always** on paid plans). Once running, `prontaro forward` waits and recovers on its own.

## Step 4. Verify the outbound IP from Railway

Do not use `railway run curl ...` for network verification: `railway run` pulls variables and runs `curl` locally on your laptop, not inside your Railway container.

Verify directly inside the deployed container with `railway ssh`:

```
 railway ssh -- curl -fsS --proxy "$PRONTARO_PROXY_URL"
203.0.113.10
```

If your container image does not include `curl`, add a temporary `/egress-check` route in your app that calls `https://api.ipify.org` through your `agent`, hit it after deploy, and remove it once verified.

## Step 5. Lock down allowed targets (recommended)

Once verified, restrict your credentials to the required host and port:

1. Open **IP addresses → Proxy credentials** in [my.prontaro.com](https://my.prontaro.com/ips), select `railway-api`, and switch to **Access**.
2. Add `api.example.com:443` (or `*.mongodb.net:27017` for Atlas) under **To** and save.

IP addresses Proxy credentials Access [Open in dashboard](https://my.prontaro.com/ips)

## Railway notes and limits

- **Align regions.** Choose the Prontaro location in the dashboard closest to your Railway service region to minimize latency.
- **One IP across services.** Multiple Railway services can share one dedicated IPv4 as long as total open connections stay within your [plan limit](https://prontaro.com/docs/billing/limits.md).

## Common errors

| Error | Cause | Fix |
| --- | --- | --- |
| Internal Railway Postgres or Redis unreachable after setting `HTTPS_PROXY` | Global proxy intercepted `*.railway.internal`. | Add `.railway.internal` to `NO_PROXY`, or pass `PRONTARO_PROXY_URL` only to the external HTTP client. |
| Variables saved, but the app still sees old values | No fresh deployment ran after updating Variables. | Click **Apply Changes** / **Deploy** on the Railway service. |
| `ECONNREFUSED 127.0.0.1:15432` with `prontaro forward` | App started before the local port finished binding. | Wait for `nc -z 127.0.0.1 15432` in `start.sh` before `exec`. |

For `407`, `403`, or `PRONTARO_KEY` token errors, see [error codes](https://prontaro.com/docs/cli/errors.md) and [HTTP & SOCKS5 proxy](https://prontaro.com/docs/outbound/proxy.md).

## Next steps

- [Connect to MongoDB Atlas](https://prontaro.com/docs/integrations/mongodb-atlas.md) — reach MongoDB Atlas from a dedicated IPv4 over SOCKS5.
- [Local port forwarding (`prontaro forward`)](https://prontaro.com/docs/outbound/forward.md) — forward TCP connections for database drivers without SOCKS5 support.
- [HTTP & SOCKS5 proxy](https://prontaro.com/docs/outbound/proxy.md) — language examples and allowed destination rules.
- [Static IP for Render](https://prontaro.com/docs/integrations/render.md) — the same pattern for Render Web Services, Workers, and Cron Jobs.
- [Reliability, zero-downtime updates, and BGP failover](https://prontaro.com/docs/outbound/failover.md) — how your `/32` stays intact during server failover.
