投げ銭

★当サイトへの投げ銭(PayPal)★

LINK


(無償、寄付歓迎) logo
世界中で使われるISO標準オフィスソフト(MSオフィス互換)

★LibreOfficeの導入事例★
詳細について

人気の投稿(1ヶ月間)

Ad

Ad

投げ銭

★当サイトへの投げ銭(PayPal)★

2018年3月31日土曜日

【RasPBX raspbx-03-12-2017】ip6tablesで設定するルールをシステム起動時にも反映させる【Raspberry Pi 2】


raspbx-03-12-2017.img で導入したRasPBXで、
iptables/ip6tablesで設定したルールをシステム再起動後にも継続させるために、
iptables-persistent パッケージを導入しようとしたところ、エラーが発生した。

# apt-get install iptables-persistent
(省略)
Unpacking netfilter-persistent (1.0.3+deb8u1) ...
Selecting previously unselected package iptables-persistent.
Preparing to unpack .../iptables-persistent_1.0.3+deb8u1_all.deb ...
Unpacking iptables-persistent (1.0.3+deb8u1) ...
Processing triggers for systemd (215-17+deb8u6) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up netfilter-persistent (1.0.3+deb8u1) ...
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
A dependency job for netfilter-persistent.service failed. See 'journalctl -xn' for details.
invoke-rc.d: initscript netfilter-persistent, action "start" failed.
dpkg: error processing package netfilter-persistent (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of iptables-persistent:
 iptables-persistent depends on netfilter-persistent (= 1.0.3+deb8u1); however:
  Package netfilter-persistent is not configured yet.
dpkg: error processing package iptables-persistent (--configure):
 dependency problems - leaving unconfigured
Processing triggers for systemd (215-17+deb8u6) ...
Errors were encountered while processing: netfilter-persistent iptables-persistentE: Sub-process /usr/bin/dpkg returned an error code (1)


■別の方法でシステム起動の際に自動的にIPフィルタルールを追加するようにした。

○適当な名前でルールを設定するスクリプトを作成した。
root@raspbx:~# nano /etc/ip6table.setting
/sbin/ip6tables -F
/sbin/ip6tables -P INPUT DROP
/sbin/ip6tables -P FORWARD DROP
/sbin/ip6tables -P OUTPUT ACCEPT
/sbin/ip6tables -A INPUT -i lo -j ACCEPT
/sbin/ip6tables -A INPUT -i eth0 -m state --state ESTABLISHED -j ACCEPT
/sbin/ip6tables -A INPUT -i eth0 -m state --state RELATED -j ACCEPT
/sbin/ip6tables -A INPUT -s fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
/sbin/ip6tables -A INPUT -s fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
/sbin/ip6tables -A INPUT -s fe80::/64 -j ACCEPT
○作成したスクリプトを実行できるようにした。
root@raspbx:~# chmod +x /etc/ip6table.setting

○問題なく実行できるか確認した。
root@raspbx:~# /etc/ip6table.setting

○起動時に実行されるrc.localファイルにスクリプトファイルのパスを追加した。
root@raspbx:~# nano /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Setting ip6tables rules
/etc/ip6table.setting 

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
exit 0

以上

【RASPBIAN STRETCH LITE March 2018】iptablesのルールをシステム再起動後でも自動的に反映できるようにする【Raspberry Pi 2】

RASPBIAN STRETCH LITE(March 2018) で、
iptablesや、ip6tablesを用いて設定したフィルタルールが、システムの再起動後にも自動的に反映されるように設定を行った。

CentOS6なら、serivce iptables save で保存でき、また再起動時の自動復元が可能だった。
RASPBIAN STRETCH LITE でも、保存とパッケージの追加だけで再起動時の復元ができた。
ただし、作法が異なった。

そのパッケージの導入後、
iptableや、ip6tablesコマンドで変更したルールは、iptables-saveや、ip6tables-saveコマンドを用いて、設定保存ファイルに出力できる。

設定保存ファイルの内容は、サービスによってシステム起動時に自動的に反映される。

以下で、パッケージの導入から、動作確認までを扱っている。



iptables-persistentの導入を行った。

○必要なパッケージを導入した。

インストール中に、TUIが現れてiptablesの設定とip6tablesの設定を保存するかどうかを聞かれる。
いずれも、<YES>で答えた。

root@raspberrypi:/home/pi# apt-get install iptables-persistent
Reading package lists... Done
Building dependency tree     
Reading state information... Done
The following additional packages will be installed:
  netfilter-persistent
The following NEW packages will be installed:
  iptables-persistent netfilter-persistent

0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 19.5 kB of archives.
After this operation, 79.9 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf netfilter-persistent all 1.0.4+nmu2 [8,792 B]
Get:2 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf iptables-persistent all 1.0.4+nmu2 [10.7 kB]
Fetched 19.5 kB in 1s (9,889 B/s)             
Preconfiguring packages ...
Selecting previously unselected package netfilter-persistent.
(Reading database ... 34547 files and directories currently installed.)
Preparing to unpack .../netfilter-persistent_1.0.4+nmu2_all.deb ...
Unpacking netfilter-persistent (1.0.4+nmu2) ...
Selecting previously unselected package iptables-persistent.
Preparing to unpack .../iptables-persistent_1.0.4+nmu2_all.deb ...
Unpacking iptables-persistent (1.0.4+nmu2) ...
Setting up netfilter-persistent (1.0.4+nmu2) ...
Created symlink /etc/systemd/system/multi-user.target.wants/netfilter-persistent.service → /lib/systemd/system/netfilter-persistent.service.
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Processing triggers for systemd (232-25+deb9u2) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up iptables-persistent (1.0.4+nmu2) ...

▲途中で、iptablesで既に設定されているルールを保存するかどうか尋ねられるので、<YES>で答えた。
これによって、システムの再起動の際に自動的にこのルールがロードされる。
ここで保存されたルールは後でも変更ができる。
Configuring iptables-persistent
Current iptables rules can be saved to the configuration file /etc/iptables/rules.v4.
These rules will then be loaded automatically during system startup.
Rules are only saved automatically during package installation.
See the manual page of iptables-save(8) for instructions on keeping the rules file up-to-date.
Save current IPv4 rules?<Yes><No>
▲ip6tablesについても同様である。
Configuring iptables-persistent
Current iptables rules can be saved to the configuration file /etc/iptables/rules.v6.
These rules will then be loaded automatically during system startup.
Rules are only saved automatically during package installation.
See the manual page of ip6tables-save(8) for instructions on keeping the rules file up-to-date.
Save current IPv6 rules?<Yes><No>
以上で導入自体は完了した。



■システム再起動後にルールが復元されるか確かめた

○実際に保存されていることを確認した。

# cat /etc/iptables/rules.v6
# Generated by ip6tables-save v1.6.0 on Fri Mar 30 15:35:44 2018
*filter
:INPUT DROP [8:736]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [18:1474]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -d fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
-A INPUT -d fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
-A INPUT -d ff02::/16 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
-A INPUT -d ff02::/16 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
COMMIT
# Completed on Fri Mar 30 15:35:44 2018

○システムを再起動してもルールが復元されているか確認した。

root@raspberrypi:/home/pi# reboot ←(注意)システムが再起動する。

root@raspberrypi:/home/pi# ip6tables -L -v
Chain INPUT (policy DROP 10 packets, 1598 bytes)
 pkts bytes target     prot opt in     out     source               destination       
    0     0 ACCEPT     all      any    any     anywhere             anywhere             state RELATED,ESTABLISHED
    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             fe80::/64            ipv6-icmp neighbour-solicitation
    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             fe80::/64            ipv6-icmp neighbour-advertisement
    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             ff02::/16            ipv6-icmp neighbour-solicitation
    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             ff02::/16            ipv6-icmp neighbour-advertisement
Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination       
Chain OUTPUT (policy ACCEPT 17 packets, 1954 bytes)
 pkts bytes target     prot opt in     out     source               destination
上記の通り、設定が復元されていた。


■後でルールを変更して有効化するか確認した。

(1)iptablesコマンドでルール変更する場合

○ルールを変更した。

FORWARDのポリシーをDROPに変更した。
root@raspberrypi:/home/pi# iptables -P FORWARD DROP


○変更したルールを保存した。

iptables-saveコマンドは設定内容をテキストに出力するだけ。
root@raspberrypi:/home/pi# iptables-save
# Generated by iptables-save v1.6.0 on Fri Mar 30 15:56:21 2018
*filter
:INPUT ACCEPT [22:1504]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [12:1136]
COMMIT
# Completed on Fri Mar 30 15:56:21 2018
したがって、このiptables-saveコマンドの出力を、先のルールファイルに書き込みした。
root@raspberrypi:/home/pi# iptables-save > /etc/iptables/rules.v4

書き込んだ内容を確認した。
root@raspberrypi:/home/pi# cat /etc/iptables/rules.v4
# Generated by iptables-save v1.6.0 on Fri Mar 30 15:56:37 2018
*filter
:INPUT ACCEPT [35:2392]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [20:2112]
COMMIT
# Completed on Fri Mar 30 15:56:37 2018

○システムを再起動してもルールが復元されているか確認した。

root@raspberrypi:/home/pi# reboot ←(注意)システムが再起動する。

root@raspberrypi:/home/pi# iptables -L -v
Chain INPUT (policy ACCEPT 87 packets, 9107 bytes)
 pkts bytes target     prot opt in     out     source               destination       
Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination       
Chain OUTPUT (policy ACCEPT 65 packets, 8767 bytes)
 pkts bytes target     prot opt in     out     source               destination
上記の通り、設定が復元されていた。


(2)直にルール設定ファイルを変更する場合

○直接、ルール設定ファイルを変更した。

root@raspberrypi:/home/pi# vi /etc/iptables/rules.v6
# Generated by ip6tables-save v1.6.0 on Fri Mar 30 15:35:44 2018
*filter
:INPUT DROP [8:736]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [18:1474]
-A INPUT -m state --state ESTABLISHED -j ACCEPT
-A INPUT -m state --state RELATED -j ACCEPT

-A INPUT -d fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
-A INPUT -d fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
-A INPUT -d ff02::/16 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
-A INPUT -d ff02::/16 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
COMMIT
# Completed on Fri Mar 30 15:35:44 2018

○この変更を反映させた。

サービスをrestartした。
root@raspberrypi:/home/pi# systemctl restart netfilter-persistent

反映されているか確認した。
root@raspberrypi:/home/pi# ip6tables -L -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination       
    0     0 ACCEPT     all      any    any     anywhere             anywhere             state ESTABLISHED
    0     0 ACCEPT     all      any    any     anywhere             anywhere             state RELATED

    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             fe80::/64            ipv6-icmp neighbour-solicitation
    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             fe80::/64            ipv6-icmp neighbour-advertisement
    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             ff02::/16            ipv6-icmp neighbour-solicitation
    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             ff02::/16            ipv6-icmp neighbour-advertisement
Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination       
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
システムを再起動しても、変更は保持され復元された。


新品価格
¥5,980から
(2018/3/30 01:45時点)

新品価格
¥2,160から
(2018/3/30 01:42時点)

<参考>
・Persistent IPtables on Raspberry Pi (Raspbian)
< http://blog.mxard.com/persistent-iptables-on-raspberry-pi-raspbian > 2018年3月31日

・Make the configuration of iptables persistent (Debian)
< http://www.microhowto.info/howto/make_the_configuration_of_iptables_persistent_on_debian.html > 2018年3月31日


2018年3月30日金曜日

【さくらVPS/東】ipv6tablesを設定する【Linux CentOS 6】

(更新 2018/8/1)ip6tablesの設定変更の必要あり

(注意)
8月1日以降、東京リージョンでは「(この記事内の旧情報)フィルタルール例」でうまく通信できなくなってしまった。
代わりに、ICMPv6関係では、次の設定を用いる必要があった。
ip6tables -A INPUT -d fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
ip6tables -A INPUT -d fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
ip6tables -A INPUT -d ff02::/16 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
ip6tables -A INPUT -d ff02::/16 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
ip6tables -A INPUT -s 2xxx:xxxx:xxxx:xxxx::1/128 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
ip6tables -A INPUT -s 2xxx:xxxx:xxxx:xxxx::1/128 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT

ip6tables -A INPUT -s fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
ip6tables -A INPUT -s fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
※2xxx:xxxx:xxxx:xxxx::1 は、割り当てられたGUAの先頭64bit::1である。

上記はICMPv6だけ抜粋したものです。
実際の通信には、さらに下記旧情報を参考にして、ICMPv6以外の設定を加える必要があります。

しかし、ip6tables -L -v コマンドで、通過パケットの統計情報を確認すると、
最後の2行(太字)で設定したパスフィルタにはパケットが通過しており、
それ以外のフィルタは0パケットのままだった。
このことから、ICMPv6で必要なのはただ2行分だけかもしれない。
さらに追跡調査する必要がある。


以下は、旧情報としてあげておきます。考え方は共通するものがあるので、
ご参考にしてください。


-----旧情報↓------

さくらのVPS環境(東)の仮想マシンでIPv6通信を行う場合、
次のようにip6tablesを設定すると、うまくインターネット側とのやりとりができた。
さくらVPSでは、IPアドレスは静的に設定するため、下記ではDHCP関係の通信は考慮していない。

下記に加えて、
インターネット側にあるマシンのGUAをACCEPTするフィルタをさらに追加することで、
インターネット側から開始する接続も可能になった。


■考え方

IPv6では、IPv4とは異なり、隣接するマシンを探索するブロードキャストでもIP通信を行う。

・ipv6-icmp neighbour-solicitation(icmpv6-type 135)
・pv6-icmp neighbour-advertisement(icmpv6-type 136) 

この2種類のICMPパケットの入力を許可しなければ、通信不可能になってしまう。

また、さくらのVPS環境では、このICMPパケットのフィルタリングルールで使うIPv6アドレスとして、何パターンか用意する必要があった。
無用な通信の入力を避けるため、AnyWhereは使用したくなかった。

下記の例では、ipv6-icmp neighbour パケットの入力と、ステートフルインスペクションを考慮して作成したものである。
しかしIPv6においてICMPの役割は重要で、これ以外のタイプのICMPの入力も必要になってくる。
例えば、パケットが大きすぎて経路上のルーターで分割が必要になった際に通知される情報もICMPの別のタイプで通知される。
下記の例では、これらの通知を受け取ることができない。

それでもとりあえず、下記の設定で、システムのアップデートを行うことができた。



■フィルタルール例

# cat /etc/sysconfig/ip6tables
# Generated by ip6tables-save v1.4.7 on Wed Mar 28 21:31:02 2018
*filter
:INPUT DROP [2:144]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [7219:625541]
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -m state --state ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -m state --state RELATED -j ACCEPT
-A INPUT -d fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
-A INPUT -d fe80::/64 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
-A INPUT -d ff02::/16 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
-A INPUT -d ff02::/16 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
-A INPUT -s 2xxx:xxxx:xxxx:xxxx::1 -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j ACCEPT
-A INPUT -s 2xxx:xxxx:xxxx:xxxx::1 -p ipv6-icmp -m icmp6 --icmpv6-type 136 -j ACCEPT
COMMIT
# Completed on Wed Mar 28 21:31:02 2018
※2xxx:xxxx:xxxx:xxxx::1 は、割り当てられたGUAの先頭64bit::1である。


○マシン起動直後に、各フィルタを通ったパケットの状態を表示させた。

# ip6tables -L -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination     
    0     0 ACCEPT     all      lo     any     anywhere             anywhere       
   27  5321 ACCEPT     all      eth0   any     anywhere             anywhere            state ESTABLISHED
    0     0 ACCEPT     all      eth0   any     anywhere             anywhere            state RELATED
    1    72 ACCEPT     ipv6-icmp    any    any     anywhere             fe80::/64           ipv6-icmp neighbour-solicitation
    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             fe80::/64           ipv6-icmp neighbour-advertisement
   15  1080 ACCEPT     ipv6-icmp    any    any     anywhere             ff02::/16           ipv6-icmp neighbour-solicitation
    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             ff02::/16           ipv6-icmp neighbour-advertisement
    1    72 ACCEPT     ipv6-icmp    any    any     2xxx:xxxx:xxxx:xxxx::1/128  anywhere            ipv6-icmp neighbour-solicitation
    1    72 ACCEPT     ipv6-icmp    any    any     2xxx:xxxx:xxxx:xxxx::1/128  anywhere            ipv6-icmp neighbour-advertisement     
   
   
Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination     

Chain OUTPUT (policy ACCEPT 45 packets, 6237 bytes)
 pkts bytes target     prot opt in     out     source               destination


○数分経過後に、同様に結果を表示させた。

# ip6tables -L -v
Chain INPUT (policy DROP 7 packets, 504 bytes)
 pkts bytes target     prot opt in     out     source               destination     
    0     0 ACCEPT     all      lo     any     anywhere             anywhere       
   42  6521 ACCEPT     all      eth0   any     anywhere             anywhere            state ESTABLISHED
    0     0 ACCEPT     all      eth0   any     anywhere             anywhere            state RELATED
  147 10584 ACCEPT     ipv6-icmp    any    any     anywhere             fe80::/64           ipv6-icmp neighbour-solicitation
  237 16240 ACCEPT     ipv6-icmp    any    any     anywhere             fe80::/64           ipv6-icmp neighbour-advertisement
  119  8568 ACCEPT     ipv6-icmp    any    any     anywhere             ff02::/16           ipv6-icmp neighbour-solicitation
    0     0 ACCEPT     ipv6-icmp    any    any     anywhere             ff02::/16           ipv6-icmp neighbour-advertisement
    1    72 ACCEPT     ipv6-icmp    any    any     2xxx:xxxx:xxxx:xxxx::1/128  anywhere            ipv6-icmp neighbour-solicitation
    1    72 ACCEPT     ipv6-icmp    any    any     2xxx:xxxx:xxxx:xxxx::1/128  anywhere            ipv6-icmp neighbour-advertisement      
   
   
Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination     

Chain OUTPUT (policy ACCEPT 549 packets, 43501 bytes)
 pkts bytes target     prot opt in     out     source               destination



<参考>
・IPv6 - multicast address
< http://www.infraexpert.com/study/ipv6z10.html > 2018年3月30日

・VPS  OSセットアップ情報(CentOS 6)
< https://help.sakura.ad.jp/hc/ja/articles/206053672-OS%E3%82%BB%E3%83%83%E3%83%88%E3%82%A2%E3%83%83%E3%83%97%E6%83%85%E5%A0%B1-CentOS-6- > 2018年3月30日

【RASPBIAN STRETCH LITE March 2018】OSの導入、SSHの有効化、システムの更新【Raspberry Pi 2】

Raspberry pi 2 に、CentOSのminimalのようなOSを入れて、CUIのみで動作させたい。

以下は、この要件を満たしたOSの導入、SSHリモート接続、
そしてシステムの更新までの手順を記している。


■microSDに、OSイメージの書き込み

○RASPBIAN STRETCH LITE のダウンロード

RASPBIAN STRETCH LITEは、Raspberry pi のminimal版OSのようなものである。
グラフィカルな機能は省かれていて、CentOSのminimalイメージの位置付けと似ている。

下記、WEBサイトから、RASPBIAN STRETCH LITE をダウンロードした。(370MBほど)
https://www.raspberrypi.org/downloads/raspbian/
RASPBIAN STRETCH LITE
Minimal image based on Debian Stretch
Version:March 2018
Release date:2018-03-13
Kernel version:4.9
Release notes:Link
○zipファイルを展開(imgファイルを取り出し)

○ddコマンドで、SDカードに書き込み

imgファイルは、2GB程度の大きさだった。
余裕を持たせて、書き込みには16GBのmicroSDを使用した。

(例)microSDがsdXの場合
# dd if=./2018-03-13-raspbian-stretch-lite.img of=/dev/sdX



■SSHでリモートからログインできるようになるまでの設定

○直接コンソールからpiユーザーでログイン

Raspberry pi 2 に、「RASPBIAN STRETCH LITE」 を書き込んだmicoSDを取り付けて起動した。
Raspberry pi には、HDMIでモニターと、USBでキーボードが接続されている。

ユーザー pi、パスワード raspberry、でログインした。


○rootパスワードの設定

pi@raspberrypi:~ $ sudo passwd root
Enter new UNIX password: ←rootユーザーのパスワードを設定
Retype new UNIX password: ←確認のために入力
passwd: password updated successfully

○SSHを有効化

SSHはデフォルトでは無効化されている。
次のように空のファイルを作成すると有効化される。

まず、rootユーザーになった。
pi@raspberrypi:~ $ su
Password: 
/bootディレクトリに、sshという名前の空のファイルを作成した。
root@raspberrypi:/home/pi# touch /boot/ssh

再起動を行った。
root@raspberrypi:/home/pi# reboot

再起動後、SSHは有効になって、リモートからログインが可能になった。



■システムのアップデート

ブロードバンドルーターに接続したLANケーブルをRaspberry pi 2のLANコネクタに接続しておくだけで、
自動的にネットワークを認識し、インターネットとの通信が可能になった。
IPv6通信も可能だった。

(注意)
iptablesやip6tables の状態を確認すると、フィルタリングは未設定だった。
そのため、ブロードバンドルーターなどのファイアウォールの配下に接続すべきである。


○仮想端末tmuxのインストールと起動

システムのアップデート中に、不意にSSH接続が切れては困るので仮想端末を利用した。

root@raspberrypi:/home/pi# apt-get install tmux
root@raspberrypi:/home/pi# tmux


○システムのアップデート(tmux仮想端末で実行)

利用可能なパッケージリストの更新
root@raspberrypi:/home/pi# apt-get update

リストに基づいて実際にシステムをアップデート
root@raspberrypi:/home/pi# apt-get upgrade

完了後、マシンを再起動しておく。
root@raspberrypi:/home/pi# reboot

新品価格
¥5,980から
(2018/3/30 01:45時点)

新品価格
¥2,160から
(2018/3/30 01:42時点)


<参考>
・Minimal image?
< https://www.raspberrypi.org/forums/viewtopic.php?t=195347 > 2018年3月30日

・Raspberry Pi セットアップ(書き込み~SSH設定まで)
< https://qiita.com/Halhira/items/1da2ae543217be26988a > 2018年3月30日

・RaspberryPiをRaspbianで使う場合の初期設定メモ(ユーザ追加)
< https://qiita.com/R-STYLE/items/b481ba2d695ddf8bcee4 > 2018年3月30日

・「Raspberry Pi」(ラズベリーパイ)Linuxコマンド集・基本編
< http://www.stdio.jp/entry/raspberry_pi/linux-command-collection-basic > 2018年3月30日

2018年3月29日木曜日

【RasPBX raspbx-03-12-2017】完全バックアップを作成する方法(オンラインフォルダに差分データのみ転送する方法)【Raspberry Pi 2】



<転送先マシンでの設定>

○バックアップ保存先にするオンライン共有フォルダの準備

バックアップ保存先別マシンに、SAMBAを使って共有フォルダを作成した。
共有名は SHARE とし、BACKUPというサブフォルダを作成した。

ネットワーク経由で、問題なくこの共有フォルダにアクセスできることを確認した。
SAMBAユーザー名「sambauser」で書き込みができるようにした。 後で使用する。


○バックアップの核となるRasPBXのimgファイルをダウンロード

差分のみを転送するため、その核となるimgファイルを転送先に保存しておく。

# wget http://download.raspberry-asterisk.org/raspbx-03-12-2017.zip
# unzip raspbx-03-12-2017.zip
# ls -all
total 4690868
drwxr-xr-x 2 root root       4096 Mar 23 23:47 .
drwxr-xr-x 3 root root       4096 Mar 23 23:22 ..
-rw-r--r-- 1 root root 3904897024 Dec  3 03:30 raspbx-03-12-2017.img
-rw-r--r-- 1 root root  898532430 Dec  4 01:35 raspbx-03-12-2017.zip


<転送元であるRasPBXでの設定>

○rsyncをインストールしておく。

root@raspbx:~# apt-get install rsync


○上記で用意したオンライン上の共有フォルダを /mnt にマウントした。

マウントを行う。 (リモートマシンのファイル共有をマウント)
root@raspbx:~# mount -t cifs -o user=sambauser,password=PAssWoRD "//192.168.1.10/SHARE" /mnt/

マウントできたか確認した。
root@raspbx:~# ls /mnt
BACKUP
root@raspbx:~# ls /mnt/BACKUP/
raspbx-03-12-2017.img  raspbx-03-12-2017.zip
以上のように、リモートのファイル共有にアクセスできている。
差分バックアップの核にするimgファイルが見えている。


ファイル名の変更(バックアップだとわかるようにした。)

root@raspbx:~# cd /mnt/BACKUP/
root@raspbx:/mnt/BACKUP# mv raspbx-03-12-2017.img raspbx-backup.img

raspbx-backup.img を差分バックアップのための核となるファイルとする。

また、ここでパーミッションのエラーが出ずに、書き込みが成功するか確認できる。


○バックアップの開始

不意なSSH接続の切断に備えて、仮想端末のtmuxなどで動作させる。
なければ、apt-get install tmux で導入しておく。

仮想端末を起動した。
root@raspbx:/mnt/BACKUP# tmux

バックアップを開始した。
root@raspbx:/mnt/BACKUP# raspbx-backup raspbx-backup.img

差分の内容によるが、このときは、2.5GB程度のデータが転送された。


○バックアップ完了後はアンマウントしておく

root@raspbx:/mnt/BACKUP# cd /
root@raspbx:/# umount /mnt



<リストアの方法>

RasPBXが故障するなどして、リストアしなければならない場合、
以上で作成した、raspbx-backup.imgをddコマンドでSDカードへの書き込んで復元する。


新品価格
¥5,940から
(2018/3/29 23:00時点)

<参考>
・Backup your System
< http://www.raspberry-asterisk.org/documentation/backup-your-system/ > 2018年3月23日

2018年3月20日火曜日

【.Net Core 2.0】データベース接続文字列をappsettings.jsonに保存しプログラムから参照する方法



■データベース接続文字列をプログラムから参照できるように保存する。

○接続文字列の生成

Visual Studio 2017  ツール→データベースへの接続 から、ダイアログにしたがって、SQL Server を追加した。
すると、サーバーエクスプローラーに、追加したSQL Serverが表示される。
このプロパティーから接続文字列を拾い出した。(例)
Data Source=127.0.0.1\TESTinstance;Initial Catalog=testdb;Persist Security Info=True;User ID=sa;Password=abcdefg
(注意)
127.0.0.1\InstanceName で接続する場合、SQL Server browser を起動していなければならない。
初期状態では起動もしておらず、起動することもできない状態になっている。
コントロールパネル→管理ツール→サービス→SQL Server browser から、起動するように設定しておく。


○接続文字列情報の追加

appsettings.json の初期状態の内容を確認した。
{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }

  }

}
次のように、接続文字列情報を追加した。
参照用の名前は、testDatabase とした。
{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  },
"ConnectionStrings": {
    "testDatabase": "Data Source=127.0.0.1\TESTinstance;Initial Catalog=testdb;Persist Security Info=True;User ID=sa;Password=abcdefg;"
  }

}


