Forrest logo
back to the iptables tool

iptables:tldr:d00ca

iptables: Append rule to chain policy for IP considering protocol and port.
$ sudo iptables -A ${chain} -s ${ip} -p ${protocol} --dport ${port} -j ${rule}
try on your machine

This command is used to add a rule to the iptables firewall configuration in Linux systems. Let's break it down:

  • sudo: It is used to run the command as a superuser or with root privileges. This is necessary because iptables configuration requires administrative rights.

  • iptables: This is the command-line utility for configuring the Linux kernel's firewall. It allows you to set up rules and chains to control network traffic.

  • -A ${chain}: It specifies the target chain where the rule will be appended. ${chain} is a placeholder for the name of the chain, which can be INPUT, OUTPUT, or FORWARD. For example, -A INPUT specifies that the rule should be added to the input chain.

  • -s ${ip}: It specifies the source IP address or IP range from where the traffic originates. ${ip} is a placeholder for the actual IP address.

  • -p ${protocol}: It specifies the protocol type, such as TCP, UDP, ICMP, etc. ${protocol} is a placeholder for the desired protocol.

  • --dport ${port}: It specifies the destination port number or port range where the traffic is being sent. ${port} is a placeholder for the actual port number.

  • -j ${rule}: It specifies the target action for the rule. ${rule} is a placeholder for the action to be taken, which can be ACCEPT, DROP, REJECT, or other custom actions. For example, -j ACCEPT allows the traffic to pass through, whereas -j DROP blocks it.

By executing this command, a new rule will be added to the specified chain in the iptables firewall configuration, allowing or blocking traffic based on the provided criteria.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the iptables tool