IP Tables

  • Allows system administrators to define rules that control how incoming and outgoing traffic is handled

Important commands:

iptables --version - Command to check iptables version


iptables -L - To check the list of input and output traffic


iptables -A INPUT -p tcp -s 172.xx.xxx.xxx --dport 22 -j ACCEPT

  • Command permits SSH access only from the given IP(172.xx.xxx.xxx) address. This is a solid approach for limiting SSH access to trusted sources — a common best practice for hardening servers.
  • -A INPUT: Appends the rule to the INPUT chain, which handles packets destined for the local system.

  • -p tcp: Specifies that the rule applies to TCP packets.

  • -s 172.xx.xxx.xxx: Source IP address. Only packets coming from this IP will be matched.

  • --dport 22: Destination port 22 — typically used for SSH.

  • -j ACCEPT: The action to take — allow the packet through.


iptables -A INPUT -s 192.168.1.100 -j DROP - Command to drop all incoming traffic from a specific IP


iptables -A OUTPUT -j ACCEPT - To allow all outgoing traffic

0
Subscribe to my newsletter

Read articles from Prithvi Kumar Detne directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prithvi Kumar Detne
Prithvi Kumar Detne