8
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AirPrintするためだけにUbuntuでAvahi-daemonを動かしてみました。

Last updated at Posted at 2017-04-15

WiFiルーターと異なるLANセグメントにあるプリンターにiPadからAirPrintしたい。

iOSから「印刷」を選ぶとプリンタが検索できますが、WiFiルーターと同じLANセグメントにプリンターを設置していないと一覧に表示されません。

ポリシー上、あるいはトポロジー上、WiFiセグメントとLANセグメントを同一にしたくない場合もあるかと思います。

そこで、WiFiルーターのLAN側ポート(WiFi接続と等価な側)にpcDuinoを繋いで、Avahi-daemonを使ってプリンターのIPアドレスを告知するようにしてみました。

(普通にRaspberryPiとか、型落ちして使わなくなった昔のRaspberryPiとかでいいとおもいます)

Avahi-daemonのインストール

$ sudo apt-get install avahi-daemon

まあ、これだけなんですが。

設定とか

設定ファイルは /etc/avahi/ にあります。
プリンタサービスは、/etc/avahi/services/ 以下に、適当なプリンタ名.service というxmlファイルを置きます。

<?xml version="1.0" ?>
<!DOCTYPE service-group SYSTEM 'avahi-service.dtd'>
<service-group>
  <name replace-wildcards="yes">AirPrint DocuCentre-V C5585</name>
  <service>
    <type>_ipp._tcp</type>
    <subtype>_universal._sub._ipp._tcp</subtype>
    <host-name>xeroxcolor.local</host-name>
    <port>631</port>
    <txt-record>txtvers=1</txt-record>
    <txt-record>qtotal=1</txt-record>
    <txt-record>rp=ipp/print</txt-record>
    ・・・中略・・・
    <txt-record>Transparent=T</txt-record>
    <txt-record>Binary=T</txt-record>
    <txt-record>TBCP=F</txt-record>
    <txt-record>URF=none</txt-record>
  </service>
</service-group>

*.localに対する hosts の記述

*.local というドメイン名は、AppleのBonjour(zeroconf)固有のローカルドメイン名になります。これもAvahi-daemonが知らせてくれますので、
/etc/avahi/hosts というファイルにIPアドレスを書いておきます。

# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
# ・・・
192.168.1.2  xeroxcolor.local

ここで、192.168.1.2 は、実際に設置されているAirPrint対応のプリンタの、到達可能なIPアドレスの一例です。
WiFiルーターが端末に割り振るアドレスは192.168.1.x ではない、と仮定します。
(同一LANセグメントであれば、そもそもAvahi-daemonを入れなくてもプリンタが勝手にBonjourを喋ります)

Avahi-daemonを再起動します。

 $ sudo service avahi-daemon restart

デバッグ

$ avahi-browse -r -a

同一LAN上にあるBonjour(zeroconf)のサービス一覧(自分のマシンも含む)が表示されます。

補足

ここまでの説明で、プリンタ名.serviceをどうやって作成するかの説明が抜けています。
作成方法としては、

(1) AirPrint対応プリンタと同じLANセグメントにこのLinuxを接続して、

$ avahi-browse -r -a

の表示結果から*.service を書く。
(上記の

    <txt-record>・・・</txt-record>

のところを全部埋めていく。)という感じになります。

(2) AirPrintしたいPrinterがもともとAirPrint非対応の場合はCUPS経由でのprintを行うようにします。

CUPSサーバーを先にインストールして、LinuxからCUPS経由で印刷できることを確認しておきます。

そのあとでAvahi-daemonをインストールすれば、わりと自動でそのCUPSプリンタ.serviceファイルが作られます。

8
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?