Question

How do I bulk add IP addresses to firewall?

I have ~60 IPs to whitelist and would like to paste the entire list into each of the rules but can’t. It seems to only allow single IP entry at a time. is there a way to to add the entire list with a copy and paste?

Subscribe
Share

You get the PERSONAL-TOKEN from here:

https://cloud.digitalocean.com/account/api/tokens

And FIREWALL-ID from the link of your rule

https://cloud.digitalocean.com/networking/firewalls/YOUR-FIREWALL-ID/

In this example, I added a whitelist for port 443 from inbound coming from source IP1 and IP2

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer PERSONAL-TOKEN" -d '{"inbound_rules":[{"protocol":"tcp","ports":"443","sources":{"addresses":["IP1","IP2"]}}]}' "https://api.digitalocean.com/v2/FIREWALL-ID/rules"

Just remember you will not be able to remove this rule from the GUI

For more information visit:

https://developers.digitalocean.com/documentation/v2/#add-rules-to-a-firewall

I was having the same issue so I thought why not help others 😊


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

It doesn’t look like the cloud control panel UI allows you to paste in multiple IP Addresses at once. That’s a good idea for a UI improvement.

In the meantime you can definitely do it via the API

Here is a curl command you can run to create a new Firewall with multiple IP addresses allowed on an inbound rule TCP port 22 rule on a specific droplet:

curl -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_DIGITALOCEAN_API_TOKEN" \
-d '{"name":"My-Firewall", "inbound_rules":[{"droplet_ids":[DROPLETID], "protocol":"tcp", "ports":22, "sources":{"addresses":["JSON.ARRAY.OF", "ALL.THE.IP.ADDRESSES", "YOU.WANT.TO.ADD"] } } ] }' \
"https://api.digitalocean.com/v2/firewalls/"