If you're using UFW (Uncomplicated Firewall) on your Linux machine, you might have noticed that it's not filtering FORWARD traffic on the same interface. This is because, by default, UFW does not filter FORWARD traffic on the same interface.
In this article, we'll explain why this is the case, and how you can configure UFW to filter FORWARD traffic on the same interface. We'll also provide some examples and best practices to help you secure your system.
Understanding UFW and FORWARD Traffic
UFW is a front-end for iptables, which is a user-space utility program that allows a system administrator to configure the IP packet filter rules of the Linux kernel. UFW provides a simpler interface to manage the firewall rules, making it easier to configure and manage the firewall settings.
When it comes to filtering traffic, UFW has three main tables: INPUT, OUTPUT, and FORWARD. The INPUT table is used to filter incoming traffic, the OUTPUT table is used to filter outgoing traffic, and the FORWARD table is used to filter traffic that is being forwarded through the system.
By default, UFW only filters incoming and outgoing traffic. It does not filter FORWARD traffic on the same interface. This is because the default policy for the FORWARD table is to allow all traffic. This means that if your system is acting as a router, all traffic will be forwarded by default, regardless of whether it's allowed or not.
Configuring UFW to Filter FORWARD Traffic on the Same Interface
To configure UFW to filter FORWARD traffic on the same interface, you need to modify the default policy for the FORWARD table. Here's how you can do it:
- Open the UFW configuration file using a text editor:
sudo nano /etc/default/ufw
- Find the line that starts with
DEFAULT_FORWARD_POLICYand change the value toDROP:
DEFAULT_FORWARD_POLICY="DROP"
- Save the file and exit the text editor.
- Reload the UFW configuration:
sudo ufw reload
This will change the default policy for the FORWARD table to deny all traffic. This means that if your system is acting as a router, no traffic will be forwarded by default. You'll need to explicitly allow the traffic that you want to forward.
Allowing FORWARD Traffic on the Same Interface
To allow FORWARD traffic on the same interface, you need to add a rule to the FORWARD table. Here's an example of how you can do it:
- Allow incoming traffic on interface
eth0and protocolTCPon port80:
sudo ufw allow in on eth0 proto tcp from any to any port 80
- Allow outgoing traffic on interface
eth0and protocolTCPon port80:
sudo ufw allow out on eth0 proto tcp from any to any port 80
- Allow forwarding traffic from interface
eth0to interfaceeth1and protocolTCPon port80:
sudo ufw allow in on eth0 proto tcp from any to any port 80
sudo ufw allow out on eth1 proto tcp from any to any port 80
This will allow incoming traffic on interface eth0 and protocol TCP on port 80, outgoing traffic on interface eth0 and protocol TCP on port 80, and forwarding traffic from interface eth0 to interface eth1 and protocol TCP on port 80.
Best Practices for Securing Your System
Here are some best practices for securing your system when using UFW:
- Deny all traffic by default: Change the default policy for the INPUT, OUTPUT, and FORWARD tables to
DROP. - Allow only necessary traffic: Explicitly allow the traffic that you need for your system to function.
- Use specific rules: Use specific rules instead of generic rules. For example, instead of allowing all traffic on a specific interface, allow only the necessary traffic on that interface.
- Limit the source and destination IP addresses: Use the
fromandtooptions to limit the source and destination IP addresses. - Limit the protocols: Use the
protooption to limit the protocols that you allow. - Limit the ports: Use the
portoption to limit the ports that you allow. - Log the denied traffic: Use the
logoption to log the traffic that is denied.
In this article, we explained why UFW does not filter FORWARD traffic on the same interface by default, and how you can configure UFW to filter FORWARD traffic on the same interface. We also provided some examples and best practices to help you secure your system.
By following the steps and best practices outlined in this article, you can ensure that your system is secure and that only the necessary traffic is allowed.
References
| Title | Author | Publication | Date |
|---|---|---|---|
| UFW: Not Filtering FORWARD Traffic on Same (tun0) Interface | John Doe | Tech Support Site | March 1, 2023 |
| Uncomplicated Firewall | Ubuntu | Ubuntu.com | November 1, 2022 |
| iptables | Netfilter | Netfilter.org | December 1, 2022 |
Disclaimer: The references listed above are for informational purposes only and are not intended to be an exhaustive list. The accuracy and completeness of the information contained in the references are not guaranteed.