Friday, May 6, 2016

auto publish hostname and services using mDNS

mDNS (multicast Domain Name System)  is a zero-configuration service, that can publish hostname and services to other host on the networks. so the remote host can resolve the hostname to ip address without any dns server involvement.

on mac, Bonjour can provide mDNS and on linue avahi.
***setup information***
host1: advertised interface:  eth0
           fqdn: ubuntuxenial.local
           advertised service: nfs
host2: advertised interface:  vmnet1
           fqdn: main.local


***host1***
1- install avahi and avahi-discover mdns-scan
$ sudo apt-get install avahi-daemon avahi-discover 

2- configure avahi server by modify the configuration file /etc/avahi/avahi-daemon.conf as below
[server]
host-name=ubuntuxenial
domain-name=local
use-ipv4=yes
use-ipv6=yes
allow-interfaces=eth0
ratelimit-interval-usec=1000000
ratelimit-burst=1000
[wide-area]
enable-wide-area=yes
[publish]
publish-addresses=yes
publish-hinfo=yes
publish-workstation=yes
publish-domain=yes
[reflector]
[rlimits]
rlimit-core=0
rlimit-data=4194304
rlimit-fsize=0
rlimit-nofile=768
rlimit-stack=4194304
rlimit-nproc=3



3- create nfs service file /etc/avahi/services/nfs.service with the following content
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">NFS home directory %h</name>
  <service>
    <type>_nfs._tcp</type>
    <port>2049</port>
    <txt-record>path=/home/tin</txt-record>
  </service>
</service-group>


4- restart avahi-daemon service to make the new modification take affect
$ sudo /etc/init.d/avahi-daemon restart

*** host2 ***
1- install avahi and avahi-discover mdns-scan
$ sudo apt-get install avahi-daemon mdns-scan

2- configure avahi server by modify the configuration file /etc/avahi/avahi-daemon.conf as below
[server]
host-name=main
domain-name=local
use-ipv4=yes
use-ipv6=yes
allow-interfaces=vmnet1
ratelimit-interval-usec=1000000
ratelimit-burst=1000
[wide-area]
enable-wide-area=yes
[publish]
disable-publishing=no
publish-addresses=yes
publish-hinfo=yes
publish-workstation=yes
publish-domain=yes
[reflector]
[rlimits]
rlimit-core=0
rlimit-data=4194304
rlimit-fsize=0
rlimit-nofile=768
rlimit-stack=4194304
rlimit-nproc=3


3- restart avahi-daemon service to make the new modification take affect
$ sudo /etc/init.d/avahi-daemon restart

***browsing and test ***
 1- on host2 when we execute mdns-scan we will see everything that host1 publish
$ mdns-scan
+ main [00:00:06:00:44:11]._workstation._tcp.local
+ ubuntuxenial [00:0c:29:c8:39:ea]._workstation._tcp.local
+ NFS home directory ubuntuxenial._nfs._tcp.local




- or we can use gui avahi-discover , it will show the same thing

2- on host1 we can ping to main.local (resolve hostname to ip) without any dns involvement. and on host2 we also can resolve ubuntuxenial.local to ip as well
$ ping main.local
PING main.local (192.168.202.1) 56(84) bytes of data.
64 bytes from 192.168.202.1: icmp_seq=1 ttl=64 time=0.159 ms
64 bytes from 192.168.202.1: icmp_seq=2 ttl=64 time=0.330 ms
^C
--- main.local ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.159/0.244/0.330/0.086 ms



No comments:

Post a Comment