Skip to content

Instantly share code, notes, and snippets.

@jack828
Last active December 12, 2023 18:54
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jack828/b8375b16b6fb9eae52201d4deb563ab7 to your computer and use it in GitHub Desktop.
Save jack828/b8375b16b6fb9eae52201d4deb563ab7 to your computer and use it in GitHub Desktop.
TrueNAS Jail mDNS Setup Kickstarter
# An explanation of this script is available on my blog https://jackburgess.dev/blog/truenas-jails-access-via-mdns
# This allows you a nice way of connecting to your jails via their hostname using mDNS
# e.g. for Netdata, which runs on port 3000, you can access it on your jail via:
# http://<jail ip>:3000/
# But wouldn't it be nice to access it on
# http://jailhostname.local/
#
# Oneliner to kickstart
# pkg install -y curl && curl --silent https://gist.githubusercontent.com/jack828/b8375b16b6fb9eae52201d4deb563ab7/raw | /bin/sh -s PORT
PORT=$1
HOSTNAME=$(hostname)
echo "Installing services..."
pkg install -y avahi-app socat
sysrc dbus_enable="YES"
sysrc avahi_daemon_enable="YES"
sysrc socat_enable="YES"
rm /usr/local/etc/avahi/services/*.service
cat > /usr/local/etc/avahi/services/http.service << EOF
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_http._tcp</type>
<port>80</port>
</service>
</service-group>
EOF
cat >> /usr/local/etc/socat-instances.conf << EOF
[jailredirect]
daemonuser=root
flags="tcp-listen:80,reuseaddr,fork tcp:localhost:$PORT"
EOF
echo "Starting services..."
service dbus start
service avahi-daemon start
service socat start jailredirect
echo "Done! You can now access your jail service on http://$HOSTNAME.local/"
@Erdack54
Copy link

Erdack54 commented Apr 7, 2022

Hi, how i can revert this ? It's seem not working anymore :/

@jack828
Copy link
Author

jack828 commented Apr 7, 2022

Hey @Erdack54, if you have it on a fresh jail you can simply delete the jail.

Otherwise, you can just

pkg delete -y avahi-app socat

sysrc dbus_enable="NO"
sysrc avahi_daemon_enable="NO"
sysrc socat_enable="NO"

Otherwise, I need more information to help you.

@Erdack54
Copy link

Erdack54 commented Apr 7, 2022

@jack828 Thank you for your quick response, I'm going to spend a little more time looking because I have another problem at the same time a little more important, TrueNAS becomes totally inaccessible after 30m :/ I'll come back to you if it concerns your script, have a good day 🙂

@jack828
Copy link
Author

jack828 commented Apr 7, 2022

@Erdack54 No problem. I did have an issue that cleared itself eventually wherein socat consumed a lot of CPU and locked me out. Do let me know how you get on!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment