Skip to content

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

ParameterRequirementTypeDescription
idRequiredstringTarget virtual machine's unique identifier

Body Parameters

ParameterRequirementTypeDescription
directionRequiredstringTraffic flow direction: inbound (ingress) or outbound (egress)
protocolRequiredstringNetwork protocol specification: tcp, udp, or icmp
ethertypeRequiredstringIP protocol version: IPv4 or IPv6
remote_ip_prefixRequiredstringCIDR notation for allowed IP range
port_range_minRequiredintegerLower bound of permitted port range (1-65535)
port_range_maxRequiredintegerUpper bound of permitted port range (1-65535)
descriptionOptionalstringRule 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 direction
  • protocol: Network protocol
  • ethertype: IP protocol version
  • remote_ip_prefix: Allowed IP range in CIDR notation
  • port_range_min: Lower port boundary
  • port_range_max: Upper port boundary
  • description: 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"
    }
}