IP Address Syntax in Intrusion Rules
The following table summarizes the various ways you can specify source and destination IP addresses.
To Specify... |
Use... |
Example |
---|---|---|
any IP address |
|
|
a specific IP address |
the IP address Note that you would not mix IPv4 and IPv6 source and destination addresses in the same rule. |
|
a list of IP addresses |
brackets ( |
|
a block of IP addresses |
IPv4 CIDR block or IPv6 address prefix notation |
|
anything except a specific IP address or set of addresses |
the
|
! |
anything in a block of IP addresses except one or more specific IP addresses |
a block of addresses followed by a list of negated addresses or blocks |
|
IP addresses defined by a network variable |
the variable name, in uppercase letters, preceded by
Note that preprocessor rules can trigger events regardless of the hosts defined by network variables used in intrusion rules. |
|
all IP addresses except addresses defined by an IP address variable |
the variable name, in uppercase letters, preceded by
|
|
The following descritptions provide additional information on some of the IP address entry methods.
Any IP Address
You can specify the word
any
as a rule source or destination IP address to
indicate any IPv4 or IPv6 address.
For example, the following rule uses the argument any in the Source IPs and Destination IPs fields and evaluates packets with any IPv4 or IPv6 source or destination address:
alert tcp any any -> any any
You can also specify
::
to indicate any IPv6 address.
Multiple IP Addresses
You can list individual IP addresses by separating the IP addresses with commas and, optionally, by surrounding non-negated lists with brackets, as shown in the following example:
[192.168.1.100,192.168.1.103,192.168.1.105]
You can list IPv4 and IPv6 addresses alone or in any combination, as shown in the following example:
[192.168.1.100,2001:db8::1234,192.168.1.105]
Note that surrounding an IP address list with brackets, which was required in earlier software releases, is not required. Note also that, optionally, you can enter lists with a space before or after each comma.
Note | You must surround negated lists with brackets. |
You can also use IPv4 Classless Inter-Domain Routing (CIDR) notation or IPv6 prefix lengths to specify address blocks. For example:
-
192.168.1.0/24 specifies the IPv4 addresses in the 192.168.1.0 network with a subnet mask of 255.255.255.0, that is, 192.168.1.0 through 192.168.1.255.
-
2001:db8::/32 specifies the IPv6 addresses in the 2001:db8:: network with a prefix length of 32 bits, that is, 2001:db8:: through 2001:db8:ffff:ffff:ffff:ffff:ffff:ffff.
Tip | If you need to specify a block of IP addresses but cannot express it using CIDR or prefix length notation alone, you can use CIDR blocks and prefix lengths in an IP address list. |
IP Addresses Negation
You can use an exclamation point (!
) to negate a
specified IP address. That is, you can match any IP address with the exception
of the specified IP address or addresses. For example,
!192.168.1.1
specifies any IP address other than
192.168.1.1, and
!2001:db8:ca2e::fa4c
specifies any IP address other
than 2001:db8:ca2e::fa4c.
To negate a list of IP addresses, place
!
before a bracketed list of IP addresses. For example,
![192.168.1.1,192.168.1.5]
would define any IP address
other than 192.168.1.1 or 192.168.1.5.
Note | You must use brackets to negate a list of IP addresses. |
Be careful when using the negation character with IP address
lists. For example, if you use
[!192.168.1.1,!192.168.1.5]
to match any address that
is not 192.168.1.1 or 192.168.1.5, the system interprets this syntax as
“anything that is not 192.168.1.1,
or
anything that is not 192.168.1.5.”
Because 192.168.1.5 is not 192.168.1.1, and 192.168.1.1 is not
192.168.1.5, both IP addresses match the IP address value of
[!192.168.1.1,!192.168.1.5]
, and it is essentially the
same as using “any
.”
Instead, use
![192.168.1.1,192.168.1.5]
. The system interprets this
as “not 192.168.1.1
and not 192.168.1.5,” which matches any IP address other
than those listed between brackets.
Note that you cannot logically use negation with
any
which, if negated, would indicate no address.