[FreeBSD-users-jp 95846] Re: ipfwとDNS
丸山直昌
maruyama @ ism.ac.jp
2016年 7月 11日 (月) 03:23:23 UTC
青木 様
Sun, 10 Jul 2016 17:55:51 +0900
Tomoaki AOKI <junchoon at dec.sakura.ne.jp> writes:
>一応念の為。
>
>FreeBSDだと
> 1./etc/defaults/rc.confを読み込む。
ええ、それは承知しています。PC-BSDではこの /etc/defaults/rc.conf の中に
rc_conf_files="/etc/rc.conf.pcbsd /etc/rc.conf /etc/rc.conf.local"
という行がある(つまり元祖FreeBSDの /etc/defaults/rc.conf をいじって
いる)ので、
2./etc/rc.conf.pcbsdを読む
3./etc/rc.confを読む
4./etc/rc.conf.localがあれば読む
となります。なお、/etc/rc.conf.pcbsd の中で重要な設定は
pcdm_enable="YES"
で、これを rc.conf で NO に設定すると、一見したところFreeBSDと区別がつか
なくなると思います。
> 2./etc/rc.confがあれば/etc/defaults/rc.conf内の処理で読み込む。
> 3./etc/rc.conf.localがあれば/etc/defaults/rc.conf内の処理で読み込む。
> 4./etc/defaults/vendor.confがあれば/etc/defaults/rc.conf内の処理で
> 読み込む。
>という流れになっており、後の設定で前の設定を上書きできるようになって
>おり、デフォルトでは、/etc/defaults/rc.confしか存在しません。
>一応の使い分けとして、
>
> ・/etc/defaults/rc.confはFreeBSDの動作上必要な設定のデフォルトを
> 纏めてあり、管理者・ユーザによる編集は一切想定しない。
従って、PC-BSDが /etc/defaults/rc.conf の中の rc_conf_files という変数を
いじったのは、元祖 FreeBSDの設計者の「想定外」かも知れませんね。
> ・/etc/rc.confはサイト(職場や自宅)内の全サーバ・端末で共通の
> 設定を行う。 デフォルトで不都合のある場合のみ作成要。
>
> ・/etc/rc.conf.localはそのサーバ・端末固有の設定を行う。
> /etc/rc.confまでの設定で不都合のある場合のみ作成要。
このような「階層的な」考えは私には非常に納得できるのもですが、しかしそれ
なら hostname や ifconfig_(インターフェース名)は/etc/rc.conf.local に入
れるべき、という議論になると思います。FreeBSDのインストーラーではどう設
定されますか?また皆さんはどうしていますか?PC-BSDはこれらは
/etc/rc.conf に設定されてしまいます。
(引用途中略)
>/etc/defaults/vendor.confを使う意味は、ベンダーとしての保証上、何がなん
>でもユーザ側で上書きされると困る設定がある場合への対応でしょうか。
>PC-BSDでそちらを使っていないのなら、「設定したのに反映されない。 なん
>で?」という不平を産んでまで強制したい設定は無い、ということでしょう。
>
>...と書いていて気になったのでsvnwebで確認したら、stable/10では
>/etc/defaults/vendor.donfに関する処理は入っていませんでした。 11系から
>の新機能のようです。 もしかするとPC-BSDの10系からはこちらの仕組みが
>使われるかも?
というより、 PC-BSDの /etc/rc.conf.pcbsd を「参考にして」、あるいは「影
響されて」/etc/defaults/vendor.conf が 11 で導入されたのではないですか?
PC-BSDは、FreeBSDを基本としながらも、いくかの点で「本家FreeBSDの改良を先
導したい」というような意図を感じるところがあります。例えば package がtbz
から txz に変わったのは、本家 FreeBSDよりも PC-BSDの方が先でした。このよ
うな態度を取るPC-BSDのチームが本家FreeBSDのコアメンバーとどういう人間関
係なのか、私は少し気になっていたのですが、今回PC-BSDのKris Mooreが
Core.9 に加わった(7月6日の FreeBSD-Announce参照)ので、PC-BSDとFreeBSDの
間の「乖離」はこれまでよりも少なくなるだろうと考えています。
>> # grep firewall rc.conf.pcbsd
>> firewall_enable="YES"
>> firewall_type="open"
>> firewall_enable="YES"
>> firewall_script="/etc/ipfw.rules"
>> firewall_type="open"
>>
>> となっております。
>
>/etc/ipfw.rulesというのはPC-BSD独自のようですね。
>FreeBSDの場合、/etc/defaults/rc.confにfirewall_script="/etc/rc.firewall"
>の設定がありますので、/etc/rc.firewallを置き換える形で使うことになり
>ます。 従って、同じfirewall_type="open"でもFreeBSDと処理が異なる
>可能性があります。
PC-BSD10.2, 10.3 の /etc/ipfw.rules は以下のようになっております。
#!/bin/sh
# To re-apply rules, you can run "sh /etc/ipfw.rules"
# Flush out the list before we begin.
ipfw -q -f flush
# Set rules command prefix
cmd="ipfw -q add"
# No restrictions on loopback
####################################################################
$cmd 00020 allow all from any to any via lo0
####################################################################
# Check the state of packets
####################################################################
$cmd 01000 check-state
$cmd 01050 allow tcp from any to any established
$cmd 01100 allow udp from any to any established
####################################################################
# Allow all outgoing packets
####################################################################
$cmd 02000 allow ip from any to any out keep-state
$cmd 02050 allow ip6 from any to any out keep-state
$cmd 02100 allow ipv6-icmp from any to any keep-state
$cmd 02150 allow icmp from any to any keep-state
####################################################################
# Allow specific ports IN now
# Add items to /etc/ipfw.openports in the format
# {tcp|udp} <portnum>
####################################################################
nextnum=10000
if [ -e "/etc/ipfw.openports" ] ; then
while read line
do
echo $line | grep -q "^#"
if [ $? -eq 0 ] ; then continue ; fi
proto="`echo $line | awk '{print $1}'`"
port="`echo $line | awk '{print $2}'`"
if [ -z "$proto" -o -z "$port" ] ; then continue ; fi
$cmd $nextnum allow $proto from any to any $port in keep-state
nextnum=`expr $nextnum + 1`
done < /etc/ipfw.openports
fi
####################################################################
# Allow specific IPs incoming traffic now (Used for jails mainly)
# Add items to /etc/ipfw.openip in the format
# {ip4|ip6} <ip>
####################################################################
nextnum=20000
if [ -e "/etc/ipfw.openip" ] ; then
while read line
do
echo $line | grep -q "^#"
if [ $? -eq 0 ] ; then continue ; fi
proto="`echo $line | awk '{print $1}'`"
ip="`echo $line | awk '{print $2}'`"
if [ -z "$proto" -o -z "$ip" ] ; then continue ; fi
$cmd $nextnum allow $proto from any to $ip in keep-state
nextnum=`expr $nextnum + 1`
done < /etc/ipfw.openip
fi
####################################################################
# Deny all other incoming troublemakers
####################################################################
$cmd 64000 deny log all from any to any
####################################################################
# Check for user custom rules
if [ -e "/etc/ipfw.custom" ] ; then
sh /etc/ipfw.custom
fi
>> PC-BSD をNFSサーバーにするには、あと /etc/hosts.allow もいじる必要があり
>> ますが、皆様に披露するような話でもないと思いますので、省略します。
>
>潜在的に需要はありそうな気もしますが、少なくともFreeBSDではこのファイル
>自体が事例集のようになっているので、見たいという声が挙がったらでいいか
>と。
PD-BSD10.2 の /etc/hosts.allow は以下の通りです。
#
# hosts.allow access control file for "tcp wrapped" applications.
# $FreeBSD: src/etc/hosts.allow,v 1.19.8.1 2006/02/19 14:57:01 ume Exp $
#
# NOTE: The hosts.deny file is deprecated.
# Place both 'allow' and 'deny' rules in the hosts.allow file.
# See hosts_options(5) for the format of this file.
# hosts_access(5) no longer fully applies.
# _____ _ _
# | ____| __ __ __ _ _ __ ___ _ __ | | ___ | |
# | _| \ \/ / / _` | | '_ ` _ \ | '_ \ | | / _ \ | |
# | |___ > < | (_| | | | | | | | | |_) | | | | __/ |_|
# |_____| /_/\_\ \__,_| |_| |_| |_| | .__/ |_| \___| (_)
# |_|
# !!! This is an example! You will need to modify it for your specific
# !!! requirements!
# Start by allowing everything (this prevents the rest of the file
# from working, so remove it when you need protection).
# The rules here work on a "First match wins" basis.
#ALL : ALL : allow
# Wrapping sshd(8) is not normally a good idea, but if you
# need to do it, here's how
#sshd : .evil.cracker.example.com : deny
# Protect against simple DNS spoofing attacks by checking that the
# forward and reverse records for the remote host match. If a mismatch
# occurs, access is denied, and any positive ident response within
# 20 seconds is logged. No protection is afforded against DNS poisoning,
# IP spoofing or more complicated attacks. Hosts with no reverse DNS
# pass this rule.
ALL : PARANOID : RFC931 20 : deny
# Allow anything from localhost. Note that an IP address (not a host
# name) *MUST* be specified for rpcbind(8).
ALL : localhost 127.0.0.1 : allow
# Comment out next line if you build libwrap with NO_INET6=yes.
ALL : [::1] : allow
ALL : my.machine.example.com 192.0.2.35 : allow
# To use IPv6 addresses you must enclose them in []'s
ALL : [fe80::%fxp0]/10 : allow
ALL : [fe80::]/10 : deny
ALL : [2001:db8:2:1:2:3:4:3fe1] : deny
ALL : [2001:db8:2:1::]/64 : allow
# Sendmail can help protect you against spammers and relay-rapers
sendmail : localhost : allow
sendmail : .nice.guy.example.com : allow
sendmail : .evil.cracker.example.com : deny
sendmail : ALL : allow
# Exim is an alternative to sendmail, available in the ports tree
exim : localhost : allow
exim : .nice.guy.example.com : allow
exim : .evil.cracker.example.com : deny
exim : ALL : allow
# Rpcbind is used for all RPC services; protect your NFS!
# (IP addresses rather than hostnames *MUST* be used here)
rpcbind : 192.0.2.32/255.255.255.224 : allow
rpcbind : 192.0.2.96/255.255.255.224 : allow
rpcbind : ALL : deny
# NIS master server. Only local nets should have access
ypserv : localhost : allow
ypserv : .unsafe.my.net.example.com : deny
ypserv : .my.net.example.com : allow
ypserv : ALL : deny
# Provide a small amount of protection for ftpd
ftpd : localhost : allow
ftpd : .nice.guy.example.com : allow
ftpd : .evil.cracker.example.com : deny
ftpd : ALL : allow
# You need to be clever with finger; do _not_ backfinger!! You can easily
# start a "finger war".
fingerd : ALL \
: spawn (echo Finger. | \
/usr/bin/mail -s "tcpd\: %u@%h[%a] fingered me!" root) & \
: deny
# The rest of the daemons are protected.
#ALL : ALL \
# : severity auth.info \
# : twist /bin/echo "You are not welcome to use %d from %h."
# denyhosts
sshd : /etc/hosts.deniedssh : deny
sshd : ALL : allow
--------
丸山直昌@統計数理研究所
freebsd-users-jp メーリングリストの案内