Skip to main content

How to configure firewall and NAT rules

When to use​

When you need to allow or block traffic through an Edge, or publish a service at a different address and port. This procedure takes you from reading the current set to applying rules to the router and checking the packet filter log.

Keep the key distinction in mind: editing rules and applying them are separate steps. Adding and removing rules changes only the configuration in vStack Center. Until you click Apply rules, traffic follows the previous set. Always finish a series of edits by applying the rules.

Prerequisites​

  • To read the set, the Cluster master role or any VDC (virtual data center) role: administrators, users, and observers can read the rules of every router in their own VDC;
  • To edit and apply the set, the Cluster master role or router ownership. A VDC administrator can edit and apply rules only on routers they created;
  • To apply the set, the router is running: the operation has completed, and internal initialization (bootstrap) is complete;
  • The router ports are already connected to networks: a rule is bound to a port, and the form selects the port by network name;
  • vStack Center version 3.0.3.

Steps​

  1. Open the router page. In the sidebar tree, expand Virtual Data Centers, select the VDC, go to its Edges section, and open the required router's row. The current sets are in the Firewall rules and NAT rules sections: rule tables with the rule count next to each section heading.

  2. Add a firewall rule. In the Firewall rules section, click Add rule and fill in the fields:

    Form fieldRequiredWhat it specifies
    #YesRule number, 100–32767. The form fills it in automatically: 100 for the first rule, then the highest number in the set plus 100
    ActionYesAction: block or pass
    DirectionYesDirection: in or out
    NetworkYesRouter port to which the rule is bound. Selected by network name
    ProtocolYesProtocol: ICMP, UDP, TCP, or IP
    From (CIDR)YesSource in CIDR notation. Default: 0.0.0.0/0
    From PortYesSource port. Default: 0
    Dst. (CIDR)YesDestination in CIDR notation. Default: 0.0.0.0/0
    Dst. PortYesDestination port. Default: 0
    LogNoRule logging checkbox. Available only for the block action

    Click Save Rule. The rule appears in the section table.

  3. Add a NAT rule. In the NAT rules section, click Add rule. Here, the translation address and port replace the direction and source port:

    Form fieldWhat it specifies
    #Rule number. The form fills it in automatically using the same rule as for firewall rules
    ActionAction: SNAT, DNAT, or biNAT
    NetworkRouter port to which the rule is bound
    ProtocolProtocol: ICMP, UDP, TCP, or IP
    From (CIDR)Source in CIDR notation
    Dst. (CIDR)Destination in CIDR notation
    Dst. PortDestination port
    NAT IPTranslation address: a single IPv4 address without a mask
    NAT PortTranslation port

    Click Save Rule.

  4. Remove rules you no longer need. In the rule row, click the delete icon and confirm with Remove in the Are you sure want to remove firewall rule N? dialog (for NAT, Are you sure want to remove NAT rule N?).

    A rule cannot be edited in place: to change it, remove the rule and add a new one with the same number.

  5. Apply the set. The Apply rules button is below the sections on the router page; the same item is available in the Actions menu, both on the page and in the Edges list row.

    Application replaces the entire set on the router, rather than adding changes. Apply a series of edits once, after the last edit.

    The button and menu item remain disabled while the router is not running, its operation has not completed, or internal initialization after its last start has not finished.

Verify the result​

The panel confirms successful application with a notification, and the Rules applied pair in General properties updates to the time when the router accepted the set. State modified appears next to it: if that time is later, the router has restarted since the set was applied.

Then reread the Firewall rules and NAT rules section tables and check that rules with the required numbers are present and removed rules are absent from the set. The columns match the form fields: for firewall rules, Action, Log, Direction, Network, Protocol, From (CIDR), From Port, Dst. (CIDR), and Dst. Port; for NAT, Action, Network, Protocol, From (CIDR), Dst. (CIDR), Dst. Port, NAT IP, and NAT Port.

Packet filter log​

If a rule has been added and applied but traffic does not behave as expected, retrieve the packet filter log from the Logs section on the router page. The section appears only if log export is enabled by the feature.edge_log_pcap feature flag in the cluster settings and the role has access to the router. The log contains packets blocked by rules with the Log checkbox enabled.

  1. Set Limit to the number of packets to retrieve.

  2. Set Period to the interval for which you need the log.

  3. Click Get file. A download link appears next to it; use the link to save the PCAP file, then open it in a traffic analyzer. If nothing was found for the interval, the section displays "No data found. Try another params.".

