Adding mDNS/Bonjour support for Samba and Jellyfin
Since I can't really run a DNS server because of how my stupid ISP is set up I had to resort to more basic tools. I remembered that Apple does Bonjour and it works like magic. So I must have Bonjour on my Ubuntu Server as well. Of-course that doesn't exist, but some further investigation shows that Bonjour is just Apple's way of doing mDNS and Avahi does the same thing, if fully compatible and works just as well. Great! What is mDNS you may ask?
According to Wikipedia it's this:
Multicast DNS (mDNS) is a computer networking protocol that resolves hostnames to IP addresses within small networks that do not include a local name server. It is a zero-configuration service, using essentially the same programming interfaces, packet formats and operating semantics as unicast Domain Name System (DNS).
So basically, it's a decentralized DNS server. Every computer talks to each other to yell that they use Arch, eh... what services they have available. Everything that talks mDNS then sort of remembers who does what and in what way and software can then simply connect to it as needed. It's really neat!
But since linux in general doesn't care much about mDNS, how to set that up? And if practically nothing in Linux uses it, why even bother? That last part is simple, the rest of my network is mostly Macs, iPhones and and iPad. Even Android started supporting it in recent years. Since that all uses it natively, Ubuntu should too. And the how was more simple than I thought.
Install the service
Simply run ~$: sudo apt install avahi-daemon.
Then enable and start the service like so:
~$: sudo systemctl enable avahi-daemon
~$: sudo systemctl start avahi-daemon
And test it:
~$: ping HOSTNAME.local
Of-course replace HOSTNAME with your computer's hostname. I named my server home. Yes, I'm super creative!
Adding services to Avahi
Adding services is also not hard. These are added to /etc/avahi/services/ in the form of service files. Whatever it's called. They're XML files with a .service extension.
For Jellyfin I cobbled this together:
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h Jellyfin</name>
<service>
<type>_http._tcp</type>
<port>8096</port>
</service>
</service-group>
Save this as jellyfin.service and save it in /etc/avahi/services/.
And for Samba I found this:
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_smb._tcp</type>
<port>445</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=RackMac</txt-record>
</service>
</service-group>
Save this as smb.service and stick it in /etc/avahi/services/ as well.
Done!
What this does is have Avahi promote the services on your local network through mDNS. Jellyfin in general doesn't really use it, their apps need to be fed a URL/IP Address and then it finds it's own way. But 3rd party apps might use it. And now they can easily find the Jellyfin Server.
Same for Samba really. My laptop thinks it's talking to another mac and got rid of the stupid Windows BSOD icon that Apple puts on everything that isn't macOS. Supposedly because of the model=RackMac line. It shows a little Apple Display Icon now and instantly finds the shares I made.