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

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

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

3 days ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

3 days ago

who Command in Linux: Show All Logged-In Users and Sessions

When you share a server with a team or investigate unexpected activity, the first question…

3 days ago

file Command in Linux: Identify File Types Without Extensions

The file command inspects the actual contents of a file and reports its type — regardless of…

4 days ago

chattr Command in Linux: Set File Attributes with lsattr

chattr sets and removes special file attributes that operate at the filesystem level, separate from standard…

4 days ago

env Command in Linux: Show and Set Environment Variables

env prints the current environment, sets or removes variables for a single command, and can start…

4 days ago