Adding Firewall Rules with iptables on Ubuntu Linux involves the following steps. At Bobcares, with our Server Management Service, we can handle your issues.
How to Add Firewall Rules with iptables on Ubuntu Linux?
iptables is a tool that lets us manage the firewall rules on a Linux server to improve security by filtering and inspecting network traffic. iptables operates by comparing network traffic against a set of rules. Setting up firewall rules with iptables on Ubuntu Linux involves creating rules to control the flow of traffic to and from the server. Here’s a step-by-step guide to set up basic firewall rules using iptables:
Key Concepts
1. Chains:
INPUT: Handles incoming packets.
FORWARD: Handles packets being routed through the server.
OUTPUT: Handles outgoing packets.
2. Default Policy: Determines what happens to packets that don’t match any rule (usually ACCEPT or DROP).
Basic Commands
1. List current rules: This shows rules for INPUT, FORWARD, and OUTPUT chains. By default, all chains might be set to ACCEPT.
sudo iptables -L
2. List rules with numbers:
sudo iptables -L --line-numbers
Configuring Rules
1. We can allow established connections with the below code:
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
2. To allow SSH traffic, use the code:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
3. Allow HTTP traffic with the following code:
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
4. Block all other traffic (after setting up necessary rules):
sudo iptables -P INPUT DROP
Managing Specific IPs
1. Allow specific IP (whitelisting):
sudo iptables -A INPUT -s xx.xx.xx.xx -j ACCEPT
2. Block specific IP using code:
sudo iptables -A INPUT -s xx.xx.xx.xx -j DROP
Saving and Restoring Rules
1. Save current rules using the code:
sudo iptables-save > /etc/iptables/rules.v4
2. Restore saved rules using :
sudo iptables-restore < /etc/iptables/rules.v4
3. Install iptables-persistent (to load rules at boot):
sudo apt-get install iptables-persistent
By following these steps, we can configure iptables to enhance the security of the Ubuntu Linux server.
[Need to know more? We’re available 24/7.]
Conclusion
To sum up, our Tech team went over the steps to Add Firewall Rules with iptables on Ubuntu Linux. By following these steps, you will have setup a basic set of firewall rules using iptables
on the Ubuntu server.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments