For AI agents: The documentation index is at https://docs.digitalocean.com/llms.txt. Markdown versions of pages use the same URL with index.html.md in place of the HTML page (for example, append index.html.md to the directory path instead of opening the HTML document).
How to Configure Firewall Rules
Last verified 18 Nov 2026
DigitalOcean Cloud Firewalls are a network-based, stateful firewall service for Droplets provided at no additional cost. Cloud firewalls block all traffic that isn’t expressly permitted by a rule.
Inbound firewall rules define what traffic to allow or deny to the server, on which ports, and from which sources. If no inbound rules are configured, no incoming traffic is permitted.
Outbound firewall rules define what outgoing traffic to allow or deny, on which ports, and to which destinations. If no outbound rules are configured, no outbound traffic is permitted.
Note
The DigitalOcean Cloud Firewall service is a separate firewall from any firewall software running on a Droplet, such as UFW or IPFire. Any rules created using the Cloud Firewall service are not reflected in the firewall software of the Droplets it protects. Additionally, if you are using both the Cloud Firewall service and a Droplet-based firewall software to protect your Droplets, ensure that the rules between the two firewalls do not conflict.
Rule Actions
Each firewall rule has an action that determines whether the firewall allows or denies matching traffic. Allow rules permit traffic that matches the rule’s protocol, ports, and sources or destinations. Deny rules block matching traffic, which lets you filter traffic from specific sources, such as known malicious IP addresses, while still allowing broader access to your services.
For example, the following inbound rules allow public HTTPS traffic while blocking all traffic from one IP address and one IP range:
Protocol
Ports
Sources
Action
All
All
203.0.113.5
Deny
All
All
198.51.100.0/24
Deny
TCP
443
All IPv4, All IPv6
Allow
Deny rules take precedence over allow rules, including when the two rules belong to different firewalls applied to the same Droplet. If traffic matches both an allow rule and a deny rule, the firewall denies the traffic. Traffic that does not match any rule is denied by default.
Add, Update, or Remove Rules from a Firewall Using the CLI
The firewall rule management commands require the firewall’s ID. To retrieve a list of firewalls and their IDs, use the doctl compute firewall list command.
Note
doctl does not support a rule’s action field. To create or update deny rules, use the API.
How to Add a Rule to a Firewall Using the DigitalOcean CLI
The following example updates a cloud firewall named example-firewall that contains an inbound rule and an outbound rule and applies them to the specified Droplet:
You can use the optional action field when you create or update a rule with the API. The field accepts either allow or deny. If you omit the field, the rule allows traffic.
Deny rules also accept a protocol value of all, which matches traffic on all IP protocols and ports. Allow rules must specify tcp, udp, or icmp. When you set protocol to all, either omit the ports field or set it to "0". Any other port value returns an error.
For example, the following request adds an inbound rule that denies all traffic from the IP address 203.0.113.5:
When more than one firewall is applied to a Droplet, the rules from every one of those firewalls are combined into a single set. Allow rules are additive, so a broad allow rule in one firewall permits traffic that another firewall does not address. Deny rules take precedence across the combined set, so a deny rule in one firewall blocks matching traffic even when a different firewall applied to the same Droplet allows it.
Create New Rules
To create an inbound rule, click Add inbound rule in the Inbound rules section. To create an outbound rule, click Add outbound rule in the Outbound rules section. Each opens a window where you can use a preset rule type or define a custom rule.
Note
You can only define firewall rules to restrict traffic to and from ports based on connection types, sources, and destinations. You cannot define a rule to restrict traffic based on HTTP headers, such as X-Forwarded-For, Content-Type, or User-Agent.
From Presets
The Type drop-down includes presets for common protocols, such as SSH, HTTP, and HTTPS. Selecting a preset fills the Protocol and Port fields automatically. For example, selecting HTTP sets Protocol to TCP and Port to 80. If a service listens on a non-standard port, use a custom rule instead.
Custom Rules
To add a custom rule, set Type to Custom. You can then define the protocol, port range, source or destination, and action. For a custom rule, specify the:
Protocol. Choose TCP, UDP, or All. All is available for deny rules and matches all IP protocols and ports. Because ICMP has no port abstraction, allow ICMP traffic by selecting ICMP from the Type drop-down instead.
Port. For the TCP and UDP protocols, you can specify:
A single port.
A range of ports by entering the starting and ending ports separated by a dash - with no spaces, such as 3000-4000. To open multiple non-sequential ports, create a separate rule for each.
All ports by leaving the field blank.
Sources for inbound rules, which restrict the source of incoming connections. By default, the field is pre-populated with All IPv4 and All IPv6. Click x next to a chip to remove it, or clear all to remove all defaults. You can restrict incoming connections to:
Resources or tags by searching the name of the resource or tag. This includes Droplets, load balancers, VPCs, Kubernetes clusters, and resource tags.
IP addresses or IP ranges by entering individual IP addresses or a CIDR. For example, the CIDR 10.128.0.0/16 allows incoming traffic from any IP address between 10.128.0.0 and 10.128.255.255. The same applies to IPv6 addresses and CIDRs.
Types of IP addresses by choosing All IPv4 or All IPv6. This allows all IP addresses of that type to connect to the Droplet. If you are using the API, enter 0.0.0.0/0 (IPv4) or ::/0 (IPv6) into the addresses field of the sources object.
Sources for outbound rules, which restrict where outgoing connections can go. The field is labeled Sources in both inbound and outbound rule windows and accepts the same values described above.
Action. Choose whether the rule allows or denies matching traffic. Rules allow traffic by default. If traffic matches both an allow rule and a deny rule, the deny rule takes precedence.
You can limit the sources to:
Droplets, by name, IP address, or tag.
DigitalOcean load balancers, by name, IP address, or tag.
When you have set the type, port, sources, and action, click Add inbound rule or Add outbound rule to save the rule.
Edit or Delete Rules
To edit or delete a rule, click the … (More) menu on the right of the rule and choose Edit rule or Delete rule. When you select Delete rule, the rule is deleted immediately without an additional confirmation prompt.
We can't find any results for your search.
Try using different keywords or simplifying your search terms.