# How to Change OpenClaw Default Port: Complete Guide

Change the OpenClaw gateway port from the default 18789. Fix port conflicts, set up reverse proxies, run multiple instances, and configure firewall rules.

## OpenClaw Default Port

OpenClaw runs on port 18789 by default. This port serves the Control UI, API, and channel ingress.

## Why Change the Port?

- Port 18789 is already used by another service
- Running multiple OpenClaw instances
- Hosting provider blocks the default port
- Using a reverse proxy (Nginx, Caddy)

## Three Ways to Change the Port

### Method 1: CLI Flag (Quick, temporary)
```
openclaw gateway --port 9000
```

### Method 2: Config File (Permanent)
Edit ~/.openclaw/openclaw.json:
```json
{
  "gateway": {
    "port": 9000
  }
}
```
Then: `openclaw gateway restart`

### Method 3: CLI Config Command (One-liner)
```
openclaw config set gateway.port 9000
openclaw gateway restart
```

## Fix "Port Already in Use"

Find what's using the port:
```
# Linux/macOS
lsof -i :18789

# Windows
netstat -ano | findstr 18789
```

Kill the process or change OpenClaw's port.

## Reverse Proxy (Nginx)

```nginx
server {
    listen 443 ssl;
    server_name openclaw.yourdomain.com;
    location / {
        proxy_pass http://127.0.0.1:18789;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
```

## Network Binding Options

| Bind Mode | Listens On | Use Case |
|-----------|-----------|----------|
| loopback | 127.0.0.1 | Local use, behind proxy |
| auto | Auto-detected | Most deployments |
| lan | LAN interface | Other devices on network |
| custom | Specific IP | Multi-NIC servers |
| tailnet | Tailscale | Secure remote access |

## Running Multiple Instances

```
openclaw gateway --port 18789  # Instance 1
OPENCLAW_CONFIG_PATH=~/.openclaw/openclaw-2.json openclaw gateway --port 18790  # Instance 2
```

## Firewall Rules

```
# UFW
sudo ufw allow 18789/tcp

# firewalld
sudo firewall-cmd --permanent --add-port=18789/tcp
```

Best practice: Keep on loopback + reverse proxy. Don't expose directly.

## Quick Reference

| Action | Command |
|--------|---------|
| Check port | `openclaw gateway status` |
| Change (temp) | `openclaw gateway --port 9000` |
| Change (permanent) | `openclaw config set gateway.port 9000` |
| Restart | `openclaw gateway restart` |
| Check usage | `lsof -i :18789` |

## FAQ

**What is the default port?**
18789.

**How do I change it?**
CLI flag, config file, or `openclaw config set gateway.port`.

**Do I need to open firewall?**
Only for external access. Local use needs no changes.

---

Skip port config: https://www.ampere.sh/setup
