GoAdmio

block

Block 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/block blocks an IP address on the server and, where possible, at Cloudflare. It:

It is also the command that sshtop, sasltop, and other GoAdmio monitors call when they find a bad source. Run it yourself to block an IP by hand.


Quick start

# Block an IP address
/go/block 203.0.113.45

Syntax

/go/block <ip> [type] [country] [company] [bot-name]

The command takes positional arguments and has no -- options. If you are not root, it re-runs itself with sudo.


Arguments

Position Argument Required Default Notes
1 <ip> Yes — An IPv4 address, an IPv4 /24 range written as a.b.c.0/24, or an IPv6 address.
2 [type] No log Why the IP is blocked. It changes the firewall action and the log file's extension. See Block types.
3 [country] No — Saved in the IP's log file. If the value contains a dot, it is treated as a hosted domain instead. See below.
4 [company] No — Saved in the IP's log file.
5 [bot-name] No — Used only when type is bot. Saved in the log file.

If the third argument contains a dot, GoAdmio looks up that domain's account username and stores both in the block database. The same value is still written to the log file as Country.


Output

The command prints what it is doing, then a blank line. Messages depend on the firewall and the number of hosted domains.

Message Meaning
Blocking IPv4 <ip> (<country>) [Local]... A new IPv4 firewall rule is being added.
Blocking IPv6 <ip> (<country>) [Local]... A new IPv6 firewall rule is being added.
Blocking IPv4 <ip> (<country>) [Local] (IP Found)... A rule for this IP already exists. Nothing is added, and Cloudflare is skipped.
[<n>/<total>] Blocking IP <ip> (<country>) [<domain>] | <result> One line per hosted domain for the Cloudflare step.

Cloudflare results

Result Meaning
Success. The block rule was created in the domain's Cloudflare zone.
Already Exists. The zone already blocks this IP.
Failed. Cloudflare rejected the request.
No Zone ID. The domain was not found in the configured Cloudflare account.
Proxy Off. The domain points straight at this server, so a Cloudflare rule would not help.
Proxy Off | Too Many | Break More than 5 such domains were found. The Cloudflare step stops.
Subdomain. Only main domains have zones. Subdomains are skipped.

Exit status

The command exits with status 1, and blocks nothing, in the cases below.

Message Cause
Cannot block server IP address. The IP is this server's own IPv4 or IPv6 address.
Invalid IP "<ip>" The first argument is not a valid IP or range.
IP <ip> is from whitelisted The IP matches an entry in /var/go/etc/white.
<ip> access whitelisted file (<file>) The IP requested a file listed in /var/go/etc/whitefiles.
IP <ip> (<country>) From Whitelisted Countries (<list>) The IP's country is a whitelisted country.
Can not Detect a Country Code Whitelisted countries are configured, but the IP's country could not be detected.

Examples

# Block an IP by hand
/go/block 203.0.113.45
# Block an SSH attacker (dropped at the firewall, no Cloudflare step)
/go/block 203.0.113.45 ssh NL "Example Hosting B.V."
# Block a bad bot and record its name
/go/block 203.0.113.45 bot NL "Example Hosting B.V." "ExampleBot"
# Block a /24 range
/go/block 203.0.113.0/24
# Block an IPv6 address
/go/block 2001:db8::1
# Review the log of past runs
tail -n 20 /var/log/go/block.log

Troubleshooting

