How To Add Iptables Rules In Ubuntu?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
1. Use the iptables command
The most straightforward way to add a new rule in iptables is to use the iptables command.
For example, to add an input rule that denies connections from a specific IP address, you can use the following command:
sudo iptables -A INPUT -s <ip-address> -j DROP
2. Use the ufw command
The Uncomplicated Firewall (ufw) is an easy-to-use command-line interface for managing iptables rules.
To add a new rule using the ufw command, use the following syntax:
sudo ufw allow from <ip-address>
3. Use a configuration file
You can also manage your iptables rules using a configuration file.
The iptables configuration file is located at /etc/iptables/iptables.rules. To add a new rule to the file, simply add the rule to the end of the file.
For example, to add an input rule that denies connections from a specific IP address, you can add the following line to the end of the file:
-A INPUT -s <ip-address> -j DROP