■接続文字列を取得するコードを作成した。

○JSON形式の情報の読み取りに必要なパッケージの追加

NuGetで以下を追加した。

 Microsoft.Extensions.Configuration
 Microsoft.Extensions.Configuration.Json
 Microsoft.Extensions.Configuration.Binder


○取得までの流れ

IConfigurationRootのインスタンスを生成する。

このIConfigurationRootのインスタンスは、カレントディレクトリ内のappsettings.jsonを取り扱うメソッドを備えている。
たとえば、GetConnectionStringで、キーを指定して接続文字列を取得することができる。

IConfigurationRootのインスタンスは、ConfigurationBuilderインスタンス生成し設定したうえで、このBuildメソッドによって生成される。
このとき、appsettings.jsonへのパスは何らかの方法で指定しなければならない。


○appsettings.jsonへのパスを直接コードに埋め込む方法。
(実用的でない。これは動作テスト用である。)

IConfigurationRoot configuration = new ConfigurationBuilder()           .AddJsonFile(@"C:\Users\root\source\repos\WebApp_test01\WebApp_test01\appsettings.json", false)
 .Build();

string constr = configuration.GetConnectionString("testDatabase");


○appsettings.jsonへのパスを動的に取得する方法。

上の例では appsettings.json のパスが固定されているからいけない。
これを動的に指定したい。

また、共通して使えるIConfigurationRootのインスタンスは、プログラム起動時に一回だけ生成しておき、
後でいつでも参照できるようにしたい。

先ず、次のように、Programクラスに、staticメンバ(IConfigurationRoot configuration)を追加して、
Mainメソッド内でConfigurationBuilderによって生成したIConfigurationRootのインスタンスの参照を保存するようにする。
public class Program
    {
        public static IConfigurationRoot configuration;
        public static void Main(string[] args)
        {
         
            configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(@"appsettings.json", false).Build();       
            BuildWebHost(args).Run();
        }
        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();
    }
<略>
次に、appsettings.jsonを参照するには、次のように、
さきのProgramクラスを指定しその静的メンバであるconfigurationを参照することで、
先ほどのIConfigurationRootのインスタンスがもつアクセス用メソッドを呼び出す。
    public class MyRepository
    {
        public SqlConnection con; //using System.Data.SqlClient;
        private void connection()
        {
            string constr = Program.configuration.GetConnectionString("testDatabase");

            con = new SqlConnection(constr);
        }
<略>

以上


NuGet
System.Data.Common
System.Data.SqlClient


ASP.NET MVCプログラミング入門 (マイクロソフト関連書)

新品価格
¥3,456から
(2018/5/21 15:43時点)


<参考>

・I cannot start SQL Server browser
< https://stackoverflow.com/questions/21375014/i-cannot-start-sql-server-browser > 2018年3月17日

▲json形式ファイルに保存された接続文字列情報

・Configure an ASP.NET Core App / JSON configuration
< https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?tabs=basicconfiguration > 2018年3月20日

・Connection Strings/ASP.NET Core
< https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-strings#aspnet-core > 2018年3月17日

・.NET Core のコンソ-ルアプリケーションで設定ファイルを利用する
< https://qiita.com/abpla/items/c4faeed42bef4d450c8d >2018年3月18日

・Using .NET Core Configuration with legacy projects
< http://benfoster.io/blog/net-core-configuration-legacy-projects > 2018年3月18日

2018年3月19日月曜日

【Linux CentOS 7】デバイス名(/dev/sdX)のディスクが筐体内にある物理ディスクのうちどれかを調べる手順

例えば、システム内で無効にしたSATAディスクの物理的な取り外しを行いたい。
取り外したいデバイス名( /dev/sdX等 )はわかる。
しかし、それがマシン筐体内でどのディスクに相当するのかも知らなければならない。

以下では、システム内のディスク一覧と、そのディスクのシリアルナンバーを調べる方法について書いている。
シリアルナンバーがわかれば、ディスク本体に貼られているシール記載から見つけることができる。



○取り外したいディスクは、動作中システムにおいて無効にしておく。

たとえば、RAIDアレイのディスクであれば、専用コマンドで切り離しを行っておく。
http://akira-arets.blogspot.jp/2016/12/linux-centos7-softwareraid-add-hotspare.html

たとえば、マウントされているディスクであれば、アンマウントしておく。



○Linuxマシンに取り付けられているディスクの一覧を得る。

# lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda       8:0    0 232.9G  0 disk  
├─sda1    8:1    0   476M  0 part  /boot
├─sda2    8:2    0  46.6G  0 part  /
├─sda3    8:3    0    28G  0 part  /var
├─sda4    8:4    0     1K  0 part
├─sda5    8:5    0   9.3G  0 part  [SWAP]
└─sda6    8:6    0 148.6G  0 part  /home
sdb       8:16   0 931.5G  0 disk  
└─sdb1    8:17   0 930.4G  0 part
  └─md0   9:0    0 930.3G  0 raid1 /home/mDATA
sdc       8:32   0 931.5G  0 disk  
└─sdc1    8:33   0 930.4G  0 part
  └─md0   9:0    0 930.3G  0 raid1 /home/mDATA
sdd       8:48   0 931.5G  0 disk  
└─sdd1    8:49   0 930.4G  0 part
  └─md0   9:0    0 930.3G  0 raid1 /home/mDATA
sde       8:64   1 119.3G  0 disk
└─sde1    8:65   1 119.3G  0 part  /run/media/admin/xxxxxxxxxxxxxxxx


○ディスク固有の情報を得る。

仮に、上記の一覧より、/dev/sdX がターゲットのディスクだとすれば
次のようにコマンドを実行して、そのディスク固有のシリアル番号を得る。

# hdparm -i /dev/sdX
/dev/sdb:
 Model=TOSHIBA MK1002TSKB, FwRev=MT4A, SerialNo=ABCDEFGHI
 Config={ Fixed }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0
 BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=1953525168
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio1 pio2 pio3 pio4
 DMA modes:  sdma0 sdma1 sdma2 mdma0 mdma1 mdma2
 UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5
 AdvancedPM=yes: unknown setting WriteCache=enabled
 Drive conforms to: Unspecified:  ATA/ATAPI-3,4,5,6,7
 * signifies the current active mode


○筐体内のディスクの取り外し

マシンをシャットダウンし、電源をオフにした上で、
上記で調べたシリアル番号を持つディスクを、その製品ラベルから見つける。
該当するディスクを取り外す。




新品価格
¥15,272から
(2018/3/19 23:23時点)
<参考>

・How do I find out what hard disks are in the system?
< https://unix.stackexchange.com/questions/4561/how-do-i-find-out-what-hard-disks-are-in-the-system > 2018年3月19日

・Linux: Which physical disk is /dev/sdd?
< https://superuser.com/questions/427939/linux-which-physical-disk-is-dev-sdd > 2018年3月19日

2018年3月16日金曜日

【Linux CentOS 7】firewalld でなく、CentOS6のようにiptablesサービスを使う手順


CentOS 7 では、firewalld がデフォルトになっている。


# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: active (running) <略>
これによって、以下に挙げるようにルールが適用されている。
そのルールを見ると、プログラミングみたいに階層構造があって、ひたすら長い。
単純なサーバーだし、CentOS6みたいにもっと単純なのがいい。

自分は、CentOS6のiptablesサービスに慣れているので、
CentOS7でもそれと同じように設定したい。
インターネットに接続するサーバーの設定なので、自分で作成したルールも持っている。
それを適用したいのである。(ただし、インターフェイス名は修正する必要がある。)

不慣れなことをして、隙をつくってしまったら意味ない。



■せっかくなので、firewalldによって設定されているルールを一部だけ確認した。


# iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
       
    2   104 ACCEPT     all  --  any    any     anywhere             anywhere             ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere         
    0     0 INPUT_direct  all  --  any    any     anywhere             anywhere         
    0     0 INPUT_ZONES_SOURCE  all  --  any    any     anywhere             anywhere         
    0     0 INPUT_ZONES  all  --  any    any     anywhere             anywhere         
    0     0 DROP       all  --  any    any     anywhere             anywhere             ctstate INVALID
    0     0 REJECT     all  --  any    any     anywhere             anywhere             reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
       
    0     0 ACCEPT     all  --  any    any     anywhere             anywhere             ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere         
    0     0 FORWARD_direct  all  --  any    any     anywhere             anywhere         
    0     0 FORWARD_IN_ZONES_SOURCE  all  --  any    any     anywhere             anywhere         
    0     0 FORWARD_IN_ZONES  all  --  any    any     anywhere             anywhere         
    0     0 FORWARD_OUT_ZONES_SOURCE  all  --  any    any     anywhere             anywhere         
    0     0 FORWARD_OUT_ZONES  all  --  any    any     anywhere             anywhere         
    0     0 DROP       all  --  any    any     anywhere             anywhere             ctstate INVALID
    0     0 REJECT     all  --  any    any     anywhere             anywhere             reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT 2 packets, 104 bytes)
 pkts bytes target     prot opt in     out     source               destination
       
    2   104 OUTPUT_direct  all  --  any    any     anywhere             anywhere

このように、最初に、INPUT、FORWARD、OUTPUTチェインが定義されていて、
続いて、各チェインで参照されているターゲットが定義されている
(以下、一部のみ抜粋)

Chain INPUT_ZONES (1 references)
 pkts bytes target     prot opt in     out     source               destination       
    0     0 IN_public  all  --  wlp4s0 any     anywhere             anywhere            [goto]
    0     0 IN_public  all  --  +      any     anywhere             anywhere            [goto]
Chain INPUT_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination       
Chain INPUT_direct (1 references)
 pkts bytes target     prot opt in     out     source               destination       
Chain IN_public (2 references)
 pkts bytes target     prot opt in     out     source               destination       
    0     0 IN_public_log  all  --  any    any     anywhere             anywhere         
    0     0 IN_public_deny  all  --  any    any     anywhere             anywhere         
    0     0 IN_public_allow  all  --  any    any     anywhere             anywhere         
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere         
Chain IN_public_allow (1 references)
 pkts bytes target     prot opt in     out     source               destination       
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp dpt:ssh ctstate NEW
Chain IN_public_deny (1 references)
 pkts bytes target     prot opt in     out     source               destination       
Chain IN_public_log (1 references)
 pkts bytes target     prot opt in     out     source               destination

以上は、INPUTチェインをルートとして定義を追ったものである。
ACCEPTだけで受けずに、まず別のチェインで受けることで、階層的に定義がされていることがわかる



