Skip to content

Instantly share code, notes, and snippets.

@davisford
Created July 12, 2013 14:14
Show Gist options
  • Star 86 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save davisford/5984768 to your computer and use it in GitHub Desktop.
Save davisford/5984768 to your computer and use it in GitHub Desktop.
Setup avahi-daemon on Ubuntu for so you can reach hostname `ubuntu.local` from host OS
sudo apt-get install avahi-daemon avahi-discover avahi-utils libnss-mdns mdns-scan
@davidhbrown-uri
Copy link

thank you :-)

@nerdinand
Copy link

sudo apt-get install avahi-daemon seems to be enough to make your Ubuntu Server 18.04 accessible as ubuntu.local.

@icedawn
Copy link

icedawn commented Jul 4, 2020

Confirmed that sudo systemctl restart avahi-daemon is sufficient. Note that, because of my network, this wasn't sufficient to get my Jetson nano's online and discoverable in the .local domain. In order to get this to work, I had to disable AVAHI_DAEMON_DETECT_LOCAL in /etc/default/avahi-daemon.

# 1 = Try to detect unicast dns servers that serve .local and disable avahi in
# that case, 0 = Don't try to detect .local unicast dns servers, can cause
# troubles on misconfigured networks
AVAHI_DAEMON_DETECT_LOCAL=0

It's recommended that you fix your network rather than disabling this detection, but if you are like me and are unable to do this for some reason, the above fix works. Just set it to zero and restart the daemon (or reboot) ... sudo systemctl restart avahi-daemon on Ubuntu 18.04.4 worked for me.

@ryanmaclean
Copy link

ryanmaclean commented Nov 21, 2020

Also chiming in here, sudo apt install -y avahi-daemon was all that was needed on Ubuntu 20.04 on (AMD/ARM)64.
Now Raspberry Pi 3 + 4 devices, desktops and servers on the network can be contacted via hostname.local addresses ♥️

@zigmoo
Copy link

zigmoo commented Jan 27, 2021

Also chiming in here, sudo apt install -y avahi-daemon was all that was needed on Ubuntu 20.04 on (AMD/ARM)64.
Now Raspberry Pi 3 + 4 devices, desktops and servers on the network can be contacted via hostname.local addresses ♥️

+1... works on my Pi4 as well

@GarethHards
Copy link

how do i add domain names in avaho conf file or in XDG config file?please help me here

@Debdut
Copy link

Debdut commented Feb 10, 2021

omg finally thanks 😊

@davidhbrown
Copy link

Thanks also to the commenters, especially @ryanmaclean!

@azureology
Copy link

If you only wish your host to be discoverable via hostname.loacl , then avahi-daemon is sufficient.
Once you want to resolve other client on local network using xxxx.local the rest of packages are still needed.

@mbratch
Copy link

mbratch commented Jun 26, 2021

I'm not sure what's wrong on my Ubuntu system. avahi-browse -a shows my five local mDNS devices on the network by their host names. However, if I try avahi-resolve-host-name on any one of them it gives me a "Timeout reached". I'm unable to ping any of them. I've installed everything described in this thread, and I've tried the various settings. The behavior remains unchanged. Any thoughts what I may be missing?

@mikew
Copy link

mikew commented Jul 11, 2021

Once you want to resolve other client on local network using xxxx.local the rest of packages are still needed.

I don't think I've ever installed the rest of those packages, avahi-daemon alone has always let me ping and talk to other machines via their .local address. Just now on 20.10-server, even.

@mbratch
Copy link

mbratch commented Jul 11, 2021

Once you want to resolve other client on local network using xxxx.local the rest of packages are still needed.

I don't think I've ever installed the rest of those packages, avahi-daemon alone has always let me ping and talk to other machines via their .local address. Just now on 20.10-server, even.

I wish mine worked as well in either case. Unfortunately, it doesn't.

@enggsath
Copy link

Hello All,
For Home automation project I used Esp8266 module,i configured it as SoftAcess point(It serves as router) and I connected things to it.
To acess it,I type IpAddress of it,it works fine.I need to acess it,When I type esp.local in url.When Iam trying these It didn't responding in ubuntu.But works fine in windows when i installed Bonjour.It didn't works in ubuntu.Please help

I installed avahi by following steps

1.sudo apt-get install avahi-daemon avahi-discover avahi-utils libnss-mdns mdns-scan
2.sudo gedit sudo systemctl restart avahi-daemon
then I changed AVAHI_DAEMON_DETECT_LOCAL=1 to 0
Neither worked whe it is 0 nor 1.
3.I even tried sudo systemctl restart avahi-daemon

This is the code written in ArduinoIde

#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <ESPmDNS.h>
#else
#error "Board not found"
#endif

#include <ESPAsyncWebServer.h>

AsyncWebServer server(80); // server port 80

void notFound(AsyncWebServerRequest *request)
{
request->send(404, "text/plain", "Page Not found");
}

void setup(void)
{

Serial.begin(115200);

WiFi.softAP("techiesms", "");
Serial.println("softap");
Serial.println("");
Serial.println(WiFi.softAPIP());

if (MDNS.begin("ESP")) { //esp.local/
Serial.println("MDNS responder started");
}

server.on("/", [](AsyncWebServerRequest * request)
{
String message = "hello world";
request->send(200, "text/plain", message);
});

server.on("/page1", HTTP_GET, [](AsyncWebServerRequest * request)
{
String message = "Welcome to page1";
request->send(200, "text/plain", message);
});

server.onNotFound(notFound);

server.begin(); // it will start webserver
}

void loop(void)
{
}****

@fade2gray
Copy link

Glad I stumbled on this. avahi-daemon alone worked for me on Ubuntu Server 20.04.3 LTS. I could even log in to Virtualmin/Webmin's control panel using the hostname after adding a rule for the mdns service in firewalld.

Thank you.

@donbarthel
Copy link

I'm not sure what's wrong on my Ubuntu system. avahi-browse -a shows my five local mDNS devices on the network by their host names. However, if I try avahi-resolve-host-name on any one of them it gives me a "Timeout reached". I'm unable to ping any of them. I've installed everything described in this thread, and I've tried the various settings. The behavior remains unchanged. Any thoughts what I may be missing?

Try the hostname without the ".local". I have an Octopi server (its a 3D printer appliance) on a Raspberry Pi and sometimes octopi.local works and sometimes just octopi. Not sure why. Then I just recently installed Avahi on a virtual machine and no matter what I did hostname.local didn't work. Then I tried hostname by itself without a .local and viola! SSH and web browser can both reach it that way.

@Bandicoot
Copy link

May I suggest the following as an all-in-one? sudo apt update && sudo apt-get install avahi-daemon avahi-discover avahi-utils libnss-mdns mdns-scan && sudo apt upgrade. Once that looks good, sudo reboot. That got me going on my new Ubuntu install on the TuringPi RK-1 modules.

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