doctl Verified current stable Not installed? Documentation

Doctl / Add Database Firewall Rule

Add Database Firewall Rule

Add a firewall rule to a specific database in DigitalOcean.

$
Terminal
doctl {d|databases} {fw|firewalls} {a|append} {database_id} --rule {droplet|k8s|ip_addr|tag|app}:{value}

When To Use

When updating security measures to include or restrict access to database.

Pro Tip

Always validate rule syntax before execution to prevent errors; malformed rules can result in denied access.

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
$ doctl databases fw append 12345 --rule ip:192.168.1.10

Firewall rules for database 12345:
+----------------+-------------------+
|      TYPE      |        VALUE       |
+----------------+-------------------+
|      ip       |     192.168.1.10   |
+----------------+-------------------+

Anatomy of Output

Understanding the result

Rule added: ip:1.2.3.4 Added Rule

Confirmation of the newly applied rule.

Total rules now: 6 Rule Count

Current total number of firewall rules.

Status: success Operation Status

Indicates successful execution.

Troubleshooting

Common pitfalls

Error: Invalid rule format.

Solution: Ensure the rule follows the prescribed format.

Error: Database ID not found.

Solution: Verify the ID for the target database.

Error: Permission denied.

Solution: Check that the used access token has appropriate permissions.

Command Breakdown

What each part is doing

doctl
Base Command
The executable that performs this operation. Here it runs Doctl before the shell applies any redirect operators.
--rule
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Identify the database ID using `doctl databases list`.

  2. Step 2

    Run the command to append the firewall rule with the desired IP address.

Alternative Approaches

Comparable commands in other tools

Alternative documentation tools for the same job.