■firewallでなく従来のように、iptablesコマンドで一つずつルールを設定する。

しかし、ここでは自分で従来のようにルールを管理したいので、
firewalldを無効にし、自分で定義を行いたい。

(注意)
ファイアウォールの定義を変更するため、リモートターミナルは切断される。
必ずローカルでコンソールから設定を行う。


○iptablesを導入した。

# yum install iptables-services
インストール:
  iptables-services.x86_64 0:1.4.21-18.3.el7_4
依存性を更新しました:
  iptables.x86_64 0:1.4.21-18.3.el7_4                                     
完了しました!

# yum info iptables-services
名前                : iptables-services
アーキテクチャー    : x86_64
バージョン          : 1.4.21
リリース            : 18.3.el7_4
容量                : 25 k
リポジトリー        : installed
提供元リポジトリー  : updates
要約                : iptables and ip6tables services for iptables
URL                 : http://www.netfilter.org/
ライセンス          : GPLv2
説明                : iptables services for IPv4 and IPv6
                    :
                    : This package provides the services iptables and ip6tables that have been split
                    : out of the base package since they are not active by default anymore.

(注意)
以下の手順にすすむ前に、無防備の状態を避けるため、
安全なローカルネットワーク環境で行うか、
予め、LAN接続を断つか、無効にしておく。


