How to allowlist your IP address

Allowlisting means "only let these addresses in." It's one of the simplest ways to keep strangers away from a server, database, or admin page. Here's how to do it without locking yourself out.

Step 1: get the right address

You need your public IP, the one the server will see. It's at the top of gopherip.com, and GopherIP also shows ready-to-copy rules for it right below. From a terminal: curl gopherip.com.

Write single addresses in CIDR form: /32 for one IPv4 address, /128 for one IPv6 address. For example, 203.0.113.42/32.

Step 2: add the rule

AWS security group

aws ec2 authorize-security-group-ingress --group-id sg-XXXXXXXX \
  --protocol tcp --port 22 --cidr 203.0.113.42/32

Or in the console: EC2, Security Groups, Edit inbound rules, Add rule, Source "My IP." (The console fills it in for you, but it's worth double-checking against GopherIP if you're on a VPN.)

Apache

<Location "/admin">
    Require ip 203.0.113.42
</Location>

nginx

location /admin {
    allow 203.0.113.42;
    deny all;
}

ufw (Ubuntu firewall)

sudo ufw allow from 203.0.113.42 to any port 22 proto tcp

MySQL or MariaDB

CREATE USER 'appuser'@'203.0.113.42' IDENTIFIED BY 'a-strong-password';

The database's own firewall or security group must also allow the address.

Step 3: don't lock yourself out

Is allowlisting enough?

It's a strong first layer, not the only one. Keep passwords strong, use SSH keys instead of passwords, and keep software updated. Allowlisting just means far fewer strangers get to knock in the first place.