OpenSource For You

pfSense: Adding Firewall Rules to Filter Services

PfSense is an open source firewall, router and UTM (unified threat management) distributi­on based on FreeBSD. This is the third article in the series on pfSense, and it helps readers in designing and configurin­g firewall rules as per their requiremen­ts.

- By: Rajesh M. Deodhar The author is an IS auditor, network security consultant and trainer with more than 25 years of industry experience. He is an industrial electronic­s engineer with CISA, CISSP and DCL certificat­ion. Please feel free to contact him on

The first two articles in this series described the basic pfSense set-up, installati­on and configurat­ion of the Squid Proxy server, SquidGuard proxy filter, and configurat­ion of dual WAN failover. This article starts off from the point when pfSense has been configured, at the end of the second article. It then continues to configure the firewall to filter services – to allow internal computer systems to access required websites/IP addresses located in the Internet using permited services by configurin­g firewall rules. Please refer to the earlier articles to establish a firewall in dual WAN failover.

What is services filtering?

Many people view a firewall as a device to block access to undesirabl­e websites, which is partially true. Emphasis must also be given to blocking requests from the internal network towards the Internet or external network, using undesirabl­e services. This control is still not seen in many implementa­tions.

For example, a firewall not configured to block undesirabl­e services will not block malicious software such as viruses, worms, spyware, etc, from sending emails out using email services such as SMTP or from sending outgoing traffic using non-standard ports. This type of traffic could also lead to blacklisti­ng of your static IP address.

It is crucial that services blocking is enabled along with website filtering to ensure correct firewall configurat­ion.

The concept of the port

To explain it in simple terms, imagine a server connected to a single client by a crossover cable. This server is running three different services – HTTP, SSH and FTP. The client system is trying to access these services simultaneo­usly using only one physical cable. This gives rise to two questions: 1. How does the server differenti­ate between the requests received from different clients? How does it determine which packet is for which service? 2. How does the client differenti­ate between the replies received from the server? How does it determine which packet is received as reply to which request sent earlier? The answer lies in the concept of a port – different services run on different ports. The HTTP service runs on Port 80, SSH on Port 22, FTP on Port 21, and so on. In all, there are 65,535 ports. While sending requests to the server, the client sends the IP address of the server as part of the IP header and the port number for the service as part of the TCP header. In addition, the client also sends the self IP address as the source IP address, and adds a randomly generated source port as the source port number. While replying, the server reverses the source and the destinatio­n IP addresses so that the packet reaches the client, and also reverses the source/destinatio­n port numbers for the client to understand which packet belongs to which service request. The handshake remains the same for multiple clients and servers. The source and destinatio­n IP addresses identify the client and the server, while the source and destinatio­n ports identify the service request and the reply. See Figure 1 for quick understand­ing. In firewall parlance, the terms ‘ports’ and ‘services’ are often used interchang­eably, and mean the same thing. Please note that this explanatio­n is only to simplify the concept of ports. You can refer to a more detailed explanatio­n of the TCP/IP handshake on Wikipedia.

The firewall configurat­ion scenario

Let us consider a typical requiremen­t for a company, which would be to allow access depending on the work profile of employees. Let’s assume that there are three groups – admins, engineers and accountant­s with various access requiremen­ts.

The first step is to prepare a basic Access Control List (ACL), a sample of which is shown in Table 1. We will use this ACL to configure pfSense for this article.

Discussion­s should be held with all computer users to try and find all the services and websites being used by them, in order to create ACLs. Employees should be asked whether they use a specific website frequently or not. For instance, during such discussion­s, a website being used once in three months might get identified, which runs on a non-standard port 8080. In the example given in Table 1, it could belong to the Pune Municipal Corporatio­n local body tax division.

Please discuss in detail with computer users and have the patience to create these lists. The more details you get, the fewer reconfigur­ation calls will be needed later.

Identify internal IP addresses, external IP addresses, external host names and services required for controllin­g access, etc. For example, for allowing Gmail access, we need to configure three groups: a. GmailServi­ces Port alias group containing the following

TCP services (ports) required for Gmail access: IMAPS – 993 SMTPS – 465 POP3S – 993 Submission – 587 b. GmailServe­rs IP alias group containing IP addresses for the following servers: smtp.gmail.com imap.gmail.com c. Group of internal systems required to access Gmail using the mail client. Think about how to group various internal/external IP addresses and services to create the minimum number of access rules. Create IP and ports alias lists from Firewall – Alias menus. Note: Planning before implementi­ng rules is the best way – there are no shortcuts. Once the aliases are ready, go to Firewall – Rules – LAN and proceed to create the desired access rules as per the requiremen­ts already defined in Table 1.

From the Source dropdown box, select Single host or alias. Type the name of the predefined alias in the box in front – pfSense will auto display all matching aliases.

Since this firewall is configured with dual WAN, click on Display Advanced under Extra Options and select DualWAN Gateway.

Similarly, create the additional required rules to allow traffic from the source towards the destinatio­n by using Services. For example, to allow the computer from Admin group to access Gmail using a mail client, create the following rule: ct the pass rule with source as Admin group.

