Securing Redis via IPTables

Here's a simple script to secure Redis via IPTables (tested on CentOS 6.3):

#!/usr/bin/env bash


# this script will add an ip address to iptables
# allowing the ip address to connect to redis

# should be run with localhost first

if ! test "$IPADDRESS"; then
    echo "Please enter the IP Address you want to be able to connection to Redis."
    exit 1

sudo iptables -A INPUT -s $IPADDRESS -p tcp -m tcp --dport 6379 -j ACCEPT
sudo bash -c 'iptables-save > /etc/sysconfig/iptables'

Then run as follows:

$ ./ localhost
$ ./ 555.555.555.555 # < your ip goes here

Published on in Linux