- 追加された行はこの色です。
- 削除された行はこの色です。
*CentOS7について [#i02d8bc4]
RIGHT:更新日 &lastmod();
**rc.localについて [#ne96bc79]
インストール直後は実行権がないので動作しないの実行権を与える
chmod u+x rc.local
-再実行
# systemctl start rc-local
**Default GWについて [#y87de406]
設定
# ip route add default via 192.168.10.245 dev ens32
確認
# ip ro
default via 192.168.10.245 dev ens32
default via 192.168.200.1 dev ens34 proto static metric 1024
192.168.10.0/24 dev ens32 proto kernel scope link src 192.168.10.205
192.168.200.0/24 dev ens34 proto kernel scope link src 192.168.200.3
**CentOS7の起動について [#x3e4a595]
UNIX System V系のinit→ systemdにより「ランレベル」から「ターゲット」に変更された。
***起動モードの確認 [#i5413f7b]
# systemctl get-default
graphical.target
これはSystem V系のランレベル5
***起動サービスの確認 [#le94e44f]
# systemctl list-unit-files
UNIT FILE STATE
proc-sys-fs-binfmt_misc.automount static
dev-hugepages.mount static
dev-mqueue.mount static
proc-fs-nfsd.mount static
(略)
***ターゲットの確認 [#vfc8e7b0]
# systemctl list-units -t target -a --no-pager
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Encrypted Volumes
emergency.target loaded inactive dead Emergency Mode
final.target loaded inactive dead Final Step
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target loaded active active Local File Systems
multi-user.target loaded active active Multi-User System
network-online.target loaded inactive dead Network is Online
network.target loaded active active Network
(中略)
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
27 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.
***起動モードの変更(graphical→multi-user [runlevel5→runlevel3] [#s2bea787]
# systemctl set-default multi-user.target
rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target'
# systemctl get-default
multi-user.target
''multi-user→graphical''
# systemctl set-default graphical.target
rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/graphical.target' '/etc/systemd/system/default.target'
# systemctl get-default
***CUIからGUIに切り替え [#tfeeaf7c]
# systemctl isolate graphical.target
***ランレベルとsystemdの対応 [#g00441d5]
CENTER:| |runlevel | systemdでの変更コマンド |h
|システム停止 | 0 | systemctl isolate poweroff.target |
|シングルユーザモード | 1 | systemctl isolate rescue.target |
|マルチユーザモード | 3 | systemctl isolate multi-user.target |
|グラフィカルユーザモード | 5 | systemctl isolate graphical.target |
|再起動 | 6 | systemctl isolate reboot.target |
|緊急モード | - | systemctl isolate emergency.target |
***デーモン起動/確認等 [#i11fe6a6]
CENTER:| | SystemV系 | systemd |
|サービス開始 | /etc/rc.d/ini.d/httpd start | systemctl start httpd |
|サービス停止 | /etc/rc.d/ini.d/httpd stop | systemctl stop httpd |
|サービス再起動 | /etc/rc.d/ini.d/httpd restart | systemctl restart httpd |
|設定ファイルの再読み込み | /etc/rc.d/ini.d/httpd reload | systemctl relaod httpd |
|サービス状態 | /sbin/chkconfig httpd status | systemctl status httpd |
|サービス自動起動 | /sbin/chkconfig httpd on | systemctl enable httpd |
|サービス自動起動停止 | /sbin/chkconfig httpd off | systemctl disable httpd |
|ランレベル毎のサービスの有効無効表示 | /sbin/chkconfig --list | systemctl list-unit-files |
|ランレベル毎の指定サービスの有効無効表示 | /sbin/chkconfig --list httpd | systemctl list-unit-files (パイプ) grep httpd |
ネットワーク再起動
# systemctl restart NetworkManager.service
***サービスの起動/確認・起動時のサービス設定 [#zd88f5f9]
サービス起動
# systemctl start vsftpd
起動時のサービス設定
# systemctl enable vsftpd
ln -s '/usr/lib/systemd/system/vsftpd.service' '/etc/systemd/system/multi-user.target.wants/vsftpd.service'
確認
# systemctl list-unit-files -t service | grep vsftpd
vsftpd.service enabled ← ここを確認
vsftpd@.service disabled
起動時のサービス解除
# systemctl disable vsftpd
rm '/etc/systemd/system/multi-user.target.wants/vsftpd.service'
確認
# systemctl list-unit-files -t service | grep vsftpd
vsftpd.service disabled ← ここを確認
vsftpd@.service disabled
''もう少し詳しく''
起動
# systemctl start httpd
# systemctl list-units -t service -a | grep httpd
httpd.service loaded active running The Apache HTTP Server
停止
# systemctl stop httpd
停止すると何も表示されない
# systemctl list-units -t service -a | grep httpd
(何も表示されない)
&color(red){この情報だと設定があるか否かトラブル対応のとき情報が不明なので次のようにすれば確認できる};
# systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
Active: inactive (dead) ← 起動していない
4月 18 13:01:52 vmcent7x systemd[1]: Starting The Apache HTTP Server...
4月 18 13:01:53 vmcent7x httpd[4020]: AH00558: httpd: Could not reliably d...e
4月 18 13:01:53 vmcent7x systemd[1]: Started The Apache HTTP Server.
4月 18 13:02:32 vmcent7x systemd[1]: Stopping The Apache HTTP Server...
4月 18 13:02:34 vmcent7x systemd[1]: Stopped The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
''起動''
# systemctl start httpd
# systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
Active: active (running) since 土 2015-04-18 13:19:58 JST; 3s ago ← 起動している
Main PID: 4350 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
tq4350 /usr/sbin/httpd -DFOREGROUND
tq4351 /usr/libexec/nss_pcache 393219 off /etc/httpd/alias
tq4352 /usr/sbin/httpd -DFOREGROUND
tq4353 /usr/sbin/httpd -DFOREGROUND
tq4354 /usr/sbin/httpd -DFOREGROUND
tq4355 /usr/sbin/httpd -DFOREGROUND
mq4356 /usr/sbin/httpd -DFOREGROUND
4月 18 13:19:57 vmcent7x systemd[1]: Starting The Apache HTTP Server...
4月 18 13:19:57 vmcent7x httpd[4350]: AH00558: httpd: Could not reliably d...e
4月 18 13:19:58 vmcent7x systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
**ファイアウオール [#s1446351]
NIC毎に設定が可能になった。
NICにゾーンを割り当て管理している。ゾーンごとファイアウォールが定義でき、デフォルトで9個用意されている
「block、dmz、drop、external、home、internal、public、trusted、work」
現在のゾーンを表示
# firewall-cmd --get-active-zones
public
interfaces: ens32
NIC(ens32)にpublicというゾーンが割り振られている
ではpublicの設定は(デフォルトゾーン表示)
# firewall-cmd --list-all
public (default, active)
interfaces: ens32
sources:
services: dhcpv6-client ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
または
# cat /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers \
on networks to not harm your computer. Only selected incoming connections are \
accepted.</description>
<service name="dhcpv6-client"/>
<service name="ssh"/>
</zone>
sshとdhcpv6-clientが外部→内部パケット許可
すべてゾーン設定表示は
#firewall-cmd --list-all-zone
block
interfaces:
sources:
services:
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
dmz
interfaces:
(略)
定義ファイルは/usr/lib/firewalld/zones/にある
*** ゾーンへの追加削除 [#nd79bf7b]
-firewall-cmd --zone=public --&color(red){remove};-service=ssh --permanent #ゾーンpublicに設定されているサービスsshを永久に&color(red){削除};する。
-firewall-cmd --zone=public --add-port=12220/tcp --permanent #ゾーンpublicにTCPポート12220を永久に追加する。
-firewall-cmd --reload #設定を反映する。
&color(red){一時追加は --permanentを省略(permanentなしの場合はすぐに適用されるので、--reloadは不要)};
''ゾーンpublicにtcp 12220ポートを追加''
# firewall-cmd --zone=public --add-port=12220/tcp --permanent
success
# firewall-cmd --reload
success
''defaultゾーンの表示''
# firewall-cmd --list-all
public (default, active)
interfaces: ens32
sources:
services: dhcpv6-client ssh
ports: 12220/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
''tcp 12220ポートを削除''
# firewall-cmd --zone=public --remove-port=12220/tcp --permanent
success
# firewall-cmd --reload
success
***デフォルトゾーン変更 [#m815530c]
ゾーンtrusted(すべて許可)に変更
# firewall-cmd --set-default-zone=trusted
success
# firewall-cmd --get-default-zone
trusted
# firewall-cmd --list-all
trusted (default, active)
interfaces: ens32
sources:
services:
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
***serviciesの作成 [#n5e0fe4b]
/usr/lib/firewalld/servicesにいくつかあるのでそれを参考に作成
''rsyslog.xml''
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>RSYSLOG</short>
<description>RSYSLOG Edit By JE2ISM.</description>
<port protocol="tcp" port="514"/>
<port protocol="udp" port="514"/>
</service>
追加コマンド
# firewall-cmd --zone=public --add-service=rsyslog --permanent
success
# firewall-cmd --reload
success
***ゾーンのインターフェイスを付け替える(NICが2枚: ens32,ens34) [#a32dc4b8]
はじめは2つのインターフェイスがゾーンpubilicに設定されている
# firewall-cmd --list-all
public (default, active)
interfaces: ens32 ens34
sources:
services: dhcpv6-client ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
インターフェイスens34をゾーンtrustedに変更
# firewall-cmd --zone=trusted --change-interface=ens34
success
''アクティブゾーン表示''
# firewall-cmd --get-active-zones
public
interfaces: ens32
trusted
interfaces: ens34
''デフォルトゾーンの変更''
publicに変更
# firewall-cmd --set-default-zone=public
success
''ゾーンtrustedを表示''
# firewall-cmd --list-all --zone=trusted
trusted (active)
interfaces: ens34
sources:
services:
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
**ソースIPで制御 [#xd0ca7ca]
接続許可IPを指定
# firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -m conntrack --ctstate
\ NEW -m tcp -p tcp --dport 22 -s 192.168.10.47/32 -j ACCEPT
success
それ以外を禁止
# firewall-cmd --direct --add-rule ipv4 filter INPUT 3 -m conntrack --ctstate
\NEW -m tcp -p tcp --dport 22 -j REJECT
success
条件解除
# firewall-cmd --direct --remove-rule ipv4 filter INPUT 1 -m conntrack\
--ctstate NEW -m tcp -p tcp --dport 22 -s 192.168.10.47/32 -j ACCEPT
success
確認
# iptables -L -n --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
3 INPUT_direct all -- 0.0.0.0/0 0.0.0.0/0
4 INPUT_ZONES_SOURCE all -- 0.0.0.0/0 0.0.0.0/0
5 INPUT_ZONES all -- 0.0.0.0/0 0.0.0.0/0
6 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
7 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
3 FORWARD_direct all -- 0.0.0.0/0 0.0.0.0/0
4 FORWARD_IN_ZONES_SOURCE all -- 0.0.0.0/0 0.0.0.0/0
5 FORWARD_IN_ZONES all -- 0.0.0.0/0 0.0.0.0/0
6 FORWARD_OUT_ZONES_SOURCE all -- 0.0.0.0/0 0.0.0.0/0
7 FORWARD_OUT_ZONES all -- 0.0.0.0/0 0.0.0.0/0
8 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
9 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
(略)
Chain INPUT_ZONES (1 references)
num target prot opt source destination
1 IN_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
2 IN_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
3 IN_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
Chain INPUT_ZONES_SOURCE (1 references)
num target prot opt source destination
Chain INPUT_direct (1 references)
num target prot opt source destination
1 ACCEPT tcp -- 192.168.10.47 0.0.0.0/0 ctstate NEW tcp dpt:22
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 REJECT tcp -- 0.0.0.0/0 0.0.0.0/0 ctstate NEW tcp dpt:22 reject-with icmp-port-unreachable
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Chain IN_public (3 references)
num target prot opt source destination
1 IN_public_log all -- 0.0.0.0/0 0.0.0.0/0
2 IN_public_deny all -- 0.0.0.0/0 0.0.0.0/0
3 IN_public_allow all -- 0.0.0.0/0 0.0.0.0/0
Chain IN_public_allow (1 references)
num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:21 ctstate NEW
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 ctstate NEW
3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:514 ctstate NEW
4 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:514 ctstate NEW
Chain IN_public_deny (1 references)
num target prot opt source destination
Chain IN_public_log (1 references)
num target prot opt source destination
Chain OUTPUT_direct (1 references)
num target prot opt source destination
**参考 [#v3245b06]
''CentOS7のプロセス関係''~
-http://thinkit.co.jp/story/2014/12/11/5388
''ファイアウオール関係''~
-https://www.jdbc.tokyo/2014/10/centos7-firewalld-startup/
-http://www.unix-power.net/centos7/firewalld.html
-http://www.mk-mode.com/octopress/2014/08/09/centos-7-0-setting-of-firewall/
-http://www.gamvaro.com/kswiki/index.php?%EF%BC%AF%EF%BC%B3%E9%96%A2%E4%BF%82%2FLinux%2FCentOS7
-https://fedoraproject.org/wiki/FirewallD/jp