---
title: Ensure ufw Default Deny Policy for Incoming Connections
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > OOTB Rules > Ensure ufw Default Deny Policy for
  Incoming Connections
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Ensure ufw Default Deny Policy for Incoming Connections
 
## Description{% #description %}

A default deny policy on incoming connections ensures that any unconfigured inbound network traffic will be rejected. Set `DEFAULT_INPUT_POLICY` to `DROP` or `REJECT` in `/etc/default/ufw`. Note: Any port or protocol without an explicit allow before the default deny will be blocked.

## Rationale{% #rationale %}

With a default accept policy the firewall will accept any incoming packet that is not configured to be denied. It is easier to allow acceptable usage than to block unacceptable usage.

## Remediation{% #remediation %}

### Shell script{% #shell-script %}

The following script can be run on the host to remediate the issue.

```bash
#!/bin/bash

# Remediation is applicable only in certain platforms
if dpkg-query --show --showformat='${db:Status-Status}' 'linux-base' 2>/dev/null | grep -q '^installed$' && { dpkg-query --show --showformat='${db:Status-Status}' 'ufw' 2>/dev/null | grep -q '^installed$'; }; then

ufw default deny incoming

else
    >&2 echo 'Remediation is not applicable, nothing was done'
fi
```

## Warning{% #warning %}

Changing firewall settings while connected over network can result in being locked out of the system.
