| ADSL (Flet's ADSL : rp-pppoe) |
我が家でもついにFlet's ADSLを導入した。 そこで、linuxでADSLに接続して、IP masqueradeして パソコンからもアクセスできるようにする。
Flet's ADSLにはlinux用の接続ツールが用意されている。 が、rp-pppoeという接続ツールを使うことにした。 RP-PPPoEのサイト がある。
| ダウンロードとインストール |
rp-pppoeはRedHat 7.1でデフォルトでインストールされている。 が、RedHatにあるのは、/etc/rc.d/init.d/adslが入っておらず、 起動時にadsl接続ができない(正確にはできないのではなくて面倒くさい) ので、RP-PPPoEのページからダウンロードする。 バージョンは3.3-1が出ている。RedHat6.2用のrpmで問題無く使える。
ちなみに、RedHat7.2を入れたが、そこのデフォルトのものも起動スクリプトがなかった・・・。
# cd /usr/local/src/rpm # rpm -ivh rp-pppoe-3.3-1.i386.rpm Preparing... ########################################### [100%] 1:rp-pppoe ########################################### [100%]
Vineでも同じものが使われているはず。
| 関連ファイル |
| /etc/ppp/firewall-masq | ファイアウォールタイプを MASQUERADEを選択した時に実行される。 |
| /etc/ppp/firewall-standalone | ファイアウォールタイプを STANDALONEを選択した時に実行される。 |
| /etc/rc.d/init.d/adsl | 起動時に自動接続するためのスクリプト |
| /usr/sbin/pppoe | PPPoEの本体プログラム |
| /usr/sbin/adsl-setup | PPPoEクライアントの設定するスクリプト |
| /usr/sbin/adsl-connect | ADSL回線を接続するためのスクリプト |
| /usr/sbin/adsl-start | ADSL回線を接続開始スクリプト。 内部でadsl-connectを呼び出している。 |
| /usr/sbin/adsl-status | ADSL回線の状態を見るスクリプト |
| /usr/sbin/adsl-stop | ADSL回線を接続を切断するスクリプト |
| pppoeの設定 |
設定は設定用のツールが用意されているのでそれを使う。
まずはユーザネームを聞かれる。 プロバイダからの情報をもとに記入。
# adsl-setup Welcome to the Roaring Penguin ADSL client setup. First, I will run some checks on your system to make sure the PPPoE client is installed properly... Looks good! Now, please enter some information: USER NAME >>> Enter your PPPoE user name (default ????@?????.??.??): moke@provider.com
つづいて、ADSLに接続するデバイス名を聞かれる。 私のところでは、eth0がローカルでeth1がインターネット側につながって いるのでeth1。
INTERFACE >>> Enter the Ethernet interface connected to the ADSL modem For Solaris, this is likely to be something like /dev/hme0. For Linux, it will be ethn, where 'n' is a number. (default eth1): eth1
次は、IDLE時間が何秒あったら切断するかを設定する。 定額料金なので、切断はなしにする。
Do you want the link to come up on demand, or stay up continuously? If you want it to come up on demand, enter the idle time in seconds after which the link should be dropped. If you want the link to stay up permanently, enter 'no' (two letters, lower-case.) NOTE: Demand-activated links do not interact well with dynamic IP addresses. You may have some problems with demand-activated links. >>> Enter the demand value (default no): no
次は、DNSの設定をする。 内部でDNSを持っている場合は、何も記入しないで良い。 持たない場合は、ISPより送られてきたDNSサーバのIPを書く。 自動でDNSの割当の場合は、serverと書く。
DNS Please enter the IP address of your ISP's primary DNS server. If your ISP claims that 'the server will provide DNS addresses', enter 'server' (all lower-case) here. If you just press enter, I will assume you know what you are doing and not modify your DNS setup. >>> Enter the DNS information here: 記入しない
次は、passwardの設定をする。 ISPのpasswardを入力する。
PASSWORD >>> Please enter your PPPoE password: ISP passward >>> Please re-enter your PPPoE password: 再度 ISP passward
次は、接続時のFIREWALLの設定である。 なにもしない時は0、server単独として動かす時は1、 IP masqueradeなどして、routerとして動かす時は2を設定する。
FIREWALLING
Please choose the firewall rules to use. Note that these rules are
very basic. You are strongly encouraged to use a more sophisticated
firewall setup; however, these will provide basic security. If you
are running any servers on your machine, you must choose 'NONE' and
set up firewalling yourself. Otherwise, the firewall rules will deny
access to all standard servers like Web, e-mail, ftp, etc. If you
are using SSH, the rules will block outgoing SSH connections which
allocate a privileged source port.
The firewall choices are:
0 - NONE: This script will not set any firewall rules. You are responsible
for ensuring the security of your machine. You are STRONGLY
recommended to use some kind of firewall rules.
1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
for a LAN
>>> Choose a type of firewall (0-2): 2
最後に変更して良いか聞かれる。
** Summary of what you entered ** Ethernet Interface: eth1 User name: moke@provider.com Activate-on-demand: No DNS: Do not adjust Firewalling: MASQUERADE >>> Accept these settings and adjust configuration files (y/n)? y Adjusting /etc/ppp/pppoe.conf Adjusting /etc/ppp/pap-secrets and /etc/ppp/chap-secrets (But first backing it up to /etc/ppp/pap-secrets-bak) (But first backing it up to /etc/ppp/chap-secrets-bak) Congratulations, it should be all set up! Type 'adsl-start' to bring up your ADSL link and 'adsl-stop' to bring it down. Type 'adsl-status' to see the link status.
これで設定が完了する。
| FIREWALL |
接続を開始した時に、STANDALONEタイプなら /etc/ppp/firewall-standaloneが呼び出され、 MASQUERADEタイプならば /etc/ppp/firewall-masqが呼び出される。 これを編集すれば独自のFIREWALL設定にすることが可能である。 まずは、それぞれipchainsを使っているので、iptables環境の人は iptablesに変換しなければならない。のちのち、セキュリティーのことは 考えるとして、今回はひとまず、MASQUERADE環境が動くようにだけする /etc/ppp/firewall-masqを紹介する。
#!/bin/sh # # firewall-masq This script sets up firewall rules for a machine # acting as a masquerading gateway # # Copyright (C) 2000 Roaring Penguin Software Inc. This software may # be distributed under the terms of the GNU General Public License, version # 2 or any later version. # Interface to Internet EXTIF=ppp+ ANY=0.0.0.0/0 # それぞれのポリシーを設定する。 iptables -P INPUT ACCEPT iptables -P OUTPUT ACCEPT iptables -P FORWARD DROP # すべてのルールを消去する。 iptables -F FORWARD iptables -F INPUT iptables -F OUTPUT iptables -F -t nat # 特権ポート(privileged ports)を塞いでいる。 # Deny TCP and UDP packets to privileged ports #ipchains -A input -l -i $EXTIF -d $ANY 0:1023 -p udp -j DENY #ipchains -A input -l -i $EXTIF -d $ANY 0:1023 -p tcp -j DENY iptables -A INPUT -i $EXTIF -d $ANY -p tcp --dport 0:1023 -j DROP iptables -A INPUT -i $EXTIF -d $ANY -p udp --dport 0:1023 -j DROP # TCPのコネクションを要求された場合に # そのパケットはすてる。 # Deny TCP connection attempts #ipchains -A input -l -i $EXTIF -p tcp -y -j DENY iptables -A INPUT -i $EXTIF -p tcp --syn -j DROP # ICMPのリクエスト(つまりping) # に答えないようにしている。 # Deny ICMP echo-requests #ipchains -A input -l -i $EXTIF -s $ANY echo-request -p icmp -j DENY iptables -A INPUT -i $EXTIF -s $ANY -p icmp --icmp-type echo-request -j DROP # マスカレード設定 # Do masquerading #ipchains -A forward -j MASQ iptables -A FORWARD -s 192.168.1.0/24 -j ACCEPT iptables -A FORWARD -d 192.168.1.0/24 -j ACCEPT iptables -t nat -A POSTROUTING -j MASQUERADE echo 1 > /proc/sys/net/ipv4/ip_forward |
一応こんな感じでつながりましたが、これではセキュリティ的によくないで
しょう。FIREWALLの設定は、FIREWALL(iptables)で考えます。
くれぐれもいいますが、このままで運用しないようにして下さい。!
FIREWALLの項を参考にして下さい
| 動作確認 |
まずはADSLを接続してみよう。自動起動スクリプトにstartの引数を与え て起動する。
# /etc/rc.d/init.d/adsl start Bringing up ADSL link.. Connected! [ OK ]
上記のように Connected! [ OK ]が出れば接続完了。
adsl-statusで接続状態を確認する。 起動スクリプトでもadsl-statusを呼び出しているので同じです。
$ /etc/rc.d/init.d/adsl status または adsl-status
adsl-status: Link is up and running on interface ppp0
ppp0 Link encap:Point-to-Point Protocol
inet addr:xxx.xxx.xxx.xxx P-t-P:yyy.yyy.yyy.yyy Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1454 Metric:1
RX packets:530 errors:0 dropped:0 overruns:0 frame:0
TX packets:454 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
物理的にはeth1でつながっているのですが、IPアドレスとかは、 ppp0に割り当てられる。eth1は立ち上がっているだけの状態となる。 ifconfigで確認すると
# ifconfig eth1
eth1 Link encap:Ethernet HWaddr 00:90:99:17:60:8F
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2631 errors:0 dropped:0 overruns:0 frame:0
TX packets:3135 errors:0 dropped:0 overruns:0 carrier:0
collisions:2 txqueuelen:100
RX bytes:704576 (688.0 Kb) TX bytes:322374 (314.8 Kb)
Interrupt:5 Base address:0xc000
# ifconfig ppp0
ppp0 Link encap:Point-to-Point Protocol
inet addr:xxx.xxx.xxx.xxx P-t-P:yyy.yyy.yyy.yyy Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1454 Metric:1
RX packets:353 errors:0 dropped:0 overruns:0 frame:0
TX packets:376 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:83601 (81.6 Kb) TX bytes:43056 (42.0 Kb)
となっている。
xxx.xxx.xxx.xxxが実際に割り当てられたIPで yyy.yyy.yyy.yyyがプロバイダ側のルータのIPとなる。 実際にpingをうってみる。
$ ping yyy.yyy.yyy.yyy PING yyy.yyy.yyy.yyy (yyy.yyy.yyy.yyy) from xxx.xxx.xxx.xxx : 56(84) bytes of data. 64 bytes from yyy.yyy.yyy.yyy: icmp_seq=0 ttl=255 time=32.149 msec 64 bytes from yyy.yyy.yyy.yyy: icmp_seq=1 ttl=255 time=39.896 msec 64 bytes from yyy.yyy.yyy.yyy: icmp_seq=2 ttl=255 time=39.901 msec 64 bytes from yyy.yyy.yyy.yyy: icmp_seq=3 ttl=255 time=29.902 msec 64 bytes from yyy.yyy.yyy.yyy: icmp_seq=4 ttl=255 time=29.895 msec 64 bytes from yyy.yyy.yyy.yyy: icmp_seq=5 ttl=255 time=39.879 msec 64 bytes from yyy.yyy.yyy.yyy: icmp_seq=6 ttl=255 time=39.906 msec 64 bytes from yyy.yyy.yyy.yyy: icmp_seq=7 ttl=255 time=39.900 msec 64 bytes from yyy.yyy.yyy.yyy: icmp_seq=8 ttl=255 time=39.890 msec 実際にはずーとつづくのでこの辺でCtrl-Cでとめる。 --- yyy.yyy.yyy.yyy ping statistics --- 9 packets transmitted, 9 packets received, 0% packet loss round-trip min/avg/max/mdev = 29.895/36.813/39.906/4.402 ms
うまくいっているようだ。うまくping通らない場合は、 物理的な接続があっているか確認してみる。 あるいは、Packet Filterがかかっていないか。 つづいて、外側にpingをうってみる。 有名なwww.yahoo.co.jpに
$ ping www.yahoo.co.jp PING www.yahoo.co.jp (210.152.236.111) from xxx.xxx.xxx.xxx : 56(84) bytes of data. 64 bytes from w01.yahoo.co.jp (210.152.236.111): icmp_seq=0 ttl=243 time=497.347 msec 64 bytes from w01.yahoo.co.jp (210.152.236.111): icmp_seq=1 ttl=243 time=479.853 msec 64 bytes from w01.yahoo.co.jp (210.152.236.111): icmp_seq=2 ttl=243 time=499.869 msec 64 bytes from w01.yahoo.co.jp (210.152.236.111): icmp_seq=3 ttl=243 time=369.872 msec 64 bytes from w01.yahoo.co.jp (210.152.236.111): icmp_seq=4 ttl=243 time=339.883 msec 64 bytes from w01.yahoo.co.jp (210.152.236.111): icmp_seq=5 ttl=243 time=419.865 msec 64 bytes from w01.yahoo.co.jp (210.152.236.111): icmp_seq=6 ttl=243 time=389.875 msec 64 bytes from w01.yahoo.co.jp (210.152.236.111): icmp_seq=7 ttl=243 time=469.862 msec 実際にはずーとつづくのでこの辺でCtrl-Cでとめる。 --- www.yahoo.co.jp ping statistics --- 8 packets transmitted, 8 packets received, 0% packet loss round-trip min/avg/max/mdev = 339.883/433.303/499.869/57.938 ms
これもうまくいっている。
最後にADSLを切断してみよう。自動起動スクリプトにstopの引数を与え て止める
# /etc/rc.d/init.d/adsl stop Shutting down ADSL link[ OK ]
上記のようになればOKです。念の為外にpingをうってみましょう。
# ping www.yahoo.co.jp ping: unknown host www.yahoo.co.jp
通らなくなっている。