• Sign in
  • Sign up
Elektrine
EN
Log in Register
Modes
Overview Chat Timeline Communities Gallery Lists Friends Email Vault DNS VPN
Back to Timeline !linux @emotional_soup_88__dup_21417
In reply to 4 earlier posts
@emotional_soup_88__dup_21417@programming.dev on programming.dev Open parent
The behavior of /24 vs /32 addresses when using iptables
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
Open parent Original URL
0
1
16
@jrgd@lemmy.zip on lemmy.zip Open parent
The routing and firewalling is a bit different in terms of why certain CIDR masks are used. For the router, the /24 prefix is usually defined for itself on the LAN interface to denote the address space it may send route information to, and what addresses are controlled by the device. Almost certainly, (unless using a lower CIDR range and actually handing out /24 blocks to subsequent routers), you are granting /32 IPv4 addresses to your device from your router. For your system firewall, 192.168.1.135/24 is identical to 192.168.1.0/24 as they are the same address space. You’re simply allowing from a subnet of hosts to accept from. Given the /24 mask is 255.255.255.0, it does not matter what the last number of the IPv4 address is, but the lowest possible number to match the mask is standard form. Without knowing what rule(s) specifically are being applied, I couldn’t tell you if your firewall rules are something that would affect hostname resolution of other hosts from your system or not.
Open parent Original URL
0
0
11
@emotional_soup_88__dup_21417@programming.dev on programming.dev Open parent
If I may ask a follow up question, just out of curiosity, I did an ip a on my phone that is connected to the same router as the system whose firewal I was referring to in my original post and it gave me: inet 192.168.1.214/24 brd 192.168.1.255 scope global wlan0 Which to my untrained eye indicates that my phones WiFi interface has been alotted the .214 address in the /24 space/subnet. But if I understand you correctly, this has to do with the above being routing related - how my phone reaches WAN -, while my original post was about firewalling. And when it comes to firewalling, you specify a host with a mask of /32?
Open parent Original URL
0
0
6
@CosmicGiraffe@lemmy.world on lemmy.world Open parent
You might want to use either a /24 address or a /32 address in a firewall rule, depending on what you’re trying to do. The difference is that the /24 one refers to a set of IPs, while the /32 one applies to only one IP. Say you’re adding a firewall rule like iptables -A - s 192.168.1.123/32 - j ACCEPT. This will accept all traffic with the source IP 192.168.1.123. If instead you use iptables -A - s 192.168.1.123/24 - j ACCEPT, you’ll accept all traffic with a source IP in the 192.168.1.123/24 subnet, which is all the IPs between 192.168.1.0 & 192.168.1.255. In the case of your WiFi IP, the subnet does something different. It tells you which IP addresses you should expect to be able to contact directly, and which you need to contact via a router. 192.168.1.214/24 says that all the IPs between 192.168.1.0 & 192.168.1.255 can be reached directly, whereas IPs outside that range need to be sent to a router. ip route will show you the routes a device knows about. It’ll look something like this (simplifying a bit): default via 192.168.1.1 192.168.1.0/24 dev wlan0 src 192.168.1.214 The first line is the default route, which is used when no more specific route exists. It says that you talk to these IPs by sending your traffic to 192.168.1.1 (your wifi router) and it’ll send it on from there. The second one says that for IPs in the 192.168.1.0/24, you directly talk to them using your wlan0 interface
Open parent Original URL
0
0
3
0
emotional_soup_88__dup_21417
durinn in !linux
@emotional_soup_88__dup_21417@programming.dev · Mar 03
Thank you very much! :) Interesting why iptables behaves like that though. Because, if I understand it correctly, specifying any address between 192.168.1.[0…255]/24 will result in all addresses in that range to be accepted? So, the only way to actually single out one host is to use the mask /32…?
View on programming.dev
0
2
0
Sign in to interact

Comments (2)

Showing 0 of 2 cached locally.
Syncing comments from the remote thread. 2 more replies are still loading.

Loading comments...

About Community

linux
Linux
!linux@lemmy.ml

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word “Linux” in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules
  • Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
  • No misinformation
  • No NSFW content
  • No hate speech, bigotry, etc
Related Communities
  • !opensource@lemmy.ml
  • !libre_culture@lemmy.ml
  • !technology@lemmy.ml
  • !libre_hardware@lemmy.ml

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

64670
Members
10906
Posts
Created: June 01, 2019
View All Posts
313k7r1n3

Company

  • About
  • Contact
  • FAQ

Legal

  • Terms of Service
  • Privacy Policy
  • VPN Policy

Email Settings

IMAP: mail.elektrine.com:993

POP3: pop3.elektrine.com:995

SMTP: mail.elektrine.com:465

SSL/TLS required

Support

  • support@elektrine.com
  • Report Security Issue

Connect

Tor Hidden Service

khav7sdajxu6om3arvglevskg2vwuy7luyjcwfwg6xnkd7qtskr2vhad.onion
© 2026 Elektrine. All rights reserved. • Server: 08:30:25 UTC