Last active
July 15, 2020 11:54
-
-
Save akhiljalagam/b29097328bccfa0e9c4ffc160ea67c31 to your computer and use it in GitHub Desktop.
How to bulk add IP addresses to DigitalOcean firewall?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Akhil Jalagam | |
# update TOKEN, FIREWALL NAME, IP addresses and then run the script | |
TOKEN=dfjvbidvbasb4l5tu45hvu46vgl45h6vl | |
FIREWALL_NAME=internalaccess | |
curl -X POST -H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $TOKEN" \ | |
-d \ | |
'{ | |
"name": "'$FIREWALL_NAME'", | |
"inbound_rules": [ | |
{ | |
"protocol": "tcp", | |
"ports": "all", | |
"sources": { | |
"addresses": [ | |
"196.112.47.128/29", | |
"196.112.43.128/29" | |
] | |
} | |
}, | |
{ | |
"protocol": "udp", | |
"ports": "all", | |
"sources": { | |
"addresses": [ | |
"196.112.47.128/29", | |
"196.112.43.128/29" | |
] | |
} | |
}, | |
{ | |
"protocol": "icmp", | |
"sources": { | |
"addresses": [ | |
"0.0.0.0/0", | |
"::/0" | |
] | |
} | |
} | |
], | |
"outbound_rules": [ | |
{ | |
"protocol": "icmp", | |
"destinations": { | |
"addresses": [ | |
"0.0.0.0/0", | |
"::/0" | |
] | |
} | |
}, | |
{ | |
"protocol": "tcp", | |
"ports": "all", | |
"destinations": { | |
"addresses": [ | |
"0.0.0.0/0", | |
"::/0" | |
] | |
} | |
}, | |
{ | |
"protocol": "udp", | |
"ports": "all", | |
"destinations": { | |
"addresses": [ | |
"0.0.0.0/0", | |
"::/0" | |
] | |
} | |
} | |
] | |
}' "https://api.digitalocean.com/v2/firewalls/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment