Virtual Machine

Add firewall rule to virtual machine

Creates a firewall rule and applies it to a virtual machine. Include the virtual machine ID in the path and the firewall rule configuration in the request body.

post/core/virtual-machines/{vm_id}/sg-rules

Request

  • Base URL: https://infrahub-api.nexgencloud.com/v1
  • URL: https://infrahub-api.nexgencloud.com/v1/core/virtual-machines/{vm_id}/sg-rules
  • Auth: API key in header api_key

Path parameters

vm_idinteger required

ID of the vm.

Request body

directionstring required

The direction of traffic that the firewall rule applies to.

ethertypestring required

The Ethernet type associated with the rule.

protocol'any' | 'ah' | 'dccp' | 'egp' | 'esp' | 'gre' | 'hopopt' | 'icmp' | 'igmp' | 'ip' | 'ipip' | 'ipv6-encap' | 'ipv6-frag' | 'ipv6-icmp' | 'icmpv6' | 'ipv6-nonxt' | 'ipv6-opts' | 'ipv6-route' | 'ospf' | 'pgm' | 'rsvp' | 'sctp' | 'tcp' | 'udp' | 'udplite' | 'vrrp' required

The network protocol associated with the rule. Call the List firewall rule protocols endpoint to retrieve a list of permitted network protocols.

remote_ip_prefixstring required

The IP address range that is allowed to access the specified port. Use "0.0.0.0/0" to allow any IP address.

port_range_mininteger

The minimum port number in the range. Required when protocol is tcp or udp.

port_range_maxinteger

The maximum port number in the range. Required when protocol is tcp or udp.

Example request

{
  "protocol": "any"
}

Response

The firewall rule has been successfully added to the virtual machine.

statusboolean

Whether the request succeeded.

messagestring

Human-readable description of the result.

Example response

{
  "status": true,
  "message": "Security Rule created successfully",
  "security_rule": {
    "id": 5341,
    "direction": "ingress",
    "protocol": "tcp",
    "port_range_min": 22,
    "port_range_max": 22,
    "ethertype": "IPv4",
    "remote_ip_prefix": "0.0.0.0/0",
    "status": "pending",
    "created_at": "2026-05-06T14:32:11Z"
  }
}

Changes

No recorded changes to this operation across all 1 revision of this API.