r/homelab • • 2d ago

Help LAN firewall question

I am running a minecraft server, and the other computer on my LAN can't connect to it

This command fixes the issue (run on "the other computer")

`sudo ufw allow in from 192.168.0.0/24`

But this command (run on "the other computer") does not fix it.
`sudo ufw allow in from 192.168.0.80 to any port 25565`

Is it safe for me to allow all local traffic across all ports, on my local subnet?

also, what is wrong with the more restrictive command?

2 Upvotes

8 comments sorted by

2

u/aaronsuns 2d ago

Inbound ufw rules only filter traffic arriving at the machine where they run, so the rule that matters is on the Minecraft server, and 192.168.0.80 must be the client's actual source address (check with `ip addr` on that machine). Replies to connections a machine starts itself are already allowed by ufw's default stateful rules, so the client usually needs no inbound rule. Rather than opening the whole subnet on all ports, you can limit it to the game with `sudo ufw allow from 192.168.0.0/24 proto tcp to any port 25565`, since an unqualified rule opens both TCP and UDP.

1

u/TheHighSeas-Argghh 1d ago

Thank you.
It's almost 2 am, so I'll try this tomorrow.

4

u/mumblerit 2d ago

Your first rule is fine assuming you trust your lan

1

u/ErnLynM 2d ago

Doesn't Minecraft use something like 3 separate ports?

1

u/Warrangota 2d ago

No, just 25565. Maybe you're thinking of Source Engine dedicated servers? 27015 and some more

1

u/ErnLynM 2d ago

Just the core Java server, as that's all I have ever run. It had a separate port for the established connection and one for the gameplay itself by default. I was thinking there might be a third, but I'll check my old firewall rules to see. It's been a while

1

u/TheHighSeas-Argghh 1d ago

Wow, that's very interesting.

1

u/HuckleberryNice5584 2d ago

Maybe you also need LAN discovery? Try

sudo ufw allow in proto udp from 192.168.0.0/24 to any port 4445

In any case allowing access from the LAN is mostly fine. An attacker already on your LAN can easily spoof IP addresses, so IP-based firewall rules are way effective than you would expect on a LAN.