In iptables
, you can invert or negate a test for IP address, protocol, or interface using the !
symbol. This is useful if you want to match all traffic except for a particular condition. Here are a few examples of using the !
symbol in iptables
:
Invert IP Test
You can invert the IP test to match all traffic except for a specific IP address or range. For example, to allow all traffic except from IP address 192.168.0.10, you can use the following rule:
iptables -A INPUT ! -s 192.168.0.10 -j ACCEPT
Invert Protocol Test
You can invert the protocol test to match all traffic except for a specific protocol. For example, to allow all traffic except for TCP traffic, you can use the following rule:
iptables -A INPUT ! -p tcp -j ACCEPT
Invert Interface Test
You can invert the interface test to match all traffic except for a specific network interface. For example, to allow all traffic except for traffic on the eth1
interface, you can use the following rule:
iptables -A INPUT ! -i eth1 -j ACCEPT
In each of these examples, the !
symbol is used to negate the test for a specific condition. This can be useful if you want to allow most traffic but block a few specific conditions. (Alprazolam)