the destinatio­n with Gmail servers using Gmail services. the gateway and dual WAN to ensure this rule works with both the WAN interfaces. Knowledgea­ble readers may revisit ACL in Table 1 before reading further, to check if any rule is missing.

At the time of installati­on, pfSense configures a default rule, which allows all traffic from the LAN net towards any destinatio­n. Once all rules are configured, disable this default rule by clicking the √ button.

Note: A default anti lockout rule is configured to ensure admin access to the firewall from the internal network. Take care not to disable this rule, otherwise you wil be locked out of the firewall.

Diagnostic­s

Often, the implemente­r will stare at various inaccessib­le sites/ services after such rules are implemente­d. The best way to diagnose these issues is to browse Status – System Logs – Firewall.

All ‘blocked’ log entries will be seen on this page, ordered chronologi­cally. The button can be used to filter the results based on the source IP address, destinatio­n IP address, etc.

Missing rule?

Readers may revisit the ACL in Table 1 before reading the next sentence.

Once configurat­ion is implemente­d according to the ACL defined in Table 1, LAN users will not be able to ping the Internet or even the firewall itself, since ICMP packets are not allowed towards the firewall and towards the Internet. The importance of ICMP packets for troublesho­oting cannot be emphasised enough. Here, two rules will be required to allow ping requests towards pfSense and towards external DNS servers, at the minimum. Note: To ensure correct documentat­ion, update the ACL table first and then change the correspond­ing rule in the firewall.

An important configurat­ion for accessing Gmail via the client

Readers will definitely notice that the imap.gmail.com and smtp.gmail.com IP addresses keep changing practicall­y every time. Due to this, it is difficult to create a rule to allow outgoing traffic towards these domain names.

About using FQDN for the host alias, the pfSense website has the following caveat: “DNS names that use very low TTLs and change frequently, such as round robin entries, are not reasonable to use in this fashion. This means that large sites like google.com, which return a different set of IP addresses with each query, would not be viable in an alias.”

Thus, using various domain names such as smtp.gmail. com, imap.gmail.com, etc, as alias entries will not work

properly in setting firewall rules.

This can be overcome in two ways: 1. Search all Gmail IP addresses, and allow traffic on GmailServi­ces towards all these IP addresses. This configurat­ion will require considerab­le effort. 2. Configure Domain Override settings under DNS Resolver under Services to resolve smtp.gmail.com and imap.gmail. com to correct static IP addresses. Further, configure a rule to allow all traffic for GmailServi­ces towards these IP addresses. Use the following steps: 1. Find the current IP address belonging to such FQDNs

by pinging them. 2. Configure the DNS resolver to resolve these URLs to

these IP address(es). 3. Use these IP addresses to configure groups and

firewall rules. 4. Ensure that all users use pfSense as their DNS server so that the IP address for overridden domains will resolve to the preconfigu­red IP address. Note that systems configured with DNS servers other than pfSense will get different IP addresses for these overridden domains and access will be blocked.

Managing firewall configurat­ion changes

As a good change management practice, the following sequence should be observed: 1. Back up the firewall before making any changes – this will enable a rollback of settings if something goes wrong after the change. 2. Make changes in the documentat­ion such as the ACL table

first – to ensure the documentat­ion is up to date, always. 3. Make changes to firewall settings, ensuring comments for

created rules. Implement only documented rules. 4. Test the change to ensure it is giving only the desired

access. 5. Back up the firewall after the change is complete.

Following these steps will ensure correct and up-to-date documentat­ion of implemente­d firewall rules, which will definitely help future firewall troublesho­oting, reconfigur­ation and migration.

Interestin­g pfSense features related to firewall rules

pfSense provides easy addition of pass or drop rules by clicking the signs in the destinatio­n column. Once such a rule is created, do not forget to inspect this rule from Firewall – Rules – LAN, and change the default gateway as well as add a proper comment for easy identifica­tion at a later date.

Check logs of firewall rule changes from the menu Diagnostic­s – Backup and Restore. Here, details of changed rules can be checked by comparing the earlier rule and changed rule by selecting radio buttons correspond­ing to the required rules and clicking on them.

Latest available update

Please update pfSense to the latest new minor release version 2.3.1-RELEASE-p5 which was built on June 16, 2016. Details of new features and changes for this release are available at https://doc.pfsense.org/index.php/2.3.1_New_ Features_and_Changes#Update_5.

 ??  ?? Figure 5: LAN to WAN firewall rules
Figure 5: LAN to WAN firewall rules
 ??  ?? Figure 4: DNS rules
Figure 4: DNS rules
 ??  ?? Figure 3: IP aliases
Figure 3: IP aliases
 ??  ?? Table 1: Access Control List
Table 1: Access Control List
 ??  ?? Figure 2: GmailServi­ces
Figure 2: GmailServi­ces
 ??  ?? Figure 1: Concept of ports
Figure 1: Concept of ports
 ??  ??
 ??  ?? Figure 6: Domain overrides
Figure 6: Domain overrides

Newspapers in English

Newspapers from India