What's Actually Happening
Clients cannot connect to NATS server. Connection attempts are refused.
The Error You'll See
nats: no servers available for connectionWhy This Happens
- 1.Server not running - NATS process stopped
- 2.Wrong port - Client connecting to wrong port
- 3.Firewall blocking - Port blocked by firewall
- 4.Bind address - Server not listening on expected interface
Step 1: Check Server Status
```bash # Check if NATS running: ps aux | grep nats
# Or with systemd: systemctl status nats
# Check port: netstat -tlnp | grep 4222 ```
Step 2: Start Server
```bash # Start NATS: nats-server &
# Or with systemd: systemctl start nats ```
Step 3: Test Connection
```bash # Test with telnet: telnet localhost 4222
# Or with nats CLI: nats server info ```
Step 4: Check Configuration
```bash # Check config: cat nats.conf
# Verify port: grep port nats.conf
# Start with config: nats-server -c nats.conf ```
NATS Connection Checklist
| Check | Command | Expected |
|---|---|---|
| Server running | ps aux | Running |
| Port listening | netstat | 4222 |
| Firewall | iptables | Allowed |
Verify the Fix
nats server info
# Output: Server info displayedRelated Issues
- [Fix Kafka Broker Unavailable](/articles/fix-kafka-broker-unavailable)
- [Fix RabbitMQ Connection Refused](/articles/fix-rabbitmq-connection-refused)