VyOS cronの設定
https://wiki.vyos-users.jp/index.php/タスクスケジューラ
・スクリプトの設置
$ sudo vi /config/scripts/test.sh $ sudo chmod 755 /config/scripts/test.sh
・cronの設定
$ configure set system task-schedule task TEST executable path /config/scripts/test.sh set system task-schedule task TEST interval 30m or set system task-schedule task TEST crontab-spec "*/30 * * * *" commit save exit
VyOS プロキシの設定(ver 1.1.8)
・公式情報
https://wiki.vyos.net/wiki/Webproxy
・透過型プロキシとして動作
set service webproxy listen-address 192.168.0.1
・通常のプロキシとして動作
set service webproxy listen-address 192.168.0.1 disable-transparent
・動作ポートの変更
set service webproxy default-port 8080 ※デフォルトポートは3128
・キャッシュサイズの変更
set service webproxy cache-size 10 ※デフォルトは100MB
・アクセスログ確認
# show webproxy log
・プロキシ設定確認
# cat /etc/squid3/squid.conf
・ブラックリストファイルのダウンロード
# update webproxy blacklists
・ブラックリストの定期アップデート(毎日1回)
set service webproxy url-filtering squidguard auto-update update-hour 5
・ブラックリストの情報確認
show webproxy blacklist <TAB>
・ブラックリストの検索
show webproxy blacklist search .jp
・ブラックリストの適用
set service webproxy url-filtering squidguard block-category 'ads' set service webproxy url-filtering squidguard default-action 'allow' ※adsカテゴリは禁止、それ以外は許可
・個別ブロック設定
set service webproxy url-filtering squidguard local-block-keyword '(.*yahoo.*)' ※URLに「yahoo」の文字列を含む場合はブロックする ※ブロックに使うリストは下記から取得したものを加工して投入すると良い https://280blocker.net
・例外許可設定
set service webproxy url-filtering squidguard local-ok amazon.co.jp set service webproxy url-filtering squidguard local-ok 192.168.0.1
VyOS OpenVPNの設定(ver 1.1.8)
・公式情報
https://wiki.vyos.net/wiki/OpenVPN
・rootパスワードの設定
set system login user root authentication plaintext-password "rootのパスワード"
・証明書作成
$ su - # cp -rv /usr/share/doc/openvpn/examples/easy-rsa/2.0/ /config/easy-rsa2-my # cd /config/easy-rsa2-my # vi vars ※有効期限関連の設定は長めの期間に変更しておくこと ※DHの暗号長は2048以上にする # source vars # ./clean-all # ./build-ca # ./build-dh # ./build-key-server server # ./build-key client01 # mkdir /config/auth/ovpn # cp keys/ca.crt /config/auth/ovpn/ # cp keys/dh2048.pem /config/auth/ovpn/ # cp keys/server.key /config/auth/ovpn/ # cp keys/server.crt /config/auth/ovpn/ # cp keys/client* /config/auth/ovpn/
・ネットワーク構成
(インターネット) - [eth1] - VyOS - [eth0] - (内部セグメント) - [vtun0] - (仮想セグメント)
・OpenVPNサーバ設定
set interfaces openvpn vtun0 mode server set interfaces openvpn vtun0 openvpn-option "--proto tcp" set interfaces openvpn vtun0 openvpn-option "--port 5501" set interfaces openvpn vtun0 server subnet 192.168.100.0/24 set interfaces openvpn vtun0 openvpn-option "--client-to-client" set interfaces openvpn vtun0 openvpn-option "--comp-lzo yes" set interfaces openvpn vtun0 openvpn-option '--mssfix 1280' set interfaces openvpn vtun0 tls ca-cert-file '/config/auth/ovpn/ca.crt' set interfaces openvpn vtun0 tls cert-file '/config/auth/ovpn/server.crt' set interfaces openvpn vtun0 tls dh-file '/config/auth/ovpn/dh2048.pem' set interfaces openvpn vtun0 tls key-file '/config/auth/ovpn/server.key' ※セキュリティを向上させる場合には下記も設定 set interfaces openvpn vtun0 encryption 'aes256' set interfaces openvpn vtun0 hash 'sha512' ※クライアント側設定には下記を設定 cipher AES-256-CBC auth sha512
・ファイアウォール設定(外部→VyOS)
※外部からVyOSへのOpenVPNアクセスを許可する ※「in」ではなく「local」に適用すること set firewall name OUT_LOCAL rule 20 action 'accept' set firewall name OUT_LOCAL rule 20 destination port '5501' set firewall name OUT_LOCAL rule 20 state new 'enable' set interfaces ethernet eth1 firewall local name OUT_IN
・状態確認/再起動
show openvpn server status ps -ef | grep openvpn show configuration commands | grep openvpn monitor openvpn & grep openvpn /var/log/messages reset openvpn interface vtun0
・DstNATとSrcNATで仮想セグメントから物理セグメントにアクセスできるようにする
set nat destination rule 100 inbound-interface 'vtun0' set nat destination rule 100 destination address '192.168.100.100' set nat destination rule 100 translation address '192.168.0.100' set nat destination rule 101 inbound-interface 'vtun0' set nat destination rule 101 destination address '192.168.100.101' set nat destination rule 101 translation address '192.168.0.101' set nat source rule 100 outbound-interface 'eth0' set nat source rule 100 source address '192.168.100.0/24' set nat source rule 100 translation address '192.168.0.98' ※vtun0が受信した 192.168.100.100 宛ての通信は 192.168.0.100 に転送する ※192.168.100.0/24宛ての通信は送信元を 192.168.0.98 に変更して eth0 から送信する
KVM VyOSのインストールと設定(ver 1.1.8)
・公式情報
https://wiki.vyos-users.jp/
https://wiki.vyos.net/
・インストール
# qemu-img create -f qcow2 /usr/local/var/lib/libvirt/images/vyos.qcow2 2G # virt-install \ --connect qemu:///system \ --name vyos \ --vcpus 1 \ --ram 512 \ --network bridge=br0 \ --network bridge=br1 \ --file /usr/local/var/lib/libvirt/images/vyos.qcow2 \ --cdrom /usr/local/src/vyos-1.1.8-amd64.iso \ --nographics install image reboot
・コンソールから接続
# virsh console vyos
・設定の確認、変更、保存
show configuration show configuration commands configure ※設定モードに変更 set ... ※値を設定 delete ... ※値を削除 compare 0 ※直近の設定と比較 commit ※設定を反映 save ※設定を保存 exit ※設定モードから抜ける
・SSHの設定
set service ssh port '22'
・タイムゾーン設定
set system time-zone Asia/Tokyo date
・ネットワーク構成
(インターネット) - [ [pppoe 0] [eth1] ] - VyOS - [eth0] - (内部セグメント)
・内部インターフェースの設定
set interfaces ethernet eth0 description 'INSIDE' set interfaces ethernet eth0 address '192.168.0.1/24' set interfaces ethernet eth0 duplex 'auto' set interfaces ethernet eth0 speed 'auto'
・外部インターフェースの設定(PPPoE)
set interfaces ethernet eth1 description 'OUTSIDE' set interfaces ethernet eth1 pppoe 0 set interfaces ethernet eth1 pppoe 0 user-id [ユーザー名] set interfaces ethernet eth1 pppoe 0 password [パスワード] set interfaces ethernet eth1 pppoe 0 default-route auto set interfaces ethernet eth1 pppoe 0 name-server auto show interfaces pppoe
・MTU調整
set policy route PPPoE-IN rule 10 protocol tcp set policy route PPPoE-IN rule 10 set tcp-mss 1414 set policy route PPPoE-IN rule 10 tcp flags SYN set interfaces ethernet eth0 policy route PPPoE-IN set interfaces ethernet eth1 pppoe 0 policy route PPPoE-IN
set service dhcp-server disabled 'false' set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 default-router '192.168.0.1' set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 dns-server '192.168.0.1' set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 domain-name 'internal-network' set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 lease '86400' set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 start 192.168.0.10 stop '192.168.0.50' set service dns forwarding cache-size '0' set service dns forwarding listen-on 'eth0' set service dns forwarding name-server '8.8.8.8' ※PPPoEで取得したDNSサーバ以外に問い合わせをしたい場合は設定 set service dns forwarding name-server '8.8.4.4' ※PPPoEで取得したDNSサーバ以外に問い合わせをしたい場合は設定
・SrcNAT設定(内部→外部)
set nat source rule 10 source address '192.168.0.0/24' set nat source rule 10 translation address 'masquerade' set nat source rule 10 outbound-interface 'pppoe0' ※下記を指定して、内部からインターネットに疎通できるようにする ・SrcNATの対象となる送信元アドレス ・SrcNAT後のアドレス(masquerade を指定すればVyOSが可変アドレスに対応してくれる) ・インターネット側と通信するインターフェース
・DstNAT設定(外部→内部 ポートフォワード)
set nat destination rule 1 protocol 'tcp_udp' set nat destination rule 1 inbound-interface 'eth1' set nat destination rule 1 destination port '5501' set nat destination rule 1 translation address '192.168.0.107' ※eth1 5501ポートあての通信を 192.168.0.107 に転送する
・ファイアウォール設定の考え方
・「ポリシーセット」を作成して「インターフェース」の「out、in、local」のどれかに割り当てる ・out … インターフェースを通過して、出て行く通信 ・in … インターフェースを通過して、入ってくる通信 ・local … インターフェース自身への通信
・ファイアウォール設定(外部→VyOS)
set firewall name OUT_LOCAL default-action 'drop' set firewall name OUT_LOCAL rule 10 action 'accept' set firewall name OUT_LOCAL rule 10 state established 'enable' set firewall name OUT_LOCAL rule 10 state related 'enable' set interfaces ethernet eth1 pppoe 0 firewall local name 'OUT_LOCAL' ※上記ポリシーセットを外部向けインターフェースのlocalに割り当てて 「VyOS自身が起点となる通信とその折り返し通信は許可、それ以外は拒否」にする。 ※pppoeインターフェースにも適用すること。 適用しないとVyOS自身のSSH等のポートがインターネットに解放されてしまう。
・ファイアウォール設定(外部→内部)
set firewall name OUT_IN default-action 'drop' set firewall name OUT_IN rule 10 action 'accept' set firewall name OUT_IN rule 10 state established 'enable' set firewall name OUT_IN rule 10 state related 'enable' set firewall name OUT_IN rule 20 action 'accept' set firewall name OUT_IN rule 20 protocol 'tcp_udp' set firewall name OUT_IN rule 20 destination port '5501' set firewall name OUT_IN rule 20 state new 'enable' set interfaces ethernet eth1 pppoe 0 firewall in name 'OUT_IN' ※上記ポリシーセットを外部向けインターフェースのinに割り当てて 「折り返し通信、および5501ポート宛の通信は許可、それ以外は拒否」にする。 ※pppoeインターフェースにも適用すること。
・ファイアウォール設定(内部→外部)
※内部が起点となる通信で、拒否したいものがあれば設定する
KVM CPUのリソース制限
・物理コアとVCPUの紐付け
仮想マシンのVCPUがどの物理コアを使用するか制限する。
特定コアのみ使用するように制限すればCPUのキャッシュヒット率が向上し、性能が上昇する可能性がある。
# virsh vcpupin VM_NAME 0 0-1 # virsh vcpupin VM_NAME 1 2-3 # virsh vcpuinfo VM_NAME VCPU: 0 CPU: 0 State: running CPU time: 952862.4s CPU Affinity: yy-- VCPU: 1 CPU: 3 State: running CPU time: 937542.2s CPU Affinity: --yy
・物理コアの利用優先度の設定
複数仮想マシンに対して同一物理コアが割り当てられた場合の利用優先度を設定する。
cpu_shares の比率で利用時間が配分される。
# virsh schedinfo VM_NAME --set cpu_shares=2 ※「2」が優先度最低 # virsh schedinfo VM_NAME Scheduler : posix cpu_shares : 2 vcpu_period : 100000 vcpu_quota : -1
・CPU処理利用時間の制限
仮想マシンに対するCPU処理時間の割り当てを制限する。
vcpu_period の期間内で「CPU処理時間の合計」> vcpu_quota となると、それ以上はCPUを使用できなくなる。
CPU処理時間は仮想CPU全体で合計されるため、period < quota と設定する場合もある。
例えば仮想CPUを4コア割り当てている仮想マシンの場合、
vcpu_period=100000 vcpu_quota=400000 とすればCPUを100%使用できるが、
vcpu_period=100000 vcpu_quota=200000 とすれば50%に制限される。
# virsh schedinfo VM_NAME --set vcpu_period=100000 vcpu_quota=200000 # virsh schedinfo VM_NAME Scheduler : posix cpu_shares : 1024 vcpu_period : 100000 vcpu_quota : 200000 ※「-1」を指定すると制限なしとなる
・設定の恒久化
コマンドラインで設定した値は仮想マシンを停止すると失われるため、恒久化する場合は
仮想マシン設定に下記設定を追加する。
<domain> <cputune> <vcpupin vcpu="0" cpuset="0,1"/> <vcpupin vcpu="1" cpuset="2,3"/> <shares>2</shares> <vcpu_period>100000</vcpu_period> <vcpu_quota>200000</vcpu_quota> </cputune> </domain>
Linux sambaでファイル操作ログを出力する
・ログ出力したいセクションに設定追加
# vi /etc/samba/smb.conf [XXXX] vfs objects = full_audit full_audit: = local1 full_audit:priority = info full_audit:prefix = %m|%I|%S full_audit:success = read ※ファイル読み込みに成功したログを syslog のファシリティ local1 に出力する
※各パラメータの意味は下記参照
http://www.samba.gr.jp/project/translation/3.5/htmldocs/manpages-3/vfs_full_audit.8.html
・rsyslog にログ出力設定追加
# vi /etc/rsyslog.conf local1.* /var/log/samba.log ※ファシリティ local1 のログを samba.log に出力する
・設定反映
# systemctl restart smb.service # systemctl restart rsyslog.service
・ログローテート設定(必要に応じて実施)
http://d.hatena.ne.jp/kt_hiro/20121207/1354889595