CentOS 7 內建使用的防火牆軟體已經由 iptables 換成 firewalld 囉,不過 iptables 在 CentOS 7 一樣仍然可用。
在目前的操作範例,我們暫時使用 iptables 來取代 firewalld ,畢竟, firewalld 的語法我還不熟啦!
先看一下 firewalld 的狀態。
# systemctl status firewalld
將 firewalld 從開機過程停用。
# systemctl disable firewalld
好了,重新開機吧。
# sync;sync;sync;reboot
2017年9月8日
啟動防火牆
要架設 VPN server 之前,必須要先完成 防火牆 的準備。( 因為封包要轉送 )
# systemctl mask firewalld
# systemctl stop firewalld
# yum install iptables-services
#systemctl enable iptables
用 vi 來編輯一份檔案,例如: nat
# vi nat
輸入以下的內容
( enp1s0 要換成你的網路卡名稱 )
存檔離開。( 請記得,把192.168.6 換成你的 163.17.249 )
編輯完的 nat 這個檔案,是普通文件屬性,不能「執行」,必須把這個文件,變成可以執行的屬性。
先用 ls -l 看看檔案屬性,
# ls -l
( 可以看到 nat 這個檔案的屬性是 -rw-r--r-- ,下一個指令要把 nat 這個檔案變成可以執行的屬性 )
輸入下列指令,讓 nat 這個檔案可以執行
# chmod 744 nat
再下一次 ls -l 指令,看看 nat 這個檔案的屬性
# ls -l
( nat 這個檔案變成綠色了,屬性變成 -rwxr--r-- ,綠色代表是可以執行的檔案 )
既然 nat 這個檔案已經可以執行了,我們就來執行這個檔案吧。
# ./nat
到目前,我們成功完成安裝 VPN server 之前的防火牆準備了。
# systemctl mask firewalld
# systemctl stop firewalld
# yum install iptables-services
#systemctl enable iptables
用 vi 來編輯一份檔案,例如: nat
# vi nat
輸入以下的內容
#!/bin/bash
#PATH=/sbin:/bin:/usr/sbin:/usr/bin; export PATH
systemctl restart iptables
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables -X
iptables -Z
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F -t nat
iptables -X -t nat
iptables -Z -t nat
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -A INPUT -i enp1s0 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.6.0/24 -o enp1s0 -j MASQUERADE
( enp1s0 要換成你的網路卡名稱 )
存檔離開。( 請記得,把192.168.6 換成你的 163.17.249 )
編輯完的 nat 這個檔案,是普通文件屬性,不能「執行」,必須把這個文件,變成可以執行的屬性。
先用 ls -l 看看檔案屬性,
# ls -l
( 可以看到 nat 這個檔案的屬性是 -rw-r--r-- ,下一個指令要把 nat 這個檔案變成可以執行的屬性 )
輸入下列指令,讓 nat 這個檔案可以執行
# chmod 744 nat
再下一次 ls -l 指令,看看 nat 這個檔案的屬性
# ls -l
( nat 這個檔案變成綠色了,屬性變成 -rwxr--r-- ,綠色代表是可以執行的檔案 )
既然 nat 這個檔案已經可以執行了,我們就來執行這個檔案吧。
# ./nat
到目前,我們成功完成安裝 VPN server 之前的防火牆準備了。
2017年9月2日
關閉 防火牆
上次有操作過
# systemctl stop firewalld
這個指令是把 服務中 的防火牆停止。
但是 防火牆 的服務 有被放在 開機啟動 的 服務,所以防火牆,會在重新開機之後,依然會自動啟動。
如果要永遠取消防火牆在開機之後被啟動,要使用 disable 這個參數。
# systemctl disable firewalld
這樣就能取消開機時後啟動防火牆了。
# systemctl stop firewalld
這個指令是把 服務中 的防火牆停止。
但是 防火牆 的服務 有被放在 開機啟動 的 服務,所以防火牆,會在重新開機之後,依然會自動啟動。
如果要永遠取消防火牆在開機之後被啟動,要使用 disable 這個參數。
# systemctl disable firewalld
這樣就能取消開機時後啟動防火牆了。
2017年8月26日
停止 iptables 防火牆
安裝好 CentOS 7 的過程,跟之前 CentOS 3,4,5,6 不一樣,省略了不少的設定,包括 防火牆 的設定,CentOS 7 預設把 防火牆套件 啟動,我們先來把 防火牆 關閉吧。
CentOS 7 關閉 服務( service ) 的指令是 systemctl 。
用法: systemctl [動作] [服務名稱]
舉例:
# 用 systemctl 停止 防火牆
# systemctl stop firewalld
# 用 systemctl 查看狀態 防火牆
# systemctl status firewalld
在 CentOS 7 先關閉 firewalld 之後,才能提供後續的網站 httpd 服務。
至於關閉 CentOS 7 的防火牆之後,到底安不安全?防火牆當然是愈多道愈安全,不過目前我們還在練習階段,先簡化學習步驟,所以選擇先關閉畚箕本機防火牆。把防火牆這個重責大任交給 FortiGate 200D 就好了。俟後再另外了解 iptables 的龐大設定。
作業:
# 重新啟動 sshd
# systemctl restart sshd
( 不可停止 sshd 喔!不然伺服器就會跟你拒絕往來了 )
CentOS 7 關閉 服務( service ) 的指令是 systemctl 。
用法: systemctl [動作] [服務名稱]
舉例:
# 用 systemctl 停止 防火牆
# systemctl stop firewalld
# 用 systemctl 查看狀態 防火牆
# systemctl status firewalld
在 CentOS 7 先關閉 firewalld 之後,才能提供後續的網站 httpd 服務。
至於關閉 CentOS 7 的防火牆之後,到底安不安全?防火牆當然是愈多道愈安全,不過目前我們還在練習階段,先簡化學習步驟,所以選擇先關閉
作業:
# 重新啟動 sshd
# systemctl restart sshd
( 不可停止 sshd 喔!不然伺服器就會跟你拒絕往來了 )
訂閱:
文章 (Atom)
