【Linux】CentOS7でiptables&nfs設定

以下のような環境で、iptablesとnfsを組み合わせて使いたい。
といった場合の設定方法。
環境:CentOS7.4
nfsサーバ:192.168.0.5/24
nfsクライアント:192.168.0.3/24
nfsサーバでの設定
#iptablesのインストール [root@LINUX-3 ~]# yum -y install iptables-services 読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: centos.usonyx.net * extras: centos.usonyx.net * updates: ftp.iij.ad.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> パッケージ iptables-services.x86_64 0:1.4.21-17.el7 を インストール --> 依存性解決を終了しました。 依存性を解決しました ============================================================================================================================================== Package アーキテクチャー バージョン リポジトリー 容量 ============================================================================================================================================== インストール中: iptables-services x86_64 1.4.21-17.el7 base 50 k トランザクションの要約 ============================================================================================================================================== インストール 1 パッケージ 総ダウンロード容量: 50 k インストール容量: 24 k Downloading packages: No Presto metadata available for base 警告: /var/cache/yum/x86_64/7/base/packages/iptables-services-1.4.21-17.el7.x86_64.rpm: ヘッダー V3 RSA/SHA256 Signature、鍵 ID f4a80eb5: NOKEY iptables-services-1.4.21-17.el7.x86_64.rpm の公開鍵がインストールされていません iptables-services-1.4.21-17.el7.x86_64.rpm | 50 kB 00:00:00 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 から鍵を取得中です。 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-3.1611.el7.centos.x86_64 (@anaconda) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Running transaction check Running transaction test Transaction test succeeded Running transaction インストール中 : iptables-services-1.4.21-17.el7.x86_64 1/1 検証中 : iptables-services-1.4.21-17.el7.x86_64 1/1 インストール: iptables-services.x86_64 0:1.4.21-17.el7 完了しました! #firewalldの停止、無効化 [root@LINUX-3 ~]# systemctl stop firewalld.service [root@LINUX-3 ~]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service. [root@LINUX-3 ~]# systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1) 8月 31 15:46:42 LINUX-3 systemd[1]: Starting firewalld - dynamic firewall daemon... 8月 31 15:46:43 LINUX-3 systemd[1]: Started firewalld - dynamic firewall daemon. 8月 31 15:53:23 LINUX-3 systemd[1]: Stopping firewalld - dynamic firewall daemon... 8月 31 15:53:23 LINUX-3 systemd[1]: Stopped firewalld - dynamic firewall daemon. #nfsポートの許可 [root@LINUX-3 ~]# diff /etc/sysconfig/iptables /root/iptables 5c5 < :INPUT DROP [0:0] --- > :INPUT ACCEPT [0:0] 12d11 < -A INPUT -p tcp -m state --state NEW -m tcp --dport 2049 -j ACCEPT [root@LINUX-3 ~]# 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 DROP [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 -p tcp -m state --state NEW -m tcp --dport 2049 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT #iptablesの起動、有効化 [root@LINUX-3 ~]# systemctl restart iptables.service [root@LINUX-3 ~]# systemctl enable iptables.service Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service. [root@LINUX-3 ~]# systemctl status iptables.service ● iptables.service - IPv4 firewall with iptables Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled) Active: active (exited) since 木 2017-08-31 15:56:13 JST; 20s ago Main PID: 3280 (code=exited, status=0/SUCCESS) 8月 31 15:56:13 LINUX-3 systemd[1]: Starting IPv4 firewall with iptables... 8月 31 15:56:13 LINUX-3 iptables.init[3280]: iptables: Applying firewall rules: [ OK ] 8月 31 15:56:13 LINUX-3 systemd[1]: Started IPv4 firewall with iptables. #nfsの許可設定がされていることを確認 [root@LINUX-3 ~]# iptables -L Chain INPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT icmp -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:nfs REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination #/etc/exportsを設定 [root@LINUX-3 /]# vi /etc/exports /home/nfs 192.168.0.0/24(rw,fsid=0) #nfs関連サービスを起動(無効化していた有効化する) [root@LINUX-3 ~]# systemctl start nfs-server [root@LINUX-3 ~]# systemctl status nfs-server ● nfs-server.service - NFS server and services Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled) Active: active (exited) since 木 2017-08-31 16:10:27 JST; 24h ago Process: 3838 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS) Process: 3836 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS) Process: 3831 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS) Process: 3848 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS) Process: 3847 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS) Main PID: 3848 (code=exited, status=0/SUCCESS) CGroup: /system.slice/nfs-server.service 8月 31 16:10:27 LINUX-3 systemd[1]: Starting NFS server and services... 8月 31 16:10:27 LINUX-3 systemd[1]: Started NFS server and services. [root@LINUX-3 ~]# systemctl start nfs-lock [root@LINUX-3 ~]# systemctl status nfs-lock ● rpc-statd.service - NFS status monitor for NFSv2/3 locking. Loaded: loaded (/usr/lib/systemd/system/rpc-statd.service; static; vendor preset: disabled) Active: active (running) since 木 2017-08-31 16:03:14 JST; 24h ago Process: 3650 ExecStart=/usr/sbin/rpc.statd --no-notify $STATDARGS (code=exited, status=0/SUCCESS) Main PID: 3653 (rpc.statd) CGroup: /system.slice/rpc-statd.service mq3653 /usr/sbin/rpc.statd --no-notify 8月 31 16:03:13 LINUX-3 systemd[1]: Starting NFS status monitor for NFSv2..... 8月 31 16:03:13 LINUX-3 rpc.statd[3653]: Version 1.3.0 starting 8月 31 16:03:13 LINUX-3 rpc.statd[3653]: Flags: TI-RPC 8月 31 16:03:13 LINUX-3 rpc.statd[3653]: Initializing NSM state 8月 31 16:03:14 LINUX-3 systemd[1]: Started NFS status monitor for NFSv2/..... Hint: Some lines were ellipsized, use -l to show in full. [root@LINUX-3 ~]# systemctl start rpcbind [root@LINUX-3 ~]# systemctl status rpcbind ● rpcbind.service - RPC bind service Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; indirect; vendor preset: enabled) Active: active (running) since 木 2017-08-31 16:03:13 JST; 24h ago Process: 3654 ExecStart=/sbin/rpcbind -w $RPCBIND_ARGS (code=exited, status=0/SUCCESS) Main PID: 3656 (rpcbind) CGroup: /system.slice/rpcbind.service mq3656 /sbin/rpcbind -w 8月 31 16:03:13 LINUX-3 systemd[1]: Starting RPC bind service... 8月 31 16:03:13 LINUX-3 systemd[1]: Started RPC bind service. [root@LINUX-3 ~]# systemctl start nfs-idmap [root@LINUX-3 ~]# systemctl status nfs-idmap ● nfs-idmapd.service - NFSv4 ID-name mapping service Loaded: loaded (/usr/lib/systemd/system/nfs-idmapd.service; static; vendor preset: disabled) Active: active (running) since 木 2017-08-31 16:10:26 JST; 24h ago Process: 3842 ExecStart=/usr/sbin/rpc.idmapd $RPCIDMAPDARGS (code=exited, status=0/SUCCESS) Main PID: 3845 (rpc.idmapd) CGroup: /system.slice/nfs-idmapd.service mq3845 /usr/sbin/rpc.idmapd 8月 31 16:10:26 LINUX-3 systemd[1]: Starting NFSv4 ID-name mapping service... 8月 31 16:10:26 LINUX-3 systemd[1]: Started NFSv4 ID-name mapping service. Hint: Some lines were ellipsized, use -l to show in full.
nfsクライアントでの設定
#nfsクライアントパッケージであるnfs-utilsをインストール [root@LINUX-1 ~]# yum -y install nfs-utils 読み込んだプラグイン:fastestmirror Loading mirror speeds from cached hostfile * base: centos.usonyx.net * extras: centos.usonyx.net * updates: centos.usonyx.net 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> パッケージ nfs-utils.x86_64 1:1.3.0-0.33.el7_3 を インストール --> 依存性の処理をしています: libtirpc >= 0.2.4-0.7 のパッケージ: 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 --> 依存性の処理をしています: gssproxy >= 0.3.0-0 のパッケージ: 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 --> 依存性の処理をしています: rpcbind のパッケージ: 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 --> 依存性の処理をしています: quota のパッケージ: 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 --> 依存性の処理をしています: libnfsidmap のパッケージ: 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 --> 依存性の処理をしています: libevent のパッケージ: 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 --> 依存性の処理をしています: keyutils のパッケージ: 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 --> 依存性の処理をしています: libtirpc.so.1()(64bit) のパッケージ: 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 --> 依存性の処理をしています: libnfsidmap.so.0()(64bit) のパッケージ: 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 --> 依存性の処理をしています: libevent-2.0.so.5()(64bit) のパッケージ: 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 --> トランザクションの確認を実行しています。 ---> パッケージ gssproxy.x86_64 0:0.4.1-13.el7 を インストール --> 依存性の処理をしています: libverto-tevent のパッケージ: gssproxy-0.4.1-13.el7.x86_64 --> 依存性の処理をしています: libini_config.so.3(INI_CONFIG_1.1.0)(64bit) のパッケージ: gssproxy-0.4.1-13.el7.x86_64 --> 依存性の処理をしています: libref_array.so.1()(64bit) のパッケージ: gssproxy-0.4.1-13.el7.x86_64 --> 依存性の処理をしています: libini_config.so.3()(64bit) のパッケージ: gssproxy-0.4.1-13.el7.x86_64 --> 依存性の処理をしています: libcollection.so.2()(64bit) のパッケージ: gssproxy-0.4.1-13.el7.x86_64 --> 依存性の処理をしています: libbasicobjects.so.0()(64bit) のパッケージ: gssproxy-0.4.1-13.el7.x86_64 ---> パッケージ keyutils.x86_64 0:1.5.8-3.el7 を インストール ---> パッケージ libevent.x86_64 0:2.0.21-4.el7 を インストール ---> パッケージ libnfsidmap.x86_64 0:0.25-15.el7 を インストール ---> パッケージ libtirpc.x86_64 0:0.2.4-0.8.el7_3 を インストール ---> パッケージ quota.x86_64 1:4.01-14.el7 を インストール --> 依存性の処理をしています: quota-nls = 1:4.01-14.el7 のパッケージ: 1:quota-4.01-14.el7.x86_64 --> 依存性の処理をしています: tcp_wrappers のパッケージ: 1:quota-4.01-14.el7.x86_64 ---> パッケージ rpcbind.x86_64 0:0.2.0-38.el7_3.1 を インストール --> トランザクションの確認を実行しています。 ---> パッケージ libbasicobjects.x86_64 0:0.1.1-27.el7 を インストール ---> パッケージ libcollection.x86_64 0:0.6.2-27.el7 を インストール ---> パッケージ libini_config.x86_64 0:1.3.0-27.el7 を インストール --> 依存性の処理をしています: libpath_utils.so.1(PATH_UTILS_0.2.1)(64bit) のパッケージ: libini_config-1.3.0-27.el7.x86_64 --> 依存性の処理をしています: libpath_utils.so.1()(64bit) のパッケージ: libini_config-1.3.0-27.el7.x86_64 ---> パッケージ libref_array.x86_64 0:0.1.5-27.el7 を インストール ---> パッケージ libverto-tevent.x86_64 0:0.2.5-4.el7 を インストール --> 依存性の処理をしています: libtevent.so.0(TEVENT_0.9.9)(64bit) のパッケージ: libverto-tevent-0.2.5-4.el7.x86_64 --> 依存性の処理をしています: libtalloc.so.2(TALLOC_2.0.2)(64bit) のパッケージ: libverto-tevent-0.2.5-4.el7.x86_64 --> 依存性の処理をしています: libtevent.so.0()(64bit) のパッケージ: libverto-tevent-0.2.5-4.el7.x86_64 --> 依存性の処理をしています: libtalloc.so.2()(64bit) のパッケージ: libverto-tevent-0.2.5-4.el7.x86_64 ---> パッケージ quota-nls.noarch 1:4.01-14.el7 を インストール ---> パッケージ tcp_wrappers.x86_64 0:7.6-77.el7 を インストール --> トランザクションの確認を実行しています。 ---> パッケージ libpath_utils.x86_64 0:0.2.1-27.el7 を インストール ---> パッケージ libtalloc.x86_64 0:2.1.6-1.el7 を インストール ---> パッケージ libtevent.x86_64 0:0.9.28-1.el7 を インストール --> 依存性解決を終了しました。 依存性を解決しました ================================================================================ Package アーキテクチャー バージョン リポジトリー 容量 ================================================================================ インストール中: nfs-utils x86_64 1:1.3.0-0.33.el7_3 updates 377 k 依存性関連でのインストールをします: gssproxy x86_64 0.4.1-13.el7 base 87 k keyutils x86_64 1.5.8-3.el7 base 54 k libbasicobjects x86_64 0.1.1-27.el7 base 25 k libcollection x86_64 0.6.2-27.el7 base 41 k libevent x86_64 2.0.21-4.el7 base 214 k libini_config x86_64 1.3.0-27.el7 base 63 k libnfsidmap x86_64 0.25-15.el7 base 47 k libpath_utils x86_64 0.2.1-27.el7 base 27 k libref_array x86_64 0.1.5-27.el7 base 26 k libtalloc x86_64 2.1.6-1.el7 base 34 k libtevent x86_64 0.9.28-1.el7 base 34 k libtirpc x86_64 0.2.4-0.8.el7_3 updates 88 k libverto-tevent x86_64 0.2.5-4.el7 base 9.0 k quota x86_64 1:4.01-14.el7 base 179 k quota-nls noarch 1:4.01-14.el7 base 90 k rpcbind x86_64 0.2.0-38.el7_3.1 updates 59 k tcp_wrappers x86_64 7.6-77.el7 base 78 k トランザクションの要約 ================================================================================ インストール 1 パッケージ (+17 個の依存関係のパッケージ) 総ダウンロード容量: 1.5 M インストール容量: 4.3 M Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/18): keyutils-1.5.8-3.el7.x86_64.rpm | 54 kB 00:00 (2/18): libbasicobjects-0.1.1-27.el7.x86_64.rpm | 25 kB 00:00 (3/18): libini_config-1.3.0-27.el7.x86_64.rpm | 63 kB 00:00 (4/18): libnfsidmap-0.25-15.el7.x86_64.rpm | 47 kB 00:00 (5/18): libevent-2.0.21-4.el7.x86_64.rpm | 214 kB 00:00 (6/18): libcollection-0.6.2-27.el7.x86_64.rpm | 41 kB 00:00 (7/18): libtalloc-2.1.6-1.el7.x86_64.rpm | 34 kB 00:00 (8/18): libref_array-0.1.5-27.el7.x86_64.rpm | 26 kB 00:00 (9/18): libpath_utils-0.2.1-27.el7.x86_64.rpm | 27 kB 00:00 (10/18): libtirpc-0.2.4-0.8.el7_3.x86_64.rpm | 88 kB 00:00 (11/18): libverto-tevent-0.2.5-4.el7.x86_64.rpm | 9.0 kB 00:00 (12/18): libtevent-0.9.28-1.el7.x86_64.rpm | 34 kB 00:00 (13/18): quota-nls-4.01-14.el7.noarch.rpm | 90 kB 00:00 (14/18): nfs-utils-1.3.0-0.33.el7_3.x86_64.rpm | 377 kB 00:00 (15/18): tcp_wrappers-7.6-77.el7.x86_64.rpm | 78 kB 00:00 (16/18): quota-4.01-14.el7.x86_64.rpm | 179 kB 00:00 (17/18): gssproxy-0.4.1-13.el7.x86_64.rpm | 87 kB 00:00 (18/18): rpcbind-0.2.0-38.el7_3.1.x86_64.rpm | 59 kB 00:00 -------------------------------------------------------------------------------- 合計 2.1 MB/s | 1.5 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction インストール中 : libref_array-0.1.5-27.el7.x86_64 1/18 インストール中 : libcollection-0.6.2-27.el7.x86_64 2/18 インストール中 : libtirpc-0.2.4-0.8.el7_3.x86_64 3/18 インストール中 : rpcbind-0.2.0-38.el7_3.1.x86_64 4/18 インストール中 : libbasicobjects-0.1.1-27.el7.x86_64 5/18 インストール中 : libtalloc-2.1.6-1.el7.x86_64 6/18 インストール中 : libtevent-0.9.28-1.el7.x86_64 7/18 インストール中 : libverto-tevent-0.2.5-4.el7.x86_64 8/18 インストール中 : 1:quota-nls-4.01-14.el7.noarch 9/18 インストール中 : libpath_utils-0.2.1-27.el7.x86_64 10/18 インストール中 : libini_config-1.3.0-27.el7.x86_64 11/18 インストール中 : gssproxy-0.4.1-13.el7.x86_64 12/18 インストール中 : keyutils-1.5.8-3.el7.x86_64 13/18 インストール中 : libevent-2.0.21-4.el7.x86_64 14/18 インストール中 : tcp_wrappers-7.6-77.el7.x86_64 15/18 インストール中 : 1:quota-4.01-14.el7.x86_64 16/18 インストール中 : libnfsidmap-0.25-15.el7.x86_64 17/18 インストール中 : 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 18/18 検証中 : libtalloc-2.1.6-1.el7.x86_64 1/18 検証中 : 1:quota-4.01-14.el7.x86_64 2/18 検証中 : libnfsidmap-0.25-15.el7.x86_64 3/18 検証中 : libverto-tevent-0.2.5-4.el7.x86_64 4/18 検証中 : tcp_wrappers-7.6-77.el7.x86_64 5/18 検証中 : gssproxy-0.4.1-13.el7.x86_64 6/18 検証中 : libini_config-1.3.0-27.el7.x86_64 7/18 検証中 : libbasicobjects-0.1.1-27.el7.x86_64 8/18 検証中 : libevent-2.0.21-4.el7.x86_64 9/18 検証中 : libtevent-0.9.28-1.el7.x86_64 10/18 検証中 : keyutils-1.5.8-3.el7.x86_64 11/18 検証中 : 1:nfs-utils-1.3.0-0.33.el7_3.x86_64 12/18 検証中 : libtirpc-0.2.4-0.8.el7_3.x86_64 13/18 検証中 : libpath_utils-0.2.1-27.el7.x86_64 14/18 検証中 : 1:quota-nls-4.01-14.el7.noarch 15/18 検証中 : libcollection-0.6.2-27.el7.x86_64 16/18 検証中 : libref_array-0.1.5-27.el7.x86_64 17/18 検証中 : rpcbind-0.2.0-38.el7_3.1.x86_64 18/18 インストール: nfs-utils.x86_64 1:1.3.0-0.33.el7_3 依存性関連をインストールしました: gssproxy.x86_64 0:0.4.1-13.el7 keyutils.x86_64 0:1.5.8-3.el7 libbasicobjects.x86_64 0:0.1.1-27.el7 libcollection.x86_64 0:0.6.2-27.el7 libevent.x86_64 0:2.0.21-4.el7 libini_config.x86_64 0:1.3.0-27.el7 libnfsidmap.x86_64 0:0.25-15.el7 libpath_utils.x86_64 0:0.2.1-27.el7 libref_array.x86_64 0:0.1.5-27.el7 libtalloc.x86_64 0:2.1.6-1.el7 libtevent.x86_64 0:0.9.28-1.el7 libtirpc.x86_64 0:0.2.4-0.8.el7_3 libverto-tevent.x86_64 0:0.2.5-4.el7 quota.x86_64 1:4.01-14.el7 quota-nls.noarch 1:4.01-14.el7 rpcbind.x86_64 0:0.2.0-38.el7_3.1 tcp_wrappers.x86_64 0:7.6-77.el7 完了しました! #マウントしてみる [root@LINUX-1 ~]# mount -t nfs 192.168.0.5:/home/nfs /mnt/nfs/ [root@LINUX-1 ~]# ls -l /mnt/nfs/ 合計 4 -rw-r--r--. 1 root root 4 8月 31 16:02 aaa