Symptom Likely cause Fix
Cannot block server IP address. The IP is the server's own address. Check that you typed the attacker's IP.
Invalid IP "<ip>" The value is not an IPv4 address, a.b.c.0/24 range, or IPv6 address. Correct the value. Other ranges are not accepted.
IP <ip> is from whitelisted A line in /var/go/etc/white matches the IP, or its first one, two, or three numbers. Remove or narrow the entry, then run again. See white.
Can not Detect a Country Code Country whitelisting is on and the lookup failed. Try again later, or block the IP with a different method.
Blocking ... (IP Found)... The firewall already has a rule for this IP. None. To remove it, use unblock.
No Zone ID. for every domain The Cloudflare account ID or API token is missing or wrong in the server configuration. Check the Cloudflare settings with config.
Proxy Off. for most domains The domains are not proxied through Cloudflare. Turn the proxy on with proxy, or rely on the local firewall.
Failed. from Cloudflare The API token lacks permission to edit firewall rules, or the value is not accepted (for example a /24 range). Check the token's permissions.
A blocked IPv4 can still reach SSH or mail Only ssh and bot drop IPv4 traffic on firewalld. Other types redirect HTTPS only. Block again with type ssh or bot. See Block types.
Nothing is blocked at the firewall The server's OS is not one of the supported distributions. Block the IP with your own firewall tool.

Details

Block types

On AlmaLinux, Rocky, CentOS, Red Hat, and Fedora, the type decides what the firewalld rule does. "Forward" means HTTPS traffic (TCP port 443) from the IP is redirected to local port 2080 instead of being dropped.

Type IPv4 rule IPv6 rule Cloudflare step
ssh Drop Forward, then drop Skipped
bot Drop Drop Runs
403 Forward Drop Runs
Anything else (log, sasl, and so on) Forward Forward, then drop Runs

On Debian and Ubuntu, every type runs ufw deny from <ip> to any.

Order of checks

Checks run in this order, and the first one that matches stops the command:

# Check
1 The IP is the server's own IPv4 or IPv6 address.
2 The IP is valid.
3 The IP matches /var/go/etc/white (exact start, or its first one, two, or three numbers followed by anything).
4 The IP requested a file listed in /var/go/etc/whitefiles, found in the access log.
5 The IP's country is whitelisted, or cannot be detected while country whitelisting is on.

When check 3 matches, the command also creates an empty /var/log/go/block/<ip>.white file, so that sshtop and sasltop treat the IP as already handled and do not try again.

What gets recorded

Where What
block.db, table Block IP, country, domain, username, and time of the block. Added once per IP.
ddos.db, table DDos Any entry for this IP is removed.
/var/log/go/block/<ip>.<type> Country, company, bot name (bot only), and every access-log line for the IP. Not written for /24 ranges.
/var/log/go/block.log The command and its arguments, with a timestamp.

The database and firewall steps run only on a supported OS (AlmaLinux, Rocky, CentOS, Red Hat, Fedora, Debian, or Ubuntu).

Cloudflare step

The step runs for every type except ssh, and only when the IP did not already have a local firewall rule. For each directory in /home that has a www folder:

  1. If the domain resolves to this server's IP, it is counted as Proxy Off. After more than 5 of these, the step stops.
  2. If the domain is a subdomain, it is skipped.
  3. Otherwise the zone is looked up with the Cloudflare account ID and API token from the server configuration, and a block rule for the IP is created in that zone.

Reporting

Before blocking, the command sends the IP, the server's hostname, and the server's IP to go.blackhost.com, with a 7-second timeout. The type sent is SSH for ssh blocks and BOT for all others. The server does not wait for a reply.

What a run does

flowchart TD
    A["block ip [type] ..."] --> B{"Server IP or invalid?"}
    B -- "Yes" --> X1["Exit 1"]
    B -- "No" --> C{"Whitelisted IP, file, or country?"}
    C -- "Yes" --> X2["Exit 1"]
    C -- "No" --> D["Report to go.blackhost.com"]
    D --> E["Record in block database"]
    E --> F["Add firewall rule"]
    F --> G{"Type ssh, or rule already existed?"}
    G -- "No" --> H["Add Cloudflare rule per domain"]
    G -- "Yes" --> I
    H --> I["Write /var/log/go/block/ip.type"]

See also

Command Description
unblock Unblock an IP address on a GoAdmio server
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
bottop Block bad bots from visiting your server
ddos Track and block DDoS attack IPs in GoAdmio
waf Block IPs via Cloudflare WAF
blacklist Block blacklisted IPs (bad bots and SSH brute-force attacks)
firewall Install a firewall on a GoAdmio server
proxy Change Cloudflare's proxy setting