Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
iptables -I PREROUTING -t nat -p udp -s 192.168.0.62 --dport 53 -j DNAT --to-destination 23.21.182.24

Instead of only rerouting traffic from 192.168.0.62, I'd like to reroute traffic from all ips, 192.168.0.*, possible?

share|improve this question
2  
All to the same destination? Try replacing -s 192.168.0.62 with -s 192.168.0.0/24. –  Zoredache Sep 18 '13 at 0:07
    
Works, thank you. –  Gabe Sep 18 '13 at 0:21

1 Answer 1

Just wanted to add to @Zoredache comment (Which is also an answer)

Extract of the Command iptables in relation to -s flag

--source -s [!] address[/mask]

So what @Zoredache has suggested works by working on the subnet mask short hand

To break down -s 192.168.0.0/24 we need to look at the subnet mask it represents:

255.255.255.0

Now this doesn't really give us any indication of how it's represented as the number 24 until we look at the binary representation of the subnet mask:

11111111.11111111.11111111.00000000

Now a quick count will show that the first 24 binary switches are set to 1 this is why it's represented as /24


So what we have told the iptables command is that we want the source to be the first 256 (192.168.0.0-255) IP addresses starting at 192.168.0.0 to be declared as a source in this command


Another example would be I want the first 65,536 IP addresses starting at 10.1.0.0 to be the source

So the command would be -s 10.1.0.0/16 this is subnet mask 255.255.0.0 (Binary is 11111111.11111111.00000000.00000000) and this will declare 10.1.0.0 through 10.1.255.255 as the source addresses

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.