[SOLVED] Avahi not "self aware"
Posted by szumlins on 2012/3/26 22:08:18
I'm working on a project for a small appliance that might be plugged in on any network and I would like to advertise the location of the web administration panel for the software I'm using over mDNS. I have avahi installed and all seems to be working externally (my Macs on the network see the registered service and can ping the archipliance.local mDNS name). The problem I'm having is that the CentOS system itself doesn't appear to know its own mDNS name. When I ping on the CentOS box itself to archipliance.local, it says no host found.
Obviously this is easy in a non-dhcp world, but since this box may be on any network with any IP range at any given time, I'm not quite sure how to have it fall back onto its .local name when a static IP is not configured and good DNS is not around. I need to have the CentOS system default back to its hostname with the .local extension in absence of good DNS.
Some shell dumps just so you get an idea of what is going on:
[root@archipliance ~]# ps aux | grep avahi
avahi 1262 0.0 0.0 27880 1836 ? S 04:51 0:00 avahi-daemon: running [archipliance.local]
avahi 1263 0.0 0.0 27712 516 ? Ss 04:51 0:00 avahi-daemon: chroot helper
root 5991 0.0 0.0 103292 872 pts/0 S+ 13:41 0:00 grep avahi
[root@archipliance ~]# ping archipliance.local
ping: unknown host archipliance.local
[root@archipliance ~]# hostname
archipliance
[root@archipliance ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 50:E5:49:E8:03:54
inet addr:192.168.3.100 Bcast:192.168.3.255 Mask:255.255.255.0
inet6 addr: fe80::52e5:49ff:fee8:354/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:91112 errors:0 dropped:0 overruns:0 frame:0
TX packets:27852 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:71441071 (68.1 MiB) TX bytes:4833542 (4.6 MiB)
Interrupt:28 Base address:0xe000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1446 (1.4 KiB) TX bytes:1446 (1.4 KiB)
[root@archipliance ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search copperbell.lan.
nameserver 192.168.3.50
nameserver 192.168.3.51
nameserver 172.16.0.1
From my Mac on the same network:
[szumlins@octane:~]: ping archipliance.local
PING archipliance.local (192.168.3.100): 56 data bytes
64 bytes from 192.168.3.100: icmp_seq=0 ttl=64 time=0.172 ms
64 bytes from 192.168.3.100: icmp_seq=1 ttl=64 time=0.277 ms
Any ideas would be much appreciated.
Re: Avahi not "self aware"
Posted by pschaff on 2012/3/26 23:40:56
Not quite following what you are trying to accomplish, and I don't know how to implement the
fullback you want. You can certainly specify a HOSTNAME in /etc/sysconfig/network.
The key to correct name resolution seems to be in a correct DHCP/DNS server. Perhaps
this article may help, but that does not account for situations where it is
not correctly handled.
Re: Avahi not "self aware"
Posted by szumlins on 2012/4/4 4:24:21
The problem I have is that this system moves from location to location and can be on any variance of DHCP servers with absolutely no guarantee that I will have valid DNS at any given time. Normally this wouldn't be a problem, but one of the main pieces of software that is being used uses a web based UI and needs to know its own name and calls itself using gethostname(). If there is no valid DNS, the system falls back onto whatever hostname is set in /etc/sysconfig/network. The only problem here is that this hostname needs to have the .local extension added to it for avahi to work in absence of any DNS, so simply setting the hostname from "hostname" to "hostname.local" makes everything work.
I've written a little perl script that runs at boot time that checks to see if there is valid DNS (host against the IP), and if not it changes /etc/hosts as well as calls the hostname directive to rename the host from "hostname" to "hostname.local". I need this avahi resolving address in place before I start the service for the other web based tool (it runs at the end of sysv, so this is fine). If there is valid DNS from DHCP, we just let the hostname stay what it is and all is well in the world.
The only remaining issue I have now is that running /bin/hostname in my init script for some reason does not seem actually set the hostname, yet running it immediately after login seems to work just fine. I would just change the /etc/sysconfig/network hostname setting beforehand, but considering that I need networking to actually be up and running before I can do my tests, that wouldn't make much sense.
The end goal is that I want this CentOS box to run like my Mac on DHCP. In absence of good DNS, I want it to have a valid .local hostname that it is aware of and can address itself over. Right now all the other systems on the network can actually address it with a bad hostname set (Windows 7, Mac OS X, other Linux), but it can't see itself.
Re: Avahi not "self aware"
Posted by pschaff on 2012/4/4 14:51:56
Your needs are clear but I don't completely understand where your script approach is failing. My guess is that the hostname you set is somehow getting clobbered when subsequent services start. You could try setting it in /etc/rc.d/rc.local which should run last, but that presumably requires some logic to test what your perl script has done earlier.
Re: Avahi not "self aware"
Posted by szumlins on 2012/4/5 18:54:35
Quote:
pschaff wrote:
Your needs are clear but I don't completely understand where your script approach is failing. My guess is that the hostname you set is somehow getting clobbered when subsequent services start. You could try setting it in /etc/rc.d/rc.local which should run last, but that presumably requires some logic to test what your perl script has done earlier.
Phil, thanks for the advice on rc.local, I will give that a try today and report back. I did double check rc.local to make sure that the hostname isn't getting set in there already (it isn't), but I can move that section of the script out into rc.local and maybe just do a test against a file in /tmp if the first portion of the script runs correctly.
Re: Avahi not "self aware"
Posted by szumlins on 2012/4/9 3:37:56
Adding the hostname directive to the rc.local file worked and properly switched the hostname.
I am still really perplexed as to why it works in rc.local, but not when run during the normal boot process when every other command I run in the script runs without issue. It is really confusing to me, but it is another problem for another day.
Re: [SOLVED] Avahi not "self aware"
Posted by pschaff on 2012/4/9 15:00:12
Quote:
szumlins wrote:
Adding the hostname directive to the rc.local file worked and properly switched the hostname.
Thanks for reporting back. Marking this thread [SOLVED] for posterity.
Quote:
I am still really perplexed as to why it works in rc.local, but not when run during the normal boot process when every other command I run in the script runs without issue. It is really confusing to me, but it is another problem for another day.
Because something that runs after your first script in the boot process overwrites what you did. The usual way to handle that would be to set the hostname to the desired value, but your requirements seem to preclude that approach as the hostname is not known
a priori.
This Post was from: https://www.centos.org/newbb/viewtopic.php?forum=58&topic_id=36603