Skip to content
Avanet

Sophos Firewall Black Hole DNAT: Block Bad IPs

As soon as services are reachable from the internet, unwanted traffic usually appears quickly: port scans, login attempts, known botnets or access from countries where no users are expected. On Sophos Firewall, such sources can be blocked at several levels.

This article explains two common approaches:

  • block countries or source networks with a Firewall Rule
  • translate unwanted sources into nowhere with a Black Hole DNAT Rule

In addition, we recommend Sophos Firewall Threat Feeds so that known malicious IPs, domains or URLs can be blocked automatically.

Which method fits when?

MethodSuitable forTypical use
Firewall Rule with DropBlocking traffic based on Source Country, Source Network or Source HostBlock countries, block individual networks, maintain known Bad IP lists manually
Black Hole DNATRedirecting unwanted traffic to a non-existent internal IPIntercept traffic to published services early
WAF Blocked countriesWeb servers published through WAFBlock countries directly in a WAF rule
Threat FeedsDynamic lists of known malicious sourcesAutomatically block botnets, scanners, malware infrastructure and known attacker IP addresses

The right method depends on where the traffic is technically processed. Sophos points out that Firewall Rules do not always apply to traffic going to a Hosted Address used in WAF. In those cases, a WAF country rule or a Black Hole DNAT Rule is often more suitable.

Block countries with a Firewall Rule

For general country blocking, one can create a Firewall Rule with Drop.

Menu path:

Rules and policies > Firewall rules

Recommended fields:

FieldValue
Rule namedescriptive name, for example BLOCK_COUNTRY_PANAMA
Rule positionTop
ActionDrop
Source zonesAny
Source networks and devicescountry, country group, IP list or host group
During scheduled timeAll the time
Destination zonesAny
Destination networksAny
ServicesAny or a defined service

For country blocking, it is important not to set Source zones and Destination zones too narrowly. If only WAN is entered as Source zone, the rule may not apply to all relevant traffic paths.

Black Hole DNAT for unwanted sources

A Black Hole DNAT Rule translates traffic to a destination that does not exist in the network. The traffic therefore goes nowhere and does not reach the actual service.

This is especially useful when a service is published with DNAT and specific sources should be intercepted before the real port forwarding rule.

Sophos Firewall Add NAT rule as Black Hole DNAT for Bad IPs and countries
Sophos Firewall - Black Hole DNAT Rule for Bad IP list and countries

Example:

FieldValue
Rule nameBLOCK_BAD_IPS_COUNTRIES
Rule positionTop
Original sourceBad IP list, country or country group
Original destinationpublic WAN IP or WAN host object
Original serviceAny or the published service
Translated source (SNAT)Original
Translated destination (DNAT)dummy host that does not exist
Translated service (PAT)Original
Inbound interfaceAny
Outbound interfaceAny

The dummy host should use an IP address that does not exist in the local network and is not routed. It is important that this rule sits above the actual DNAT rules. NAT rules are processed from top to bottom. If the normal DNAT rule matches first, the Black Hole DNAT Rule is too late.

Why rule order is critical

With NAT rules, the first matching rule wins. A Black Hole DNAT Rule therefore has to be placed very high up, usually at the top of the NAT rule table.

Example order:

  1. Black Hole DNAT for Bad IP list and blocked countries
  2. specific DNAT rules for published services
  3. special SNAT rules
  4. general MASQ rule for outbound traffic

The same principle applies to Firewall Rules: specific block rules must sit above general allow rules. Otherwise, traffic may already have been allowed before the Drop rule is checked.

Do not leave Source on Any unnecessarily

For published services, the Source should be restricted as much as possible.

Useful sources can be:

  • individual public IP addresses
  • networks of partners or branch offices
  • countries from which access is expected
  • FQDN Hosts or DNS Host Groups, where appropriate
  • maintained Host Groups with allowed admin IP addresses

Any only makes sense if the service really has to be reachable worldwide. In that case, additional safeguards should be enabled: logging, IPS, MFA where possible, strong authentication, up-to-date target systems and Threat Feeds.

Use Threat Feeds as an additional layer

Manual lists and country rules are static. Attacker infrastructure changes continuously. That is why we additionally recommend Sophos Firewall Threat Feeds.

Threat Feeds are especially helpful for:

  • known scanner IP addresses
  • botnets
  • malware infrastructure
  • compromised hosts
  • dynamically maintained Bad IP lists

This avoids having to maintain every single IP manually. The firewall can block known bad sources before they reach the published service.

Typical mistakes

MistakeImpact
Black Hole DNAT is below the normal DNAT ruleThe normal DNAT rule matches first, so the block rule does not apply
The dummy destination actually exists in the networkTraffic unexpectedly lands on a real system
Source is maintained differently in the NAT rule and Firewall RuleRules become hard to understand and drift apart
Country blocking is used as the only protectionBots from allowed countries can still attack
Logging is disabledLog Viewer does not clearly show which rule matched

Troubleshooting

If a block rule does not apply, check the following in this order:

  1. Is the NAT or Firewall Rule really above the allow rules?
  2. Does the source IP match the Bad IP list or selected country?
  3. Is the traffic processed by a WAF rule, DNAT rule or Firewall Rule?
  4. Is logging enabled on the affected Firewall Rule?
  5. Does Log Viewer show the expected Firewall Rule ID or NAT Rule ID?
  6. Is the traffic visible in Diagnostics > Packet capture?

For analysis, Firewall rule not matching: Check order, matching and logs, Using Packet Capture in WebAdmin and Understanding NAT on Sophos Firewall: SNAT, DNAT, MASQ, PAT also help.

Further information