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> You need sudo access.
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> Redis will fail to start if IPv6 is disabled on your server. If this happens, remove <code>::1</code> from the <code>bind</code> line in <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.
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.
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 <REDIS_IP_ADDRESS> 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.
Ubuntu 18.04 LTS (Bionic Beaver) was released on April 26, 2018, with five years of official…
Apache Virtual Hosts let you run multiple websites on a single server. Each site gets its…
Django is a free, open-source Python web framework built for developing secure, scalable, and maintainable web…
MySQL replication is the process of automatically copying data from one database server to one or…
Joomla is one of the most popular open-source content management systems in the world. It is…
WordPress is the most popular open-source content management system in the world, powering over a quarter…