How to use or specify multiple IP addresses in iptables source or destination on Linux

ww‮.w‬lautturi.com
How to use or specify multiple IP addresses in iptables source or destination on Linux

You can use multiple IP addresses in the source or destination specification of an iptables rule by using a range of IP addresses or by specifying multiple individual IP addresses.

To specify a range of IP addresses, you can use the -m iprange module and the --src-range or --dst-range options. For example, to allow traffic from the IP address range 192.168.1.100 to 192.168.1.200, you can use the following iptables rule:

iptables -A INPUT -m iprange --src-range 192.168.1.100-192.168.1.200 -j ACCEPT

To specify multiple individual IP addresses, you can use the -s or -d options multiple times. For example, to allow traffic from the IP addresses 192.168.1.100, 192.168.1.200, and 192.168.1.250, you can use the following iptables rule:

iptables -A INPUT -s 192.168.1.100 -s 192.168.1.200 -s 192.168.1.250 -j ACCEPT

It's important to note that the iptables rules are processed in the order they are specified. If you have multiple rules that apply to the same traffic, the first matching rule will be applied. For example, if you have a rule that allows traffic from 192.168.1.100 and a rule that blocks all traffic, the traffic from 192.168.1.100 will be allowed, and all other traffic will be blocked.

Created Time:2017-10-29 22:08:40  Author:lautturi