The Juniper SRX firewalls have a special application layer gateway (ALG) for the DNS protocol. This ALG performs the following tasks:
- Closes the session as soon as a DNS reply is seen.
- Limits the maximum message length.
- Drops packet when domain name is more than 255 bytes or the label is more than 63 bytes.
- Decompresses points and detects loops.
- Performs DNS Doctoring.
Some of these functions are interesting to provide a little bit more security but most of the have major drawbacks and their default settings are just plain stupid. The default maximum message size is 512, even though everyone has been using EDNS0 for years. DNS doctoring is enabled by default, very poorly documented and causes unexpected changes in DNS replies. I'll explain the issues a bit more in detail and then suggest what I would consider to be a better default configuration.
Feel free to skip the rant :)
Closing sessions when a response is received
Closing the session as soon as the DNS server responds sounds like a very good idea to reduce the number of sessions in use on the firewall. DNS transactions are typically just two packets, waiting for the UDP session timeout every time would mean the firewall has to keep track of a lot more sessions and as most will probably know, DNS is the easiest way to kill stateful firewalls.
The drawback here is that the ALG does not keep track of the DNS transaction IDs, it closes the session as soon as a reply packet is seen. If you have an ancient DNS server which sends all its requests from the same source port, this will cause problems when there is a lot of DNS traffic. The DNS server may send multiple requests in parallel to a remote server for different names, but as soon as the first response is received, the ALG closes the session and the subsequent responses are dropped.
In practice this isn't that much of an issue nowadays. Everyone should be using random source ports on their DNS servers, for security reasons. But years after the Kaminsky hype, there are still servers that haven't been patched.
Limiting the message length to 512 bytes
I have no idea why Juniper even implemented this "feature", let alone make it the default behavior. When the first SRX was released, EDNS0 was already used by most DNS servers and that requires the firewall to allow larger DNS packet sizes.
EDNS0 is an extension which allows for larger DNS packet sizes. The original RFC only allowed 512 bytes, but now that more and more domains are switching to IPv6 and start using DNSSEC, responses are often larger than that. Nearly all DNS servers support EDNS0 and will attempt to to use it. The problem is that the SRX will block the responses, the DNS server waits for a timeout and then retries with a smaller packet size, which will get a response. To the end user, it will appear as if "the internet is slow".
BIND based name servers will generate a lot of these log messages:
named: success resolving 'news.bbc.co.uk/AAAA' (in 'bbc.co.uk'?) after reducing the advertised EDNS UDP packet size to 512 octets
Luckily this behavior can be fixed in configuration. I would recommend everyone using the DNS ALG to increase the permitted message size:
set security alg dns maximum-message-length 8192
DNS Doctoring is a functionality where the firewall will look at DNS responses from your DNS servers for addresses that have a static NAT rule defined and will then change the IP in the DNS response to the NAT address. This behavior is wrong in so many ways. There is very little documentation about this - as far as I know this behavior gets triggered when both the DNS server and the response have a static NAT rule, but I may be wrong. If you think you need functionality like this, you should rethink your DNS infrastructure. Other than it being an extremely ugly kludge, it doesn't always work and will fail in the future if you decide to use DNSSEC.
When this feature was first introduced, it couldn't even be disabled. But in more recent JunOS releases it can be disabled using the following command:
set security alg dns doctoring sanity-check
Known limitiation: DDNS Updates
As documented on the Juniper KB, the SRX DNS ALG does not permit DDNS updates. Especially when the SRX is used as an internal firewall, separating clients from their Active Directory DNS servers, this can be a problem. Many people rely on DDNS to register client or server names in DNS. The SRX will drop these registrations, resulting in missing or outdated DNS records. The only solution until now is disabling the DNS ALG:
set security alg dns disable
There are no CLI commands to see how much traffic was dropped by the ALG, but the information can be obtained from the forwarding daemon directly:
admin@srx> request pfe execute target fwdd command "show usp alg dns stats"
SENT: Ukern command: show usp alg dns stats
GOT: dns-alg init state: 1
GOT: dns-alg (total 34)
GOT: pkts received 32265728
GOT: pkts received NULL jbuf 0
GOT: pkts received dup NULL jbuf 0
GOT: pkts received ipfrag 0
GOT: pkts received V6 181659
GOT: pkts received V4 32084069
GOT: pkts invalid 0
GOT: pkts examine 32119585
GOT: pkts reply 15771693
GOT: pkts truncated message 2448
GOT: pkts oversize message 1
GOT: parse oversize name 0
GOT: parse oversize label 0
GOT: oversize compression pointer 0
GOT: undersize compression pointer 1
GOT: pkts parse quesion fail 3
GOT: pkts parse answers fail 0
GOT: pkts parse authority fail 227501
GOT: pkts parse additional fail 3
GOT: pkts parse fail 227507
GOT: pkts NAT need 2599821
GOT: pkts NAT V4 need 0
GOT: pkts NAT V6 need 0
GOT: pkts NAT xlated 0
GOT: pkts NATPT need 0
GOT: pkts DUP A query 0
GOT: pkts Dup A query fail 0
GOT: pkts receive A response 0
GOT: pkts receive DUP A response 0
GOT: pkts xlate A2AAAA fail 0
GOT: pkts xlate A2AAAA 0
GOT: session interest 13808061
GOT: session not interest 91325
GOT: pkts update name offset 0
GOT: max message length 8192
LOCAL: End of file
TL;DR: Recommended Default Config
For branch SRX devices, I would use the following default configuration:
This maintains some of the ALG advantages and fixes the annoying default behavior.
When you need to allow DDNS through the firewall, the only option is to disable the ALG entirely: