> Write RestoreCord firewall rules that fit your server: match ASN, country, username or server membership, then block, allow, require a password or bypass.

Source: https://restorecord.sh/discord-firewall-rules

# Discord firewall rules: fields, operators and decisions

Templates handle the threats every server shares. Custom rules handle the ones only your server has, like the hosting network that keeps feeding you raid accounts.

[Get started free](https://restorecord.com/register)[View pricing](https://restorecord.com/pricing)

Short answer

A RestoreCord firewall rule is one If line and one Then decision. Pick a field such as ASN, country, username or server membership, choose an operator and a value, then block, allow, require a password or bypass all checks. Custom rules start on Premium.

## The anatomy of a rule

Every rule reads like a sentence. **If** a field matches a value, **then** apply a decision, optionally **and give** one or more roles. The builder in your server's Firewall tab shows that sentence as a live preview while you fill it in, so you can read the rule back before you save it.

A rule holds a single condition on purpose. Narrow rules are easy to name, easy to expire and easy to delete when they stop being useful. If you need two conditions, write two rules.

## Fields you can match on

Ten fields cover the network, the account and the member's place in your community:

| Field                | Operators                              | Example value                         |
| -------------------- | -------------------------------------- | ------------------------------------- |
| IP address           | is, is not                             | 192.168.1.1                           |
| IP range             | is within, is not within               | 192.168.1.0/24                        |
| Country or continent | is, is not                             | One or more codes                     |
| ASN                  | is, is not                             | 13335                                 |
| Username             | is, is not, contains, does not contain | /^staff\[-\_\].+/i                    |
| Email domain         | is, is not, contains, does not contain | /\\.edu$/i                            |
| User ID              | is, is not                             | A Discord user ID                     |
| Discord role         | contains, does not contain             | A role in your server                 |
| Server membership    | contains, does not contain             | A Discord server ID (Business and up) |

## The four decisions

* **Block.** The member is refused at verification and never gets the verified role.
* **Allow through firewall.** A trusted match is waved past the firewall rules.
* **Require password.** The member must enter one of your verification passwords. Passwords are an Enterprise feature.
* **Bypass all checks.** Reserved for the handful of accounts you would trust with the keys.

A block rule can't give roles. Every other decision can add up to five distinct roles, which is handy for tagging staff or event guests the moment they verify.

## Patterns for usernames and email domains

The username and email domain fields accept either plain text or a pattern wrapped in slashes. That lets one rule match a whole family of names instead of a single account. Here is a staff rule expressed as the JSON the API accepts:

Staff access rulejson

```
{
  "name": "Staff access",
  "targetType": "USERNAME",
  "operator": "CONTAINS",
  "targetValue": "/^staff[-_].+/i",
  "actions": [
    { "type": "ALLOW" },
    { "type": "GIVE_ROLE", "roleId": "123456789012345678" }
  ]
}
```

## Let emergency rules expire

Each rule can carry an expiration, from 30 minutes up to 3 months, or none at all. Rules written in the middle of a raid are usually broader than you would like, so give them a short life by default. A rule that blocks an entire provider for 6 hours fixes tonight's problem without quietly turning away real members next month.

## Three rules worth stealing

### The staff pass

Field **Discord role**, operator **contains**, your moderator role, decision **allow through firewall**. Your team verifies from anywhere, even while the strict templates stay on.

### The hosting-network lockout

Field **ASN**, operator **is**, the number you keep seeing in the activity log, decision **block**, expiry 6 hours. One rule removes a whole cloud provider from the raid. ASN blocking needs Business or higher.

### The hostile-server rule

Field **Server membership**, operator **contains**, the ID of the server organising raids against you, decision **block**. This one also needs Business or higher.

---

Before you roll out a strict rule, verify with a known staff account and read the activity log entry it produces. If the reason matches what you expected, the rule is ready.

Back to the [RestoreCord Shield overview](https://restorecord.sh/), see how these rules fit into a [raid response plan](https://restorecord.sh/raid-response-plan), or create them from your own bot with the [firewall API](https://restorecord.sh/automate-firewall-api).

## Build your first custom rule

1. 1  
### Choose Custom Rule  
Open your server's Firewall in the RestoreCord dashboard, press Add Security Rule and pick Custom Rule.
2. 2  
### Write the If line  
Pick a field such as ASN, country or username, choose an operator and enter the value you want to match.
3. 3  
### Pick the Then decision  
Select block, allow through firewall, require password or bypass all checks, and add Give Role actions if needed.
4. 4  
### Name it and set an expiry  
Give the rule a name your staff will understand, choose an expiry or no expiry, and create it.
[Open the firewall](https://restorecord.com/firewall)

## Which decision fits the job?

What each Then option does, side by side.

|                                   | Block   | Allow                   | Require password | Bypass all |
| --------------------------------- | ------- | ----------------------- | ---------------- | ---------- |
| Member can end up verified        | —       | With the right password |                  |            |
| Can add Give Role actions         | —       | Up to 5                 | Up to 5          | Up to 5    |
| Needs an active firewall password | —       | —                       | —                |            |
| Plan                              | Premium | Premium                 | Enterprise       | Premium    |

## Firewall rule questions

### 

### 

### 

## Write the rule your raiders didn't plan for

Custom firewall rules start on Premium. Name them, expire them and keep your server's door exactly as wide as you want.

[Unlock custom rules](https://restorecord.com/pricing)[View pricing](https://restorecord.com/pricing)
