Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Netfilter-persistent is a useful tool for managing and saving iptables rules on Linux systems, including the Raspberry Pi. It allows you to create persistent firewall rules that are automatically applied on boot, ensuring your network configurations remain consistent.
Netfilter-persistent is a script that works with iptables and ip6tables to save and restore firewall rules. This is particularly useful for Raspberry Pi users who need to maintain consistent network security settings across reboots.
To use netfilter-persistent on your Raspberry Pi, you need to have iptables installed. Most Raspberry Pi distributions come with iptables pre-installed, but you can ensure it's installed by running:
sudo apt-get update
sudo apt-get install iptables
Next, install netfilter-persistent and its dependencies:
sudo apt-get install netfilter-persistent
sudo apt-get install iptables-persistent
Create Firewall Rules: Use iptables commands to create your desired firewall rules. For example, to block all incoming traffic on port 80, you would use:
sudo iptables -A INPUT -p tcp --dport 80 -j DROP
Save the Rules: After setting up your rules, save them using netfilter-persistent:
sudo netfilter-persistent save
This command saves the current iptables rules to /etc/iptables/rules.v4
and /etc/iptables/rules.v6
for IPv4 and IPv6, respectively.
Restart the Service: To ensure the rules are loaded on boot, restart the netfilter-persistent service:
sudo systemctl restart netfilter-persistent
To verify that your rules are correctly saved and loaded, you can list the current iptables rules:
sudo iptables -L
This command will display the active rules, confirming that your configurations are in place.
If your rules are not being applied on boot, check the status of the netfilter-persistent service:
sudo systemctl status netfilter-persistent
Ensure that the rules are correctly saved in /etc/iptables/rules.v4
and /etc/iptables/rules.v6
.
If netfilter-persistent does not meet your needs, consider using ufw
(Uncomplicated Firewall) as an alternative. It provides a simpler interface for managing firewall rules and is also compatible with Raspberry Pi.
sudo apt-get install ufw
Use ufw
to enable and configure your firewall rules:
sudo ufw enable
sudo ufw allow 22/tcp