○firewalld を停止し、無効にする。

systemctl stop firewalld
systemctl disable firewalld

disableにすることで、システムを再起動しても firewalld は起動しない。


○代わって、iptables サービスを起動し、有効化する。

# systemctl start iptables
# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
enableにすることで、システム起動時に iptablesサービス が起動する。

(注意)
ip6tables と、iptablesは別個のサービスである。
もし同様にして、ip6tablesを設定しているなら、
ip6tablesの起動(systemctl start ip6tables)と、
自動起動(systemctl enable ip6tables)の設定も忘れないこと。


この状態で、ルールは自動的に次のようになっていた。

# iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination       
 4623 2499K ACCEPT     all  --  any    any     anywhere             anywhere             state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere         
  252 16372 ACCEPT     all  --  lo     any     anywhere             anywhere         
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere             state NEW tcp dpt:ssh
    3   577 REJECT     all  --  any    any     anywhere             anywhere             reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination       
    0     0 REJECT     all  --  any    any     anywhere             anywhere             reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT 5231 packets, 1654K bytes)
 pkts bytes target     prot opt in     out     source               destination
あるいは、コンフフィグ直接ファイルを表示する。

# cat /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

この状態で一応ネットに接続することができた。


○以下では、自分で作成するルールを設定する。
(設定したい自分のルールをテキストで用意してから望みましょう。)

