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

Upgrade Ubuntu 16.04 to 18.04 Bionic Beaver: Step-by-Step Guide

Ubuntu 18.04 LTS (Bionic Beaver) was released on April 26, 2018, with five years of official…

26 minutes ago

Set Up Apache Virtual Hosts on Ubuntu 18.04: Complete Guide

Apache Virtual Hosts let you run multiple websites on a single server. Each site gets its…

31 minutes ago

Install Django on Ubuntu 18.04: Python venv Setup Guide

Django is a free, open-source Python web framework built for developing secure, scalable, and maintainable web…

44 minutes ago

Configure MySQL Master-Slave Replication on Ubuntu 18.04

MySQL replication is the process of automatically copying data from one database server to one or…

59 minutes ago

Install Joomla on Ubuntu 18.04 with Apache: LAMP Stack Guide

Joomla is one of the most popular open-source content management systems in the world. It is…

1 day ago

Install WordPress on Ubuntu 18.04 with Apache: LAMP Stack Guide

WordPress is the most popular open-source content management system in the world, powering over a quarter…

1 day ago