Exposing a Local Redis Instance to the Internet via TCP Tunneling

Redis is an in-memory key-value store prized for microsecond-level latency. Running it in side a private network is straightforward, but making it reachable from anywhere requires an extra hop. Below you’ll learn how to compile Redis on CentOS 8, seecure it for remote clients, and then punch a stable TCP tunnel through any NAT or firewall using cpolar.

  1. Build Redis from source

cd /usr/local
curl -O https://download.redis.io/releases/redis-7.2.4.tar.gz
tar xf redis-7.2.4.tar.gz
cd redis-7.2.4
make -j$(nproc)
make install PREFIX=/opt/redis

The binaries now live under /opt/redis/bin. Start the server once to verify everything works, then stop it with Ctrl-C.

  1. Harden the configuration

cp /opt/redis/redis.conf /opt/redis/redis.conf.bak
vim /opt/redis/redis.conf

Apply these changes:

  • daemonize yes – detach from the terminal
  • bind 0.0.0.0 – listen on every interface (or restrict to specific IPs)
  • protected-mode no – required when no password is set (see next bullet)
  • requirepass Sup3rSecret! – enforce authentication
  • maxmemory 256mb – optional safeguard against RAM exhaustion
/opt/redis/bin/redis-server /opt/redis/redis.conf

Redis is now running in the background on port 6379.

  1. Install cpolar

curl -fsSL https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
sudo cpolar authtoken <YOUR-TOKEN>
sudo systemctl enable --now cpolar

Confirm the daemon is active:

sudo systemctl status cpolar

  1. Expose Redis to the Enternet

4.1 Quick one-off tunnel

cpolar tcp 6379

The CLI prints a temporary hostname and port (e.g., 3.tcp.cpolar.io:11235). You can connect immediately with:

redis-cli -h 3.tcp.cpolar.io -p 11235 -a Sup3rSecret!

This endpoint expires after 24 hours.

4.2 Persistent reserved endpoint

  1. Log in to the cpolar dashboard → ReservedTCP Address.
  2. Select region China VIP, add a description like prod-redis, and click Reserve.
  3. Copy the fixed address shown (e.g., redis-prod.tcp.cpolar.io:18543).
  4. Create a permanent tunnel configuration:
sudo mkdir -p /etc/cpolar
sudo vim /etc/cpolar/redis.yml

/etc/cpolar/redis.yml

tunnels:
  redis-prod:
    proto: tcp
    addr: 6379
    remote_addr: redis-prod.tcp.cpolar.io:18543

sudo systemctl restart cpolar

From now on, every reboot will automatically re-establish the tunnel to the same public host and port.

  1. Verify remote connectivity

Using redis-cli from any machine:

redis-cli -h redis-prod.tcp.cpolar.io -p 18543 -a Sup3rSecret! ping

Expected response:

PONG

You can also point GUI clients like RedisInsight or Another Redis Desktop Manager to the same endpoint.

  1. Security checklist

  • Keep requirepass strong and rotate it periodically.
  • If feasible, restrict source IPs in the cpolar dashboard.
  • Consider enabling TLS (stunnel or Redis 6+ native TLS) to protect data in transit.
  • Monitor MONITOR or SLOWLOG for suspicious activity.

Tags: Redis centos cpolar TCP Tunnel Remote Access

Posted on Thu, 13 Aug 2026 16:29:01 +0000 by tonchily