How do I bulk add IP addresses to firewall?

Posted February 11, 2018 6.2k views
FirewallConfiguration Management

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?

1 comment

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.

Submit an Answer
1 answer

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"] } } ] }' \
  • Hi.

    That was a really helpful reply. Apologies for my ignorance but I have a json file with my whitelist on it.

    Can I amend the above code just to use the file or should I just add the ip addresses in that space [“JSON.ARRAY.OF”, “ALL.THE.IP.ADDRESSES”, “YOU.WANT.TO.ADD”] - it’s about 200.

    Also am I correct in thinking this sets the Droplet firewall rather than the uff firewall. Would this then show up in the firewall control panel?

    Apologies if these are very basic questions. Somewhat new to this.

    Many thanks.