root# aptitude install bridge-utils vlan pppoe root# vi /etc/network/filter-init #!/bin/sh #---NEVER EXECUTE BY HAND WHILE PPP-CONNECTION IS ACTIVE!--- /sbin/modprobe ip_nat_ftp /sbin/modprobe ip_nat_pptp /sbin/iptables -P INPUT DROP /sbin/iptables -P OUTPUT DROP /sbin/iptables -P FORWARD DROP /sbin/iptables -N input /sbin/iptables -F input /sbin/iptables -A input -i "!" "ppp+" -j RETURN /sbin/iptables -A input -j DROP /sbin/iptables -N output /sbin/iptables -F output /sbin/iptables -A output -o "!" "ppp+" -j RETURN /sbin/iptables -A output -j DROP /sbin/iptables -F INPUT /sbin/iptables -A INPUT -j input /sbin/iptables -F OUTPUT /sbin/iptables -A OUTPUT -j output /sbin/iptables -F FORWARD /sbin/iptables -A FORWARD -j input /sbin/iptables -A FORWARD -j output /sbin/iptables -P INPUT ACCEPT /sbin/iptables -P OUTPUT ACCEPT /sbin/iptables -P FORWARD ACCEPT /etc/network/filter-bf root# chmod +x /etc/network/filter-init次に、pppが有効になった時にinputおよびoutputに組み入れるチェインを作成します。 このスクリプトは上の初期化スクリプトから呼ばれます。
root# vi /etc/network/filter-bf
#!/bin/sh
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -N in-bf 2>/dev/null
/sbin/iptables -F in-bf
/sbin/iptables -A in-bf -m state --state ESTABLISHED,RELATED -j RETURN
/sbin/iptables -A in-bf -p icmp --icmp-type redirect -j DROP
/sbin/iptables -A in-bf -d 999.888.777.7 -j REJECT
/sbin/iptables -A in-bf -s 999.888.777.0/29 -j DROP
/sbin/iptables -A in-bf -s 10.0.0.0/8 -j DROP
/sbin/iptables -A in-bf -s 172.16.0.0/12 -j DROP
/sbin/iptables -A in-bf -s 192.168.0.0/16 -j DROP
/sbin/iptables -A in-bf -s 0.0.0.0/8 -j DROP
/sbin/iptables -A in-bf -s 127.0.0.0/8 -j DROP
/sbin/iptables -A in-bf -s 224.0.0.0/3 -j DROP
# 外からはpingのみ通過
/sbin/iptables -A in-bf -p icmp -d 999.888.777.1 --icmp-type echo-request
-j RETURN
# 他の許可はここに記述...
/sbin/iptables -A in-bf -j DROP
/sbin/iptables -N out-bf 2>/dev/null
/sbin/iptables -F out-bf
/sbin/iptables -A out-bf -p tcp --tcp-flags SYN,RST SYN -m tcpmss
--mss 1413: -j TCPMSS --set-mss 1412
/sbin/iptables -A out-bf -s 999.888.777.7 -j DROP
/sbin/iptables -A out-bf -d 999.888.777.0/29 -j DROP
/sbin/iptables -A out-bf -d 10.0.0.0/8 -j DROP
/sbin/iptables -A out-bf -d 172.16.0.0/12 -j DROP
/sbin/iptables -A out-bf -d 192.168.0.0/16 -j DROP
/sbin/iptables -A out-bf -d 0.0.0.0/8 -j DROP
/sbin/iptables -A out-bf -d 127.0.0.0/8 -j DROP
/sbin/iptables -A out-bf -d 224.0.0.0/3 -j DROP
/sbin/iptables -A out-bf -p udp --dport 137:139 -j DROP
/sbin/iptables -A out-bf -p tcp --dport 137:139 -j DROP
/sbin/iptables -A out-bf -p udp --dport 445 -j DROP
/sbin/iptables -A out-bf -p tcp --dport 445 -j DROP
/sbin/iptables -A out-bf -p udp --sport 137:139 -j DROP
/sbin/iptables -A out-bf -p tcp --sport 137:139 -j DROP
/sbin/iptables -A out-bf -p udp --sport 445 -j DROP
/sbin/iptables -A out-bf -p tcp --sport 445 -j DROP
/sbin/iptables -A out-bf -j RETURN
/sbin/iptables -t nat -N pre-bf 2>/dev/null
/sbin/iptables -t nat -F pre-bf
/sbin/iptables -t nat -N post-bf 2>/dev/null
/sbin/iptables -t nat -F post-bf
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT
root# chmod +x /etc/network/filter-bf
root# /etc/network/filter-init
filter-initを実行してフィルタを適用しておきます。
起動時に自動的に実行されるように、/etc/init.dにスクリプトを書くか、
下の例のようにeth0のpre-upで実行されるようにします。
/etc/interfacesにpppの設定を入れます。これでifupやifdownで起動ができます。 pon,poffとはかちあうんで、以後の試験はすべてifup,ifdownを用います。
root# vi /etc/network/interfaces
....(変更)
auto eth0
iface eth0 inet static
address 999.888.777.1
netmask 255.255.255.248
network 999.888.777.0
broadcast 999.888.777.7
pre-up /etc/network/filter-init || true フィルタの初期設定
auto bflets
iface bflets inet ppp
provider bflets
次に/etc/ppp/peers/bfletsの作成とパスワードのセット。
root# pppoe -A -I eth0.1 アクセスコンセントレータを得る Access-Concentrator: brasgp00basyo000 ←これ Got a cookie: 01 23 45 ... AC-Ethernet-Address: 00:12:44:12:34:56 -------------------------------------------------- root# vi /etc/ppp/peers/bflets ipparam bflets この名前が/etc/ppp/ip-up.dに渡ります。 user abcd1234@fbnf2.ocn.ne.jp plugin rp-pppoe.so eth0.1 rp_pppoe_ac brasgp00basyo000 カーネルモード #pty "pppoe -I eth0.1 -C brasgp00basyo000 -T 50 -m 1412" ユーザモードの場合 #connect /bin/true #999.888.777.1: #defaultroute hide-password lcp-echo-interval 15 lcp-echo-failure 10 lcp-max-configure 20 lcp-max-failure 20 noauth noproxyarp maxfail 0 persist holdoff 120 root# vi /etc/ppp/pap-secrets ...(追加) abcd1234@fbnf2.ocn.ne.jp * abcd12アクセスコンセントレータ名は指定しなくてもいいでしょう。 時々変更になったりしますし。 ここで、bfletsに接続してユーザ名とパスワードがあっているか調べます。 (ppp0はフィルタリングされているので、通信はされません。)
root# ifup bflets
root# (少したったら)plog
..... pppd[12345]: local IP address 999.888.777.0
pppd[12345]: remote IP address 222.333.444.13
root# ifdown bflets
このようにIPアドレスとして
ネットワークアドレス(999.888.777.0)が割り当てられます。
unnumberedにすべく、ppp0のアドレスとしては999.888.777.1を割り当てたいので、
/etc/ppp/peer/bfletsの999.888.777.1: の行を有効にしたいところですが、
pppの最近の版ではエラーになります。
ので、起動スクリプトを作成し、その中でppp0のアドレスを振りなおします。
root# vi /etc/ppp/ip-up.d/1local
#!/bin/sh
if [[ "$PPP_IPPARAM" == "bflets" ]] ; then
/sbin/ifconfig $PPP_IFACE 999.888.777.1
/sbin/route del default
/sbin/route add default dev $PPP_IFACE
/sbin/iptables -I input 1 -i $PPP_IFACE -j in-bf
/sbin/iptables -I input 2 -i $PPP_IFACE -j RETURN
/sbin/iptables -I output 1 -o $PPP_IFACE -j out-bf
/sbin/iptables -I output 2 -o $PPP_IFACE -j RETURN
/sbin/iptables -t nat -A PREROUTING -i $PPP_IFACE -j pre-bf
/sbin/iptables -t nat -A POSTROUTING -o $PPP_IFACE -j post-bf
fi
root# chmod +x /etc/ppp/ip-up.d/1local
root# vi /etc/ppp/ip-down.d/1local
#!/bin/sh
if [[ "$PPP_IPPARAM" == "bflets" ]] ; then
/sbin/iptables -D input -i $PPP_IFACE -j RETURN
/sbin/iptables -D input -i $PPP_IFACE -j in-bf
/sbin/iptables -D output -o $PPP_IFACE -j RETURN
/sbin/iptables -D output -o $PPP_IFACE -j out-bf
/sbin/iptables -t nat -D PREROUTING -i $PPP_IFACE -j pre-bf
/sbin/iptables -t nat -D POSTROUTING -o $PPP_IFACE -j post-bf
fi
# chmod +x /etc/ppp/ip-down.d/1local
これで接続時にアドレスの振りなおしおよびフィルタ適用がされます。
ipup bfletsして、適用されているフィルタの確認(iptables -L -n -v)、 外へpingが通ること及び外からこのマシンへpingが通ること、 他のサービスへ外から接続できないことを確認します。 うまくいったらrebootして、同様にチェックします。
サービスを公開するには、/etc/network/filter-bfを編集してフィルタを開けて /etc/network/filter-bfを再実行します。ppp接続中でもかまいません。