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 Create Firewalls
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.
Create a Firewall Using the CLI
You can provide the --droplet-ids flag a list of Droplet IDs to automatically assign existing Droplets to a firewall during its creation. To retrieve a list of Droplets and their IDs, use the doctl compute droplet list command.
How to Create a Firewall Using the DigitalOcean CLI
Use the token to grant doctl access to your DigitalOcean account.
doctl auth init
Finally, run doctl compute firewall create. Basic usage looks like this, but you can read the usage docs for more details:
doctl compute firewall create [flags]
The following example creates a cloud firewall named example-firewall that contains an inbound rule and an outbound rule and applies them to the specified Droplets:
You can provide the droplet_ids field with an array of Droplet IDs to automatically assign existing Droplets to a firewall during its creation. To retrieve a list of Droplets and their IDs, use the /v2/droplets endpoint.
How to Create a Firewall Using the DigitalOcean API
Because the compromise of a server typically begins over an inbound connection, the default inbound connections remain entirely restricted with one exception. The suggested rule allows SSH connections on port 22 from anywhere so that users can administer the server from a terminal.
Default Outbound Rules: Permit All Traffic
Many fundamental services rely on outbound communication. Utilities like ping require outbound ICMP. DNS lookups, VoIP and NTP all rely on outbound UDP. Tasks like data synchronization, package list updates, web requests and email require outbound TCP connections.
Because of this, the suggested outbound rules permit all traffic to any destination on any port. These defaults make it easier to set up a new server without introducing restrictions that could block expected functionality.
Apply to Droplets
After configuring the firewall’s rules, apply the firewall to the Droplets you want to secure using the Apply to Droplets field. You can also leave this field blank and assign Droplets later.
In the Apply to Droplets field, type the name of a Droplet or resource tag into the field. A drop-down populates with a applicable resources. Choose Droplets by name, tag, or a combination of both. You can also search for Droplets by IP address.
There are limits on the number of Droplets and tags that can be added to a firewall, but there are no limits to the number of Droplets that can be associated with a tag. Using tags allows you to exceed the individual Droplet limit for firewalls. You can also tag a Droplet when you create it, which means you can apply firewall rules immediately.
Droplets can be protected by more than one cloud firewall. When they are, a union of the rules is applied. For example, if one rule allows TCP from any source and another allows TCP from a restricted range, the union of the two means that TCP traffic is allowed from anywhere.
Create the Firewall
Once you’ve defined the firewall’s rules and added Droplets to it, click Create Firewall.
After creating a firewall, you can manage its rules and the resources it protects on the Firewalls tab of the Networking page.
We can't find any results for your search.
Try using different keywords or simplifying your search terms.