GoAdmio

unblock

Unblock an IP address in the server firewall and in Cloudflare

On this page: Overview · Quick start · Syntax · Arguments · Output · Examples · Troubleshooting · Details · See also


Overview

/go/unblock reverses block. It has three modes, chosen by the single argument:

If you are not root, the command re-runs itself with sudo.


Quick start

# Unblock one IP address
/go/unblock 203.0.113.45

Syntax

/go/unblock <ip>
/go/unblock <domain>
/go/unblock log

The command takes one argument and has no -- options. Only the first argument is read.


Arguments

The argument is checked in this order, and the first match wins:

Argument Mode What it does
log Log mode Unblocks every IP that has a file in /var/log/go/block/.
A domain with a /home/<domain>/www folder Domain mode Deletes all block rules in that domain's Cloudflare zone.
An IPv4 or IPv6 address IP mode Unblocks that IP locally and in Cloudflare.
Anything else None Prints Invalid IP "<value>" and exits.

Address ranges such as 203.0.113.0/24 are not accepted as an argument. To remove a range rule, unblock an address inside it (see Range rules).


Output

IP mode

Message Meaning
Unblocking IP <ip> The local firewall step is running.
[<n>/<total>] Unblocking IP <ip> [<domain>] | <result> One line per hosted domain for the Cloudflare step.
Cloudflare result Meaning
Success. The block rule was deleted from the zone.
Not Found. Cloudflare has no such rule.
Failed. The delete request was rejected, or no rule was found for the IP.
No Zone ID. The domain was not found in the configured Cloudflare account.

Domain mode

Message Meaning
Unblocking All IPs [<domain>]... The zone was found and its block rules are being deleted.
[<n>/<total>] Unblocked rule ID: <id> - Status: Success. One rule was deleted.
[<n>/<total>] Unblocked rule ID: <id> - Status: Failed. One rule could not be deleted.

If the domain has no zone in the configured Cloudflare account, nothing is printed.

Exit status

Situation Status
IP mode, run completed 0
Invalid IP "<value>" 1
Domain mode (even when successful) 1
Log mode (even when successful) 1

Examples

# Unblock an IPv4 address
/go/unblock 203.0.113.45
# Unblock an IPv6 address
/go/unblock 2001:db8::1
# Remove every Cloudflare block rule from one domain
/go/unblock example.com
# Unblock every IP that has a block log file, then delete the files
/go/unblock log
# Review the log of past runs
tail -n 20 /var/log/go/unblock.log

Troubleshooting

Symptom Likely cause Fix
Invalid IP "<value>" The value is not an IPv4 address, an IPv6 address, log, or a hosted domain. Correct the value. For a domain, /home/<domain>/www must exist.
Invalid IP "" No argument was given. Pass an IP, a domain, or log.
Domain mode prints nothing The domain has no zone in the configured Cloudflare account. Check the domain's DNS setup with dns.
No Zone ID. for a domain The domain is not in the configured Cloudflare account, or the API token is wrong. Add the domain to Cloudflare with dns.
Not Found. or Failed. No Cloudflare rule with this IP in its notes exists, for example because the IP was never blocked there. None. The local firewall step still ran.
Other addresses were unblocked too The firewall match is a substring match. See Range rules. Block the unintended addresses again with block.
The IP is unblocked but sshtop or sasltop never blocks it again Its file in /var/log/go/block/ still exists. See Log files. Delete /var/log/go/block/<ip>.* if you want automatic blocking to resume.
The IP is still blocked on Debian or Ubuntu ufw keeps the earlier deny rule. See Debian and Ubuntu. Delete the deny rule with ufw status numbered and ufw delete <number>.

Details

IP mode

IP mode runs these steps in order:

# Step
1 Reject anything that is not an IPv4 or IPv6 address.
2 Tell go.blackhost.com that the IP was unblocked (Action=Unblock, 7-second timeout).
3 Delete the IP from the Block table in block.db, and remove its firewall rules (see below).
4 For every hosted domain, delete the Cloudflare block rule whose notes match the IP.

The Cloudflare step runs for every hosted domain, whatever the server's OS.

AlmaLinux, Rocky, CentOS, Red Hat, and Fedora

The command lists the firewalld rich rules, removes every rule that matches the IP or one of its parent ranges (see Range rules), and reloads the firewall. The removal is permanent.

Debian and Ubuntu

The command runs ufw allow from <ip> to any and ufw reload. It adds an allow rule and does not delete the earlier deny rule that block created.

The database delete on these systems also requires the row's username to be empty. Rows recorded with a username (see block) are left in place.

Range rules

The firewall step builds three prefixes from the IP and removes any rich rule that contains the IP or one of them:

Prefix Example for 203.0.113.45
a.0.0.0/ 203.0.0.0/
a.b.0.0/ 203.0.0.0/ (first two numbers)
a.b.c.0/ 203.0.113.0/

Unblocking one IP therefore also removes /8, /16, and /24 range rules that start with those numbers, such as 203.0.113.0/24. This is the way to remove a range rule.

Matching is a substring match, and dots match any character. Unblocking 203.0.113.4 can also remove the rule for 203.0.113.45.

Domain mode

Domain mode needs /home/<domain>/www to exist. It looks up the domain's Cloudflare zone, lists the rules in block mode, and deletes each one. It does not touch the local firewall or the block database.

[!WARNING] Domain mode deletes every block rule in the zone, including rules you or someone else added in Cloudflare by hand. Only the rules returned in the first page of Cloudflare's results are deleted, so run the command again if rules remain.

Log mode

Log mode reads every file in /var/log/go/block/. For each file whose name is an IPv4 or IPv6 address plus an extension, such as 203.0.113.45.ssh, it runs /go/unblock <ip> and then deletes the file. This includes the .white marker files that block creates for whitelisted IPs.

Log files

IP mode does not delete the IP's file in /var/log/go/block/. sshtop and sasltop skip any IP that has such a file, so an IP you unblock by hand is not blocked again by them until the file is removed. Log mode removes the files for you.

What a run does

flowchart TD
    A["unblock arg"] --> B{"arg is log?"}
    B -- "Yes" --> L["Unblock each IP in /var/log/go/block, delete its file"]
    B -- "No" --> C{"/home/arg/www exists?"}
    C -- "Yes" --> D["Delete all block rules in the domain's Cloudflare zone"]
    C -- "No" --> E{"Valid IP?"}
    E -- "No" --> X["Invalid IP, exit 1"]
    E -- "Yes" --> F["Notify go.blackhost.com"]
    F --> G["Delete from block database, remove firewall rules"]
    G --> H["Delete Cloudflare rule in each hosted domain"]

See also

Command Description
block Block an IP address in the server firewall and in Cloudflare
white Add an IP to the whitelist
sshtop Report top SSH brute-force sources and optionally block them
sasltop Report SASL LOGIN authentication failures and block persistent sources
waf Block IPs via Cloudflare WAF
firewall Install a firewall on a GoAdmio server
dns Add your domain to Cloudflare and edit the DNS zone