this post was submitted on 17 Apr 2025
19 points (91.3% liked)

Linux

53461 readers
742 users here now

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

Related Communities

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

founded 5 years ago
MODERATORS
 

EDIT: The bad solution is to unblock UDP port 5353 but the port has to be source port, not destination port. (--sport flag) See the now modified rules. The issue is that this is very insecure (see this stackexchange question and comments) but obviously better than no firewall at all because at least I'm blocking TCP traffic.

The proper solution (other than using glibc and installing nss-mdns package) is to open a port with netcat (nc) in the background (using &) and then listen with dig on that port using the -b flag.

port="42069"
nc -l -p "$port" > /dev/null || exit 1 &
dig somehostname.local @224.0.0.241 -p 5353 -b "0.0.0.0#${port}"

Then we need to remember to kill the background process. The DNS reply will now be sent to port 42069, so we can just open it with this iptables rule:

-A INPUT -p udp -m udp --dport 42069 -j ACCEPT

---->END OF EDIT.

I want to setup iptables firewall but if I do that, it blocks multicast DNS which I need. I am using command

dig "somehostname.local" @224.0.0.251 -p 5353

to get the IP through mDNS and these are my iptables rules (from superuser.com):

*filter

# drop forwarded traffic. you only need it of you are running a router
:FORWARD DROP [0:0]

# Accept all outgoing traffic
:OUTPUT ACCEPT [623107326:1392470726908]


# Block all incoming traffic, all protocols (tcp, udp, icmp, ...) everything.
# This is the base rule we can define exceptions from.
:INPUT DROP [11486:513044]

# do not block already running connections (important for outgoing)
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# do not block localhost
-A INPUT -i lo -j ACCEPT

# do not block icmp for ping and network diagnostics. Remove if you do not want this
# note that -p icmp has no effect on ipv6, so we need an extra ipv6 rule
-4 -A INPUT -p icmp -j ACCEPT
-6 -A INPUT -p ipv6-icmp -j ACCEPT

# allow some incoming ports for services that should be public available
# -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
# -A INPUT -p udp -m udp --dport 5353 -j ACCEPT # does not help
-A OUTPUT -p udp -m udp --sport 5353 -j ACCEPT # SOLVES THE ISSUE BUT IS INSECURE - not recommended


# commit changes
COMMIT

Any help is welcome :)

you are viewing a single comment's thread
view the rest of the comments
[–] Eideen@lemmy.world 4 points 1 week ago* (last edited 6 days ago) (1 children)

My understanding is that dig does not support mDNS.

The most common way to use it via avahi-browse and avahi-daemon (mDNS service).

https://askubuntu.com/a/1526875

The following failes for me:

dig "pihole-s5.local" @224.0.0.251 -p 5353

The following works for me:

$getent hosts pihole-s5.local
192.168.2.10    pihole-s5.local
[–] TMP_NKcYUEoM7kXg4qYe@lemmy.world 1 points 6 days ago* (last edited 6 days ago) (1 children)

Huh weird. For me the first one works but the second one fails and returns an empty string.

I guess I should have specified that I'm on Void-musl. The reason why I'm doing this is because there is no NSS library on musl, so as far as I know you cannot automagically query hostnames on the network.

[–] Eideen@lemmy.world 1 points 6 days ago (1 children)

I don't know Void-musl.

I don't know if you can install libnss-mdns. If /etc/nsswitch.conf is not standard you also need to configure it.

Are you able to setup VM with Debian, so you can test with a standard environment?

Well the musl C library does not have nss-mdns available. But it does not matter, I solved it now. Thanks anyways!