Introduction
This article explains how to configure UFW (Uncomplicated Firewall) to forward a range of UDP ports for containers. UFW is a front-end for iptables, providing a user-friendly interface to manage firewall rules. This setup is essential when running applications inside containers, which require access to specific ports.
UDP Forwarding with UFW
To forward a range of UDP ports using UFW, follow these steps:
Prerequisites
Make sure:
- Your system is running Ubuntu or another Debian-based distribution.
- You have the necessary permissions to modify firewall rules.
Edit UFW Rules
Edit the UFW rules file:
sudo nano /etc/ufw/before.rules
Add UDP Forwarding Rule
Add the following rule:
# UDP Forwarding for containers
# eth0 is the interface name, replace it with your container network interface
# Replace 49000-60000 with the desired port range and 10.100.100.2 with the container's IP address
APRULE name="UDP_FORWARD_CONTAINER" \
state related,established \
prot udp \
src 0.0.0.0/0 \
dst 10.100.100.2/32 \
port 49000:60000 \
target DNAT \
to-destination 10.100.100.2:
Save and Reload Rules
Save and close the file:
Ctrl+X, Y, Enter
Reload UFW rules:
sudo ufw reload
Summary
In this article, we have learned how to configure UFW to forward a range of UDP ports for containers. We have also covered the prerequisites, editing UFW rules, adding a UDP forwarding rule, and saving and reloading rules.