先ず、ネットワークを不通にする。(ネットが全く使えなくなる。)

# iptables -F ; iptables -P INPUT DROP ; iptables -P FORWARD DROP ; iptables -P OUTPUT DROP

ここで、ルールの内容を表示させた。

# iptables -L -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination       
Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination       
Chain OUTPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
CentOS6 で見慣れたルールが現れた。

さらに設定を続ける。
CentOS7では、CentOS6のときと違って、-i で指定するインターフェースが、
独自のものになっていることに注意する。(例えば、-i eth0 でない。)

# iptables <略>
# iptables <略>
<省略>


○設定を終えたら、ルールを保存する。

# iptables-save > /etc/sysconfig/iptables

ルールを保存しなければ、再起動時に設定内容が復元されないので注意。

念の為、システムを再起動して、ルールが適用されているか確認した。
問題なく復元され、有効化されていた。

filterだけでなく、natルールも保存するには次のページを参考にしてください。
http://akira-arets.blogspot.jp/2018/04/linux-centos7-natrules-savingrestoring.html


以上

<参考>
・CentOS7でのiptablesの設定忘れるのでメモ
< https://qiita.com/miosee/items/0599baa3a01301265a43 > 2018年3月16日

・iptables を設定する
< http://dejune.net/deblog/raspberrypi/post/20131016222940.html > 2018年3月16日

・22.8. iptables の設定を保持する(iptables-save と iptables-restore)
< http://www.turbolinux.co.jp/products/server/11s/user_guide/iptablesboot.html > 2018年3月16日

2018年3月11日日曜日

windows10-remove-app

Windows10 アプリ削除



Windows PowerShell
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:\Users\myname>

# 3D Builder
Get-AppxPackage *3dbuilder* | Remove-AppxPackage
# 電卓
#Get-AppxPackage *windowscalculator* | Remove-AppxPackage
# アラーム&クロック
Get-AppxPackage *windowsalarms* | Remove-AppxPackage
# カレンダーとメール
Get-AppxPackage *windowscommunicationsapps* | Remove-AppxPackage
# 写真
Get-AppxPackage *photos* | Remove-AppxPackage
# カメラ
Get-AppxPackage *windowscamera* | Remove-AppxPackage
# ボイスレコーダー
Get-AppxPackage *soundrecorder* | Remove-AppxPackage
# Get Office
Get-AppxPackage *officehub* | Remove-AppxPackage
# Get Skype
Get-AppxPackage *skypeapp* | Remove-AppxPackage
# Get Started
Get-AppxPackage *getstarted* | Remove-AppxPackage
# マップ
Get-AppxPackage *windowsmaps* | Remove-AppxPackage
# OneNote
Get-AppxPackage *onenote* | Remove-AppxPackage
# People
#Get-AppxPackage *people* | Remove-AppxPackage
# モバイルコンパニオン
Get-AppxPackage *windowsphone* | Remove-AppxPackage
# Windows ストア
Get-AppxPackage *windowsstore* | Remove-AppxPackage
# ソリティアコレクション
Get-AppxPackage *solitairecollection* | Remove-AppxPackage
# 映画&テレビ
Get-AppxPackage *zunevideo* | Remove-AppxPackage
# XBOX
Get-AppxPackage *xboxapp* | Remove-AppxPackage
# ニュース
Get-AppxPackage *bingnews* | Remove-AppxPackage
# マネー
Get-AppxPackage *bingfinance* | Remove-AppxPackage
# スポーツ
Get-AppxPackage *bingsports* | Remove-AppxPackage
# 天気
Get-AppxPackage *bingweather* | Remove-AppxPackage
# music
Get-AppxPackage *zunemusic* | Remove-AppxPackage

