iptables command in Linux and it perimeters

iptables command in Linux and it perimeters

The iptables command in Linux is used to manage the netfilter firewall rules. Netfilter is the packet filtering framework within the Linux kernel that allows you to control and filter network traffic. The iptables command provides a user-friendly interface to interact with netfilter and set up rules for packet filtering, NAT (Network Address Translation), and packet mangling.

Here’s a table explaining some of the main parameters and options of the iptables command:

ParameterDescription
-AAppend a new rule to a chain.
-DDelete a rule from a chain.
-PSet the default policy for a chain.
-IInsert a rule at a specific position in a chain.
-sSource IP address or network.
-dDestination IP address or network.
-pProtocol (e.g., tcp, udp, icmp).
--sportSource port (only for outgoing packets).
--dportDestination port (only for incoming packets).
-jTarget or action (e.g., ACCEPT, DROP, REJECT).
-iInput network interface.
-oOutput network interface.

Examples of using iptables:

  1. Allow SSH (port 22) incoming traffic:
Bash
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  1. Allow HTTP (port 80) and HTTPS (port 443) incoming traffic:
Bash
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
  1. Allow outgoing DNS (port 53) traffic to specific DNS servers:
Bash
sudo iptables -A OUTPUT -p udp --dport 53 -d 8.8.8.8 -j ACCEPT
sudo iptables -A OUTPUT -p udp --dport 53 -d 8.8.4.4 -j ACCEPT
  1. Drop incoming traffic from a specific IP address:
Bash
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
  1. Set the default policy to DROP for incoming and outgoing traffic:
Bash
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT DROP
  1. Allow established connections:
Bash
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
  1. Enable NAT (Network Address Translation) to allow internet access for local network devices:
Bash
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Remember that iptables rules are stateless by default, so you need to explicitly allow incoming and outgoing traffic for established connections as shown in example 6 above. Additionally, these are just basic examples, and in real-world scenarios, you may need more complex rules to suit your specific network requirements.

After configuring iptables rules, it’s crucial to save them to apply them on system reboot. The specific method to save rules depends on your Linux distribution. Consult your distribution’s documentation for more information.

Total
2
Shares

Leave a Reply

Previous Post
how to enable packet filtering in Linux

how to enable packet filtering in Linux

Next Post
Non-Technical Aspects of Security Audit: Enhancing Organizational Cybersecurity

Non-Technical Aspects of Security Audit: Enhancing Organizational Cybersecurity

Related Posts