Log limitations:

LimitationReasonWorkaround
The log is retained for 24 hoursThe packet filter keeps only a one-day window on the routerRetrieve the log promptly. A request for an older interval returns an empty file
Exports are capped at 3000 packetsAgent limit: 0 and any value greater than 3000 are converted to 3000Narrow the interval in Period instead of increasing Limit
The Logs section is missing from the pageLog export is enabled by the feature.edge_log_pcap flag in the cluster settingsRequest that the flag be enabled at the cluster level

Troubleshooting​

The panel displays failures as notifications with text and a code, for example The edge isn't running (error code: -14005). The form highlights fields with invalid values: this is how failures -18032 (From (CIDR)) and -18037 (Dst. (CIDR)) are displayed for a firewall rule.

Editing the set (adding and removing rules):

FailureCauseResolution
-18018 Rule number below 100, -18019 Rule number above 32767The firewall rule number is outside the allowed rangeUse a number in the range 100–32767; the form shows the limits next to #. The same limits apply to removal (-18318, -18319)
-17032, -17037, -18032, -18037 Invalid CIDR valueThe source or destination is not in CIDR notation: -17032 and -17037 refer to From (CIDR) and Dst. (CIDR) in a NAT rule; -18032 and -18037 refer to the same fields in a firewall ruleEnter the network as x.x.x.x/n; use a /32 mask for a single address
-18053 Bad rule_log param valueRule logging is set to a value other than 0 or 1Control logging with the Log checkbox: it is available only for the block action
-18350 FW rule N not found for edge, -18250 NAT rule N not found for edgeThe set no longer contains a rule with that number: it was removed from another sessionReread the Firewall rules or NAT rules section table and remove the rule from the current set
-17050, -18050, -18220, -18320, -18510 Edge id doesn't existThe router was not found: the record has already been removed, or the page is outdatedReturn to the Edges list, refresh it, and reopen the router
-18803, -17003, -18003, -18203, -18303 Bad edge_id param valueThe router identifier does not look like a UUIDOpen the router from the Edges list instead of using a saved link
-403 Access deniedAnother user created the router, and the role has no cluster-level rightsEdit and apply rules as the router owner or with the Cluster master role. Reading the set remains available to all roles in its VDC
-17091, -18091, -18240, -18340Database errorRetry the edit; if the failure recurs, check the cluster database state

Applying the set and retrieving the log:

FailureCauseResolution
-14005 The edge isn't running, -25005The router is stopped, and only a running Edge accepts a rule setStart the router with the start button next to UUID and retry application
-14006 The edge start in progress, -25006Startup is still in progressWait until State shows a running machine
-14007 The edge bootstrap has not been completed yet, -25007The router is running, but internal initialization after the last start has not finishedWait and retry. Readiness is indicated by the Rules applied pair in General properties: application is available when its time is no earlier than State modified
-14040 Edge ID has not foundThe router has no rulesAdd at least one rule, then apply the set
-14010, -25010 Edge id doesn't existThe router was not foundRefresh the Edges list and reopen the router
-25030 The edge feature has not been enabledAll Edge functionality is disabled by the overarching feature.edge feature flag. This flag is checked before feature.edge_log_pcapRequest that the flag be enabled at the cluster level. While it is disabled, reading rule sets is also unavailable
-25025 The edge_log_pcap feature has not been enabledLog export is disabled by the cluster feature flagEnable feature.edge_log_pcap in the cluster settings
-25023 ts_start param value is too lowThe interval starts before January 1, 2023Move the start of the interval forward in Period: the log is retained for only one day anyway
-25024 ts_finish param value is less then ts_startThe interval ends before it startsCorrect the order of the boundaries in Period
-32602Request parameters failed validation: for example, Limit is outside the range 0–9999Check the value limits in Limit and Period
-22 Bootstrap is not done and other agent failuresThe Edge agent did not accept the set: initialization is incomplete, or the rules failed to loadThe failure text is returned unchanged by the agent; use it to investigate. Remove a rule with invalid syntax and add it again
-14004, -25004Database error or failure to forward to the agentRetry the operation; if the failure recurs, check the database and agent state

See also​

API methods​

The API operations covered on this page are edge-list-rules, edge-add-fw-rule, edge-add-nat-rule, edge-remove-fw-rule, edge-remove-nat-rule, edge-deploy-rules, and edge-get-pfloggs; see the API reference.