This shows you the differences between two versions of the page.
| — |
vps:vps4th2nd_04 [2019/06/16 15:16] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== prisoner fw設定 ====== | ||
| + | prisonerのfwをfirewallとnatboxにする。 | ||
| + | |||
| + | ===== 事前設定 ===== | ||
| + | jailerから各設定ファイルを直接編集する。各設定ファイルのプレフィックスは/usr/jail/fwとなる。 | ||
| + | |||
| + | * etc/syslog.confでconsole出力をコメント化する。<code> | ||
| + | # *.err;kern.warning;auth.notice;mail.crit /dev/console | ||
| + | </code> | ||
| + | * etc/crontabで不要なcronをコメント化する。<code> | ||
| + | # 1,31 0-5 * * * root adjkerntz -a | ||
| + | </code> | ||
| + | * etc/pw.confを新規作成する。prisoner内のuid, gidとjailerのuid, gidが同じになるとセキュリティ上の問題が発生するため、uid, gidの範囲を設定する。<code> | ||
| + | minuid 2001 | ||
| + | maxuid 2100 | ||
| + | mingid 2001 | ||
| + | maxgid 2100 | ||
| + | </code> | ||
| + | * etc/fstabをtouchで作成する。 | ||
| + | * etc/resolv.confを作成する。<code> | ||
| + | domain "ドメイン名" | ||
| + | nameserver "さくらのVPS指定 1" | ||
| + | nameserver "さくらのVPS指定 2" | ||
| + | </code> | ||
| + | * etc/hostsにfw自身と内側のホスト(jailer, prisoner)を登録する。<code> | ||
| + | 127.0.0.1 localhost localhost.example.com | ||
| + | <Global IP> fw fw.example.com | ||
| + | <Global IP> fw.example.com. | ||
| + | 192.168.100.254 gw gw.example.com | ||
| + | 192.168.100.254 gw.example.com. | ||
| + | 192.168.100.1 web web.example.com | ||
| + | 192.168.100.2 desktop desktop.example.com | ||
| + | 192.168.100.253 vps vps.example.com | ||
| + | </code> | ||
| + | * etc/rc.confを新規作成する。<code> | ||
| + | hostname="fw.example.com" | ||
| + | ifconfig_vtnet0="inet <Global IP> netmask <netmask>" | ||
| + | ifconfig_epair1b="inet 192.168.100.254 netmask 255.255.255.0" | ||
| + | gateway_enable="YES" | ||
| + | defaultrouter="<さくらのVPS指定>" | ||
| + | firewall_enable="YES" | ||
| + | firewall_type="/etc/fw.txt" | ||
| + | firewall_logging="YES" | ||
| + | firewall_nat_enable="YES" | ||
| + | </code> | ||
| + | * ifcofig_epair1b\\ jailerで作成したepair1の一端。jailerからprisonerであるfwに割り当てる。 | ||
| + | * firewall_type\\ 指定したファイルにfirewallのルールが記載される。 | ||
| + | |||
| + | ===== OS設定 ===== | ||
| + | prisoner:fwを起動後、以下の設定を行う。 | ||
| + | * prisoner:fwへ移動<code> | ||
| + | # jexec fw /bin/sh | ||
| + | </code> | ||
| + | * newaliasesの実行<code> | ||
| + | # newaliases | ||
| + | /etc/mail/aliases: 27 aliases, longest 10byte, 275 bytes total | ||
| + | </code> | ||
| + | * bsdconfigでそれぞれ設定。 | ||
| + | * Root Password | ||
| + | * User Management | ||
| + | * Time Zone | ||
| + | |||
| + | ===== ipfwルール設定(例) ===== | ||
| + | /etc/rc.confで指定したfirewall_type="/etc/fw.txt"を作成する。 | ||
| + | * /etc/fw.txt<code> | ||
| + | -f flush | ||
| + | |||
| + | # nat設定 desktop向け ssh | ||
| + | add nat 1 log tcp from any to <Global IP> <外部向けsshポート> | ||
| + | nat 1 config log redirect_port tcp 192.168.100.2:<内部向けsshポート> <Global IP>:<外部向けsshポート> | ||
| + | add nat 2 log tcp from 192.168.100.2 <内部向けsshポート> to any | ||
| + | nat 2 config log redirect_port tcp 192.168.100.2:<内部向けsshポート> <Global IP>:<外部向けsshポート> | ||
| + | |||
| + | # nat設定 web向け http | ||
| + | add nat 3 log tcp from any to <Global IP> 80 | ||
| + | nat 3 config log redirect_port tcp 192.168.100.1:80 <Global IP>:80 | ||
| + | add nat 4 log tcp from 192.168.100.1 80 to any | ||
| + | nat 4 config log redirect_port tcp 192.168.100.1:80 <Global IP>:80 | ||
| + | |||
| + | # nat設定 web向け https | ||
| + | add nat 5 log tcp from any to <Global IP> 443 | ||
| + | nat 5 config log redirect_port tcp 192.168.100.1:443 <Global IP>:443 | ||
| + | add nat 6 log tcp from 192.168.100.1 443 to any | ||
| + | nat 6 config log redirect_port tcp 192.168.100.1:443 <Global IP>:443 | ||
| + | |||
| + | # nat設定 desktop向け novnc | ||
| + | add nat 7 log tcp from any to <Global IP> <外部向けnovncポート> | ||
| + | nat 7 config log redirect_port tcp 192.168.100.2:<内部向けnovncポート> <Global IP>:<外部向けnovncポート> | ||
| + | add nat 8 log tcp from 192.168.100.2 <内部向けnovncポート> to any | ||
| + | nat 8 config log redirect_port tcp 192.168.100.2:<内部向けnovncポート> <Global IP>:<外部向けnovncポート> | ||
| + | |||
| + | # nat設定 内部から外部 | ||
| + | add nat 9 log ipv4 from any to any via <Global IP> | ||
| + | nat 9 config log ip <Global IP> | ||
| + | |||
| + | # ルール | ||
| + | add check-state | ||
| + | add deny log all from any to 192.168.100.0/24 in recv <Global IP> | ||
| + | add allow log tcp from any to 192.168.100.2 <内部向けsshポート> | ||
| + | add allow log tcp from any to 192.168.100.2 <内部向けnovncポート> | ||
| + | add allow log tcp from any to 192.168.100.1 80 | ||
| + | add allow log tcp from any to 192.168.100.1 443 | ||
| + | add allow log ip from 192.168.100.0/24 to any keep-state | ||
| + | add allow log ip from 127.0.0.1 to 127.0.0.1 | ||
| + | </code> | ||
| + | * Global IP\\ em0に割り当てたIP | ||
| + | * 外部向けsshポート\\ 22から変更した方が無難かも | ||
| + | * 内部向けsshポート\\ desktopのssh listenポート | ||
| + | * add allow log ip from 127.0.0.1 to 127.0.0.1\\ fwのメールが Permission Deniedになるため開放 | ||
| + | * /etc/fw.txt作成後、有効にする為、ipfwを再起動する。<code> | ||
| + | # service ipfw restart | ||
| + | </code> | ||