# Dolby Access
Get-AppxPackage *dolby* | Remove-AppxPackage
# Spotify
Get-AppxPackage *spotify* | Remove-AppxPackage
# Auto Desk Sketch Book
Get-AppxPackage *sketchbook* | Remove-AppxPackage
# Microsoft 3D Viewer
Get-AppxPackage *microsoft3dviewer* | Remove-AppxPackage
# Microsoft Messaging
Get-AppxPackage *messaging* | Remove-AppxPackage
# Microsoft StickyNote
Get-AppxPackage *stickynote* | Remove-AppxPackage
# Microsoft Print3D
Get-AppxPackage *print3D* | Remove-AppxPackage




Windows 10 で普通にはアンインストールできないビルドインアプリを削除する
https://loumo.jp/wp/archive/20150826000050/

2018年3月6日火曜日

【Linux CentOS 7】 (ゲストOSがWindowsの場合で)そのqcow2ディスクイメージにおいて仮想容量の空き容量分だけを物理ディスク上で短縮して実際の物理ディスクの使用容量を減らす(即ち、シュリンクする)手順

qcow2ディスクイメージにおいて、仮想容量の内で空き容量分だけを、
物理ディスク上で短縮して実際の物理ディスクの使用容量を減らす。(シュリンクと呼ぶ)
シュリンクは、仮想ディスクの圧縮オプションとは異なるので、混同しないこと。


以下は、Windows10をゲストOSとして動作させている仮想マシンを対象に処理手順である。

特に、手順の1、2、は、ゲストOS内で行う準備作業なので、Windows以外のOSの場合は、
一番下に挙げた「参考の(1)」を参照する。

それ以外の手順は、Linuxホストで行うためゲストOSを問わない。
使用した環境は、CentOS 7 である。




1、(準備作業 1)仮想マシンで動作しているWindowsでディスクのデフラグを行った。

仮想マシン上のゲストWindowsを起動した上で、
ゲストWindowsに組み込まれているデフラグツールで、ディスクのデフラグを行った。

デフラグツールは対象のハードディスクアイコンの右クリックメニューから開く。
右クリックメニューでプロパティーを選択、開いたウインドウからツールタブを開いて、
ドライブの最適化とデフラグを選択する。

でフラグによって、ディスクに保存されているデータがディスク上に再配置される。
状態によって処理にとても時間がかかる。



2、(準備作業 2)仮想マシン上Windowsで、ディスクの空きスペースをゼロで上書きした。

準備作業1が完了した後に、仮想マシン上のWindowsにおいて、次のように作業を行った。


○ゼロ書き込みツールをダウンロードした。

下記リンクより、sdeleteツールをダウンロードし、
解凍して、sdeleteコマンドファイルを、c\windows\system32\ 内にコピーした。

(ツールダウンロードサイト)
https://docs.microsoft.com/ja-jp/sysinternals/downloads/sdelete


○ゼロ書き込みツールを実行した。

DOSプロンプトから、sdeleteコマンドで次のように、C:ドライブの空領域のゼロ上書きを行った。
C:> sdelete -z c:
このとき、ディスクの空き容量が減少していく様子が確認できた。
空き容量にゼロのファイルを書き込んでいるためではないかと思う。
書き込み終わればファイルが削除されて、ゼロ上書きが完了するという仕組みだろう。
SDelete v2.01 - Secure file delete
Copyright (C) 1999-2018 Mark Russinovich
Sysinternals - www.sysinternals.com
SDelete is set for 1 pass.
Cleaning free space on C:\: 23%
99%の段階で、空容量が57.4MBとなった。
Windowsから空き容量不足の警告がでたが無視した。

なぜか、ここからなかなか進まなくなった。
とりあえず一度エンターを押してみると、100%になり、
しばらくして、また一度エンターを押すと、下記のように表示されて完了した。
Free space cleaned on C:\
1 drive cleaned.
C:/>

ディスクの空き容量も正常になった。
使用領域 16.7GB空き領域 62.2GB
容量 79.0GB

実際に使用されている容量は、16.7GB程度である。



3、仮想マシンをシャットダウンした。

 今回の処理に関係の無い仮想マシンは動作させたままにした。



4、仮想マシンディスクの物理ディスク占有サイズを小さく(シュリンク)する。
(仮想マシン上でのディスクサイズには変化はない。)


○上記の仮想マシンがシャットダウンしていることを確認した。


○シュリンク処理前の仮想マシンディスクの情報を表示させた。

# qemu-img info windows10.qcow2
image: windows10.qcow2
file format: qcow2
virtual size: 80G (85899345920 bytes)
disk size: 78G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
処理前の物理占有サイズは、78GBである。


○仮想マシンディスクのファイル名に_backupを付えて変更しておく。

# mv windows10.qcow2 windows10.qcow2_backup


○シュリンク処理を行った。(圧縮オプションは付けずに行った。)

# qemu-img convert -p -O qcow2 windows10.qcow2_backup windows10.qcow2
 (100.00/100%)

-p 進捗状況の表示
-O 出力形式の指定

この処理は少々時間を要する。

windows10.qcow2_backup がシュリンク処理されて、
windows10.qcow2 というファイルが生成された。
(windows10.qcow2_backup はオリジナルとして変更されない。)


○シュリンク処理後の仮想マシンディスクの情報を表示させた。

# qemu-img info windows10.qcow2
image: windows10.qcow2
file format: qcow2
virtual size: 80G (85899345920 bytes)
disk size: 16G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
処理後の物理占有サイズは、16GBである。


(注意)
この後、この仮想マシンのWindowsを起動して、すぐにシャットダウンした。
そして、再度、上記のようにqcow2ディスクイメージの情報を表示させると、
24GBに膨れてしまった。

仮想マシン起動前のファイルサイズの小さいうちに、バックアップをとっておきましょう。
また、別にある仮想マシン設定ファイルもバックアップをとることも忘れずに。




<参考>
(1) Shrink Qcow2 Disk Files
< https://pve.proxmox.com/wiki/Shrink_Qcow2_Disk_Files > 2018年3月6日

(2) How to shrink OpenStack qcow2 image using qemu-img
< http://www.tuxfixer.com/how-to-shrink-openstack-qcow2-image-with-qemu-img/ > 2018年3月6日

(2) SDelete v2.01
< https://docs.microsoft.com/ja-jp/sysinternals/downloads/sdelete > 2018年3月6日


投げ銭

★当サイトへの投げ銭(PayPal)★

Ad

Ad