How To

Install and Configure Redis on Ubuntu 18.04: Remote Access Guide

Redis is an open-source, in-memory data structure store used as a database, cache, and message broker. It supports Strings, Hashes, Lists, Sets, and Sorted Sets, and can persist data to disk while still delivering sub-millisecond response times. It is widely used to speed up web applications by caching database query results, session data, and frequently accessed objects.

Redis also provides high availability through Redis Sentinel, which handles monitoring, notifications, and automatic failover. For horizontal scaling across multiple nodes, Redis Cluster handles automatic data partitioning.

This guide explains how to install Redis on Ubuntu 18.04 and configure it for remote access when needed.

<strong>Prerequisite:</strong>&nbsp;You need sudo access.

Install Redis on Ubuntu

Redis is available in Ubuntu’s default repositories. Update the package list and install it:

bashsudo apt updatesudo apt install redis-server

The Redis service starts automatically after installation. Check that it is running:

bashsudo systemctl status redis-server

Look for Active: active (running) in the output. Redis runs locally and listens on port 6379 at 127.0.0.1 by default.

<strong>Note:</strong>&nbsp;Redis will fail to start if IPv6 is disabled on your server. If this happens, remove&nbsp;<code>::1</code>&nbsp;from the&nbsp;<code>bind</code>&nbsp;line in&nbsp;<code>redis.conf</code>.

This default setup is correct if your application and Redis run on the same machine. Connections from localhost only is the most secure configuration for a single-server setup.

Configure Redis for Remote Access

By default, Redis only accepts connections from localhost. If your application runs on a separate server, you need to allow remote connections. Skip this section if everything runs on one machine.

Open the Redis configuration file:

bashsudo nano /etc/redis/redis.conf

Find the line that begins with bind 127.0.0.1 ::1 and change it to:

inibind 0.0.0.0 ::1

This tells Redis to listen on all IPv4 interfaces. Save the file and restart the Redis service:

bashsudo systemctl restart redis-server

Verify that Redis is now listening on all interfaces on port 6379:

bashss -an | grep 6379
tcp  LISTEN  0  128  0.0.0.0:6379  0.0.0.0:*

The 0.0.0.0 address confirms Redis is accepting connections on all IPv4 interfaces.

Secure and Test the Redis Connection

Opening Redis to a network without firewall restrictions is a security risk. Use UFW to allow access only from trusted IP ranges. This example allows connections from the 192.168.121.0/24 subnet:

bashsudo ufw allow proto tcp from 192.168.121.0/24 to any port 6379

Replace the subnet with the actual IP range of your application servers. Never expose port 6379 to the public internet without authentication.

To verify the remote connection is working, run this command from any trusted machine with redis-cli installed:

bashredis-cli -h &lt;REDIS_IP_ADDRESS&gt; ping
PONG

A PONG response confirms the remote machine can reach your Redis server on port 6379.

Redis is now installed and configured on your Ubuntu 18.04 server. Visit the Redis documentation to learn about persistence options, replication, and data structure commands. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

What Is a Data Protection Platform and Why Your Organization Needs One

A data protection platform is a unified system that helps organizations discover, classify, monitor, and…

2 weeks ago

How Swiss Privacy Rules Affect AI Companies Under GDPR

AI companies operating in or around Switzerland face a compliance challenge that most legal teams…

2 weeks ago

Swiss FADP vs EU GDPR: Key Differences for AI and Data Privacy

Two major data privacy laws now govern how organizations handle personal data across Europe; the…

2 weeks ago

Kali Linux Commands Cheat Sheet: Complete Quick Reference

This cheat sheet covers the essential Kali Linux commands every pentester and ethical hacker uses…

2 months ago

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

2 months ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 months ago