English 中文(简体)
如何把所有子域连接到使用小型水底系统的单一东道国?
原标题:How to route all subdomains to a single host using mDNS?

I have a development webserver hosting as "myhost.local" which is found using Bonjour/mDNS. The server is running avahi-daemon.

The webserver also wants to handle any subdomains of itself. Eg "cat.myhost.local" and "dog.myhost.local" and "guppy.myhost.local".

鉴于这一我的东道主。 当地人正在从德克普岛获得一个动态的寄生地址,是否仍有办法把所有寄生于我的东道方。

I m starting to think it not currently possible...

http://marc.info/?l=freedesktop-avahi&m=119561596630960&w=2

You can do this with the /etc/avahi/hosts file. Alternatively you can
use avahi-publish-host-name.

No, he cannot. Since he wants to define an alias, not a new hostname. I.e. he only wants to register an A RR, no reverse PTR RR. But if you stick something into /etc/avahi/hosts then it registers both, and detects a collision if the PTR RR is non-unique, which would be the case for an alias.

最佳回答

当时我没有这样做了,此后我回过头再谈这个问题。

我目前的解决办法是,在当地机器的东道方档案中,大力增加每个次要利益。

问题回答

我最妥善地解决了这一问题,因为我给这项任务的时间很少。

但不幸的是,我并不认为瓦希/米德斯/博奈尔的窗口是支持别).的(如果我错过如何支持这种做法的例子的话,我就认为了这一点)。

i网站提供的假冒文字开始做什么:

Create : /usr/bin/avahi-announce-alias

使之可执行;

#! /usr/bin/env python
# avahi-alias.py

import avahi, dbus
from encodings.idna import ToASCII

# Got these from /usr/include/avahi-common/defs.h
CLASS_IN = 0x01
TYPE_CNAME = 0x05

TTL = 60

def publish_cname(cname):
    bus = dbus.SystemBus()
    server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER),
            avahi.DBUS_INTERFACE_SERVER)
    group = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()),
            avahi.DBUS_INTERFACE_ENTRY_GROUP)

    rdata = createRR(server.GetHostNameFqdn())
    cname = encode_dns(cname)

    group.AddRecord(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
        cname, CLASS_IN, TYPE_CNAME, TTL, rdata)
    group.Commit()


def encode_dns(name):
    out = []
    for part in name.split( . ):
        if len(part) == 0: continue
        out.append(ToASCII(part))
    return  . .join(out)

def createRR(name):
    out = []
    for part in name.split( . ):
        if len(part) == 0: continue
        out.append(chr(len(part)))
        out.append(ToASCII(part))
    out.append(  )
    return   .join(out)

if __name__ ==  __main__ :
    import time, sys, locale
    for each in sys.argv[1:]:
        name = unicode(each, locale.getpreferredencoding())
        publish_cname(name)
    try:
        # Just loop forever
        while 1: time.sleep(60)
    except KeyboardInterrupt:
        print "Exiting"

This script handles the announcement of each individual alias, and will remain running until you kill it. (because of this, we need to create another script which I ve shown below)

Create text file /etc/avahi/aliases

我们用的是每条线向该机器储存一台货箱。

Create directory /etc/avahi/aliases.d/

我实际上没有在我在这里所展示的任何文字中加以利用,但是,对于那些从那里入手的人来说,你可以看到需要做些什么。

想法是,你可以把别的物品编成单独的文本档案(如果你处理藏匿的虚拟主人的话,会更有意义),这是许多关于*nix的 da魔应用已经提供的。

Create /usr/bin/avahi-announce-aliases

使之可执行并填满

#!/usr/bin/env python

import os, sys
from subprocess import Popen


def ensure_file (path):
    """
        Looks for  file at provided path, creates it if it does not exist.
        Returns the file.
    """
    rfile = None    
    if not os.path.exists(path) and os.path.isfile(path) :
        rfile = open(path,"w+");
        print("ensuring file : %s " % path)

    print("file ensured : %s " % path)
    return rfile


command =  /usr/bin/avahi-announce-alias 
alias_pid_path = "/tmp/avahi-aliases.pid"
alias_file_path = "/etc/avahi/aliases"

alias_file = open(alias_file_path)
if not os.path.exists(alias_pid_path) :
    open(alias_pid_path,"w").close()

alias_pid = open(alias_pid_path,"r")


for line in alias_pid :
    txt = line.strip( 
 )
    if len(txt) > 0 :
        print("kill %s" % txt )
        os.system("kill %s" % txt)          
alias_pid.close()
alias_pid = open(alias_pid_path,"w+")

for line in alias_file :
    txt = line.strip( 
 )
    if len(txt) > 0 :
        print("publishing : << %s >>" % txt)
        process = Popen([command, txt])
        alias_pid.write("%s
" % str(process.pid))    
alias_pid.close()

print("done")

这绝不意味着是假日方案拟订的主轴,因此,如果你认为合适,就可自由作出改进。

Usage

如果我们的东道国名是“服务器”,瓦希-东道国名是“服务器”。 附有您额外东道方名的案文:

deluge.server.local
username.server.local
accounts.server.local
something-else.server.local
another.hostname.home

(然而,我确实确信,如果你确信该网络已经不存在的话,你会在那里拥有任何东道名称,这就是为什么我只是创造出正常的瓦希东道国名的子库)

然后,我们运行:

我之所以设立这一职位,主要是因为便利了对django &的模拟;在我的膝上型计算机上开发破产网站。

Caveats

My only disappointment is that the windows implementation of Bonjour/Avahi does not support the aliases that this implementation announces, it will only see the main avahi hostname normally announced (ie server.local in our example above).





相关问题
Does Bonjour networking work on ppc running 10.4?

I developed an application for Mac 10.5 desktop which communicates with iPhone over wifi using Bonjour service, and it is working fine on Mac 10.5 and able to do required syncing with iPhone over wifi ...

iPhone SDK: phone to phone file transfer

What is the simpliest approach to copy files from iPhone to iPhone (p2p). The only way I can come up is this: Use Bonjour to discover server app (which will advertize itself via Bonjour) Use ...

cannot run java app on mac properly

I have small problem..I created a java App in windows and my .jar consist of whole app..i copied this jar file to mac and executed it from there it works fine.. Java App consists of bonjour code if i ...

Is there a Bonjour SDK for Windows?

I want to know how to implement bonjour on windows, so that i can set up server on windows and access files in windows(server) using bonjour service from my iphone(client). Can anyone tell me whether ...

Secure iPhone-Desktop Connection

Background There are a lot of App Store released iPhone apps that require an IP based server on the desktop so that the iPhone can connect to the desktop as a client. For example, there are many ...

How do I build a DNS Query record in Erlang?

I am building a native Bonjour / Zeroconf library and need to build DNS query records to broadcast off to the other machines. I have tried looking thru the Erlang source code but as I am relatively ...