> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rdp.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Firewall Rule

> Create a new firewall rule for the server. The rule is applied to the
server's firewall in the background. If the firewall refuses it, for
example because of a service name it does not know,
`GET /servers/{server}/firewall` returns the reason in the rule's
`sync_error`.




## OpenAPI

````yaml post /servers/{server}/firewall
openapi: 3.1.0
info:
  title: APIFiddle Sample Definition
  version: 0.0.0
  description: Example workspace
servers:
  - url: https://rdp.sh/api/v1
    description: Default production endpoint.
security: []
paths:
  /servers/{server}/firewall:
    post:
      summary: Create firewall rule
      description: |
        Create a new firewall rule for the server. The rule is applied to the
        server's firewall in the background. If the firewall refuses it, for
        example because of a service name it does not know,
        `GET /servers/{server}/firewall` returns the reason in the rule's
        `sync_error`.
      operationId: createFirewallRule
      parameters:
        - $ref: '#/components/parameters/server'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - action
                - type
              properties:
                action:
                  type: string
                  enum:
                    - ACCEPT
                    - DROP
                    - REJECT
                  description: Rule action
                type:
                  type: string
                  enum:
                    - in
                    - out
                  description: Traffic direction
                proto:
                  type: string
                  description: >-
                    Protocol (tcp, udp, icmp, etc.). Required when `dport` or
                    `sport` is set.
                dport:
                  type: string
                  maxLength: 255
                  description: >
                    Destination ports, separated by commas: ports from 1 to
                    65535,

                    `from:to` ranges and service names such as `https`.

                    At most 15 ports, with a range counting as two.

                    Leave it empty to match every port; `*` is refused.

                    Requires `proto`.


                    Spaces between entries and `-` in ranges are accepted and
                    normalised:

                    `80, 443` is stored as `80,443` and `1000-2000` as
                    `1000:2000`.

                    Any other list returns a 422.
                sport:
                  type: string
                  maxLength: 255
                  description: |
                    Source ports, in the same format as `dport`.
                    Requires `proto`.
                source:
                  type: string
                  description: Source IP/CIDR
                dest:
                  type: string
                  description: Destination IP/CIDR
                comment:
                  type: string
                  maxLength: 255
                  description: Rule comment
                enable:
                  type: boolean
                  description: Whether rule is enabled
      responses:
        '200':
          content:
            application/json:
              schema:
                type: object
                title: CreateFirewallRuleOk
                properties:
                  status:
                    type: boolean
                  message:
                    type: string
          description: Firewall rule created successfully.
        '403':
          description: Unauthorized access.
        '422':
          description: >
            Validation error.

            The reason a port list was refused is in `errors.dport` or
            `errors.sport`.

            A rule with a port but no `proto` returns

            "A rule with a port needs a protocol, tcp or udp." in
            `errors.proto`.
        '500':
          description: Failed to create rule.
      security:
        - Authorization: []
components:
  parameters:
    server:
      in: path
      name: server
      schema:
        type: string
      required: true
  securitySchemes:
    Authorization:
      in: header
      name: Authorization
      type: apiKey

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.