I added a rule to accept connections from 192.168.1.135/24, since my router is configured to hand out /24 addresses. Then, iptables -L -v showed that connections from 192.168.1.0/24 are accepted. When I change the rule to accept connections from .135/32 - or from .135 without specifying the subnet -, it not only works as intended, but it also resolves the hostname correctly.

Why?

unsolicited “why do you still use iptables” advice not welcome :D

  • PowerCrazy@lemmy.ml
    link
    fedilink
    English
    arrow-up
    8
    ·
    edit-2
    1 day ago

    You need to understand subnetting. Allowing 192.168.1.0/24 also allows 192.168.1.135/24 In fact 192.168.1.135/24 shouldn’t be valid syntax at all, but it is easier to accept it and then let subnet math fix the mistake.

    I assume your router is 192.168.1.135 for whatever reason, so as long as your router is contained in the configured iptables allowed network, it’ll work with all of the following networks.

    192.168.1.135/32
    192.168.1.134/31
    192.168.1.132/30
    192.168.1.128/29
    192.168.1.128/28
    192.168.1.128/27
    192.168.1.128/26
    192.168.1.128/25
    192.168.1.0/24
    192.168.0.0/23
    … And 22 even larger networks.

    If you don’t configure a subnet mask for the rule, iptables will accept the IP address you put in as a single host, the /32 is implied. The same behavior would be seen using any kind of network filter, though they may not allow you to specify 192.168.1.135/24, they may require a bit boundary, but mathematically, it’s the same.