イー・モバイルとDebianでルータ

引っ越して自宅ネットワークが1ヶ月くらい使えないことになったので、衝動的にイー・モバイルスーパーライトデータプランに契約してしまいました。新二年なので2年間やめられませんが、月々最低1000円、いくら使っても上限4980円というのに惹かれました。
さて、1代のPCではもったいないので、自宅サーバをルータにしてNATしてみることにしました。以下はそのメモです。イー・モバイル端末はD02HW、OSはDebianのLenny(カーネル2.6.26)です。

接続するまで

D02HWをUSBポートに接続すると、USB CD-ROMとGSMモデムが認識されます。(ログは最後に示します。)/dev/sr0をマウントしようとしてもメディアが見つからないと言われるし、なぜCD-ROMなのかがよくわかりません。(WindowsMac用のドライバが入っているには違いないのですが。)
以下のサイトを参考に、/etc/ppp/peers/emを作成しました。
DebianLinuxイー・モバイルD02HWを使用する(プラグアンドプレイ対応)
http://d.hatena.ne.jp/Ubuntu/20080525/emobile_on_linux
さらに、/etc/network/interfacesにgateway記述を持つ定義があるとPPP接続時にゲートウェイが変わらないようだったので、interfacesからgatewayの記述を削除しました。
設定してD02HWをつなぎ、sudo pon em ですんなりつながってしまいました。

ルータにする

次にルータとして動作させるための設定です。以下を参考にしました。
tips/イーモバイル D02HW でルータ
http://f14.aaa.livedoor.jp/~javaappl/index.php?tips%2F%A5%A4%A1%BC%A5%E2%A5%D0%A5%A4%A5%EB%20D02HW%20%A4%C7%A5%EB%A1%BC%A5%BF
こちらに書かれている内容に従って設定を作成しました。以下を変更しました。

  • dhcpd.confでrangeの範囲やサブネットのアドレスを変更する。
  • 1iptablesで、
    • myhost、trusthostの値を変更する。
    • sshを許す部分のiptablesコマンド2行目を削除
    • もちろんプレステ関係は削除

DNSサーバでタイムアウト

このサーバは本来某ドメインセカンダリDNSなので、bindが動いています。dhcpでもこのサーバをDNSとして配布するようにしました。ところが、外部のサイトにアクセスしようとすると、一度目はDNSが引けずにエラーとなり、もう一度アクセスすると大丈夫という具合でした。
syslogには、

Oct 11 11:39:14 discovery named[3787]: too many timeouts resolving 'blogspot.l.google.com/A' (in 'l.google.com'?): disabling EDNS

というログが多量に記録されていました。実は以前から出ていたログだったみたいですが、これまで気づいていなかったようです。問題にならなかったのが不思議です。
調べたら、以下のような情報が見つかりました。
BIND(DNS)での備忘メモ
http://d.hatena.ne.jp/KuroNeko666/20060127/1138368421
これらの情報に従って、named.confの内向きview定義の中に、以下のように記述することでDNS解決の遅れはなくなりました。

forwarders {
        xxx.xxx.xxx.xxx; // emobileがくれたサーバ
};
server xxx.xxx.xxx.xxx { edns no; }; // こちらが大事

sambaの制限

このサーバにはsambaが動いています。これまではルータの下にいたのであまり気にしていませんでしたが、インターネットに直結されることになるので、sambaのブロードキャストが心配になりました。(外からのアクセスそのものはiptablesで止められています。)
以下の設定をsmb.confで有効にしてみました。

interfaces = 127.0.0.0/8 eth0
bind interfaces only = yes

まとめ

これで家庭内では複数のPCが問題なく使えるようになりました。とはいえ、イー・モバイルって要は携帯な訳で、携帯の電波が常時出ていると思うと気分的に暑くなりますね。

おまけ:認識時のログ

[  212.432074] usb 2-2: new full speed USB device using uhci_hcd and address 2
[  212.588135] usb 2-2: configuration #1 chosen from 1 choice
[  212.592532] usb 2-2: New USB device found, idVendor=12d1, idProduct=1003
[  212.592624] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  212.592695] usb 2-2: Product: HUAWEI Mobile
[  212.592751] usb 2-2: Manufacturer: HUAWEI Technologies
[  212.928560] Initializing USB Mass Storage driver...
[  212.932947] scsi0 : SCSI emulation for USB Mass Storage devices
[  212.934451] usbcore: registered new interface driver usb-storage
[  212.934547] USB Mass Storage support registered.
[  212.936871] usb 2-2: USB disconnect, address 2
[  212.951737] usb-storage: device found at 2
[  212.951758] usb-storage: waiting for device to settle before scanning
[  213.672070] usb 2-2: new full speed USB device using uhci_hcd and address 3
[  213.828489] usb 2-2: configuration #1 chosen from 1 choice
[  213.828489] usb-storage: probe of 2-2:1.0 failed with error -5
[  213.834323] usb-storage: probe of 2-2:1.1 failed with error -5
[  213.836799] scsi3 : SCSI emulation for USB Mass Storage devices
[  213.844609] usb 2-2: New USB device found, idVendor=12d1, idProduct=1003
[  213.844706] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  213.844782] usb 2-2: Product: HUAWEI Mobile
[  213.844842] usb 2-2: Manufacturer: HUAWEI Technologies
[  213.845758] usb-storage: device found at 3
[  213.845775] usb-storage: waiting for device to settle before scanning
[  214.821794] usbcore: registered new interface driver usbserial
[  214.821910] usbserial: USB Serial support registered for generic
[  214.822045] usbcore: registered new interface driver usbserial_generic
[  214.822113] usbserial: USB Serial Driver core
[  214.843831] usbserial: USB Serial support registered for GSM modem (1-port)
[  214.843976] option 2-2:1.0: GSM modem (1-port) converter detected
[  214.844256] usb 2-2: GSM modem (1-port) converter now attached to ttyUSB0
[  214.844349] option 2-2:1.1: GSM modem (1-port) converter detected
[  214.844537] usb 2-2: GSM modem (1-port) converter now attached to ttyUSB1
[  214.844634] usbcore: registered new interface driver option
[  214.844697] option: USB Driver for GSM modems: v0.7.2
[  218.845912] usb-storage: device scan complete
[  218.848765] scsi 3:0:0:0: CD-ROM            HUAWEI   Mass Storage     2.31 PQ: 0 ANSI: 2
[  219.195131] Driver 'sr' needs updating - please use bus_type methods
[  219.216487] sr0: scsi-1 drive
[  219.216487] Uniform CD-ROM driver Revision: 3.20
[  219.216487] sr 3:0:0:0: Attached scsi CD-ROM sr0
[  219.484636] sr 3:0:0:0: Attached scsi generic sg0 type 5