Add Firewall Rule to Virtual Machine
Configure and implement network security policies by creating firewall rules for a specific virtual machine instance. The rule configuration is specified through the request body parameters.
HTTP Request
POST
{API_URL}/virtual-machines/{id}/firewall-rules
Path Parameters
Parameter | Requirement | Type | Description |
---|---|---|---|
id | Required | string | Target virtual machine's unique identifier |
Body Parameters
Parameter | Requirement | Type | Description |
---|---|---|---|
direction | Required | string | Traffic flow direction: inbound (ingress) or outbound (egress) |
protocol | Required | string | Network protocol specification: tcp , udp , or icmp |
ethertype | Required | string | IP protocol version: IPv4 or IPv6 |
remote_ip_prefix | Required | string | CIDR notation for allowed IP range |
port_range_min | Required | integer | Lower bound of permitted port range (1-65535) |
port_range_max | Required | integer | Upper bound of permitted port range (1-65535) |
description | Optional | string | Rule description for administrative purposes |
Response Structure
status boolean
Operation result indicator. Returns true
for successful execution, false
when encountering an error.
message string
Descriptive response indicating the outcome of the rule creation request.
data object
Contains the implemented firewall rule configuration including:
direction
: Traffic flow directionprotocol
: Network protocolethertype
: IP protocol versionremote_ip_prefix
: Allowed IP range in CIDR notationport_range_min
: Lower port boundaryport_range_max
: Upper port boundarydescription
: Administrative annotation
Implementation Example
Request
bash
curl -X POST '{API_URL}virtual-machines/{id}/firewall-rules' \
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'refresh-token: {REFRESH_TOKEN}' \
-H 'Content-Type: application/json' \
-d '{
"direction": "inbound",
"ethertype": "IPv4",
"protocol": "tcp",
"port_range_min": 80,
"port_range_max": 80,
"remote_ip_prefix": "0.0.0.0/0",
"description": "HTTP access"
}'
Response
json
{
"status": true,
"message": "Firewall rule successfully implemented",
"data": {
"id": "67714175e19f11c9cb6a6147",
"direction": "inbound",
"ethertype": "IPv4",
"protocol": "tcp",
"port_range_min": 80,
"port_range_max": 80,
"remote_ip_prefix": "0.0.0.0/0",
"description": "HTTP access"
}
}