iptables - Allow or deny a connection on an interface

by
Jeremy Canfield |
Updated: November 29 2021
| iptables articles
When adding, appending, updating or deleting a rule from iptables, the following options can be used to allow or deny an incoming or outgoing connection on the inteface.
In this example, the -o or --out-inteface option is used to allow outbound connections on TCP port 80 on the eth0 interface.
iptables --append INPUT --out-inteface eth0 --protocol tcp --dport 80 --jump ACCEPT
In this example, the ! (exclamation point) is used to deny outbound connections on TCP port 80 on the eth0 interface.
iptables --append INPUT ! --out-inteface eth0 --protocol tcp --dport 80 --jump ACCEPT
In this example, the -i or --in-inteface option is used to allow inbound connections on TCP port 80 on the eth0 interface.
iptables --append INPUT --in-inteface eth0 --protocol tcp --dport 80 --jump ACCEPT
In this example, the ! (exclamation point) is used to deny inbound connections on TCP port 80 on the eth0 interface.
iptables --append INPUT ! --in-inteface eth0 --protocol tcp --dport 80 --jump ACCEPT
Did you find this article helpful?
If so, consider buying me a coffee over at