Guest User!

You are not Sophos Staff.

This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sophos Flow: Firewall and NAT

Hello folks,

Every time I need to create a NAT rule I must go back to the Sophos video that explains it. The reason - I can't remember it because it is so counter intuitive. I hope you can help me figuring out a few key moments. 

The video:

1) A long time ago there was a pinned post in the community, that outlined the foundation and main rules to follow when configuring Sophos Firewalls. One of them dictated to never use Interfaces, where the Network definition was expected (IP). Indeed, I've seen a lot of cases where instead of #Port 2 you created/used the IP definition for hte same WAN, and everything worked like a charm.

In this video, however (@12:23), the instructor is using the alias for the WAN interface in the firewall rule. She does the same thing when creating the NAT @13:38.

Q: So is it OK now to use interfaces under Source and Destination Networks when creating the Firewall and NAT rules?

2) Let's rewind back to @12:23 when the instructor creates the firewall rule for DNAT.

Destination zone: LAN ("as that is the location of the actual Webserver"). OK...

Destination Networks: interface Port6:0 ("because users request traffic will arrive on XG on its WAN interface before it is NATed to Webserver").

Services: <pre NATed service>

So based on the instructor, the firewall rule kicks in before it is NATed to Webserver. I will pretend that I didn't notice the contradiction in the rule that the destination zone = LAN is a post-NAT criteria, but I'll ask the other confusing thing:

Q: I am currently troubleshooting a DNAT (it's not working). During the troubleshooting I am noticing that my DNAT rule counter keeps going up, while the associated firewall rule sits at zero in/out. How is this possible if the firewall rule kicks in before NAT, as per official video?



This thread was automatically locked due to age.
  • Hello ,

    Thank you for reaching out to the community, have you referred the following two Docs related to the DNAT, they might help:

    1.) Create DNAT and firewall rules for internal servershttps://docs.sophos.com/nsg/sophos-firewall/18.5/Help/en-us/webhelp/onlinehelp/AdministratorHelp/RulesAndPolicies/NATRules/RulesPoliciesCreateDNATAndFirewallRulesForInternalServers/index.html

    2.) Add a DNAT rule with server access assistanthttps://docs.sophos.com/nsg/sophos-firewall/18.5/Help/en-us/webhelp/onlinehelp/AdministratorHelp/RulesAndPolicies/NATRules/NATDNATServerAccessAssistant/index.html

    Thanks & Regards,
    _______________________________________________________________

    Vivek Jagad | Team Lead, Global Support & Services 


    Sophos Community | Product Documentation | Sophos Techvids | SMS
    If a post solves your question please use the 'Verify Answer' button.

  • Essentially you have to understand: There are three different actions of traffic: Routing, Firewalling(Allow/Deny) and NATing (changing the traffic). 

    See: https://community.sophos.com/sophos-xg-firewall/f/recommended-reads/122357/life-of-a-packet-sophos-firewall

    One of the confusions starts, when NAT kicks in, changing the Destination but not the Zone. 

    I have a rule of thumb for this, which worked great for me: Change the Destination Zone, not the Destination IP in the Firewall rule.

    Means: FW Rule IP #Port1 and Zone LAN. This will work. 

    If your firewall is not hitting, it is not matching. Simple as that. So NAT will hit without firewall has to hit. See above. It works independly. So the NAT will do its stuff, and if the firewall denies the traffic (not matching-Default drop) or another rule hits, your rule will not match.

    Check the packet capture on the Webadmin of your firewall to see NAT and FW rule for the traffic. Use the configure - BPF String to dump specifically for your traffic. 

    __________________________________________________________________________________________________________________

  • I am very familiar with route, firewall and translation. The problem is that I find DNAT configuration not aligning with how the rest of scenarios are configured in the fw rules. When we do MASQ or SNAT, our destination zone and IP are in the same "realm" (i.e. WAN Zone, WAN IP). Same thing with Inter-LAN rules (Destination Zone DMZ, IP will also be in the DMZ). It's only the DNAT that has Zone = Internal and IP = External.

    If the firewall rule is processed before NAT, then there is no way the packet can match the LAN zone without being translated first.

    I am sure Sophos has an implementation that makes it all work, perhaps some sort of NAT "simulation" right before the FW rule that doesn't actually translate the DstIP, but only "checks" in which zone the packet would land after translation, so that the firewall can process it as Dst.Zone=LAN. The question is  - why it's not doing the same thing with the IP address and the service?

    It just doesn't make sense to me that "we indicate LAN zone becasue that's what is going to happen after translation, but we indicate WAN IP and pre-NAT service right in the same rule, because that's what will happen before translation.

    Also this - 

    The link you provided confirms once again that the ingress order of processing of a packet is DoS > FW Rules > DNAT > Route. If the firewall rule isn't hitting and the packet is discarded, then how come I am seeing NAT counters go up? I have no other inbound rules allowing WAN>LAN. The packet is discarded 100%

  • You are right with "it is so counter intuitive" for creating DNAT rules.

    Because of this, i use the DNAT- wizzard every time and has 0 problems (but i delete the 1-2 additional unnecessary NAT rules)


    Dirk

    Systema Gesellschaft für angewandte Datentechnik mbH  // Sophos Platinum Partner
    Sophos Solution Partner since 2003
    If a post solves your question, click the 'Verify Answer' link at this post.

  • So let me put some things into context. NAT is not aware of Zones. So you are actually not changing the Zone in any terms with NAT. 

    Firewall will hit multiple times in fact in this terms. So the life of a packet is actually some sort of "wrong" as it has multiple steps within this step "Firewall rule processing". There is a lot going on in this step. It is not wrong in terms of processing, instead it is not completely lay out, what this firewall rule processing is doing. So the "lookup of zones" is actually aware of NAT. So it actually checks for the NAT rule table. But it does not change anything (as NAT is not done here). 

    The DNAT Implementation will actually do something with the traffic. 

    Think about life of a packet as: This is what is the firewall is doing with a packet. So Changing the Zone is nothing, the packet is aware of. The packet does not know, which zone it belongs. It only knows the meta data (destination Ip, source ip, payload etc.). Zone is not something, the header is aware of. So the firewall processing unit is already changing the zone. Because otherwise we cannot do it anymore. DNAT cannot change the Zone, as DNAT implementation is not aware of zones. 

    BTW: Even if firewall is dropping the traffic, the other decisions will still be handled. So to speak, if firewall denies, the firewall still goes trough the other ingress steps. After the Routing decision is met, the firewall will drop the traffic. So the firewall module is not dropping the traffic, it flags the traffic to be dropped. 

    __________________________________________________________________________________________________________________

  • I understand that Zones are not a part of OSI stack. It's an extension of Sophos implementation. I also understand that NAT isn't Zone aware. However. The firewall rule is zone aware because it contains the Zone criteria that has to match. Meaning that there is a pre-NAT, pre--FW process that adds the Zone data to the packet before it's matched against the firewall. Most likely the Zone is determined based on the pre-NAT, pre-FW "lookup" you mentioned above.

    My point is that when you know what is going on under the hood (i.e. lookups, zone tagging, etc) it is easy to make sense why the UI configuration is the way it is (i.e. Dst zone is internal, but the Dst IP is external).

    Not knowing that makes it all look inconsistent with configuration of the firewall rules for other scenarios (MASQ, SNAT, Inter-LAN/VLAN).

    NAT before FW would have resolved this inconsistency, but I guess there is a serious reason why Sophos decided to place NAT after FW.

    Lastly, I didn't know that all other ingress steps will take place even if the firewall dropped the packet? Doesn't that seem like a waste of resources?

  • Changing the processing flow to drop the packet before those decision are made is actually worse. 

    And one important part: The change was implemented in V18. V17.5 and earlier had NAT within a firewall rule. So no confusion there. So Sophos implemented a NAT by not changing the inner works of the platform, instead changing the implementation of the configuration part. This means, the inner works is still "the same" but the NAT rules are decoupled. 

    You can even see this: By looking at a drop packet capture on the CLI, you see all criteria are already there (PBR, NAT zones etc.). 

    Most people, like above mentioned, are using the Wizard for a quick implementation. People aware of the way the firewall works, will use there own firewall rules. In the end, as long as there is a simple way to implement a DNAT, it is fine for me.

    __________________________________________________________________________________________________________________

  • DNAT wizard is good when you don't need port translation, only forwarding. During the wizard you're only prompted for the post-NAT listening port. Then it uses the same port number for original service. I killed WebAdmin access to the firewall this way years ago :))

    Thanks for the replies. I hope it will be more intuitive and easier to remember the "zone - internal ; IP:service - external" after this conversation.