此次紀錄以 vm workstation實測安裝(VM設定部分不贅述)
設置好ISO後開機,選取第一項 Install CentOS7↓

語言選擇維持英文語系↓

安裝總覽顯示各項基礎設定,先選定 軟體項目[SOFTWARE SELECTION↓

基礎安裝類型有眾多預設項目,選擇[Basic Web Server]↓
使用經驗上此模式以包含一些基礎工具指令

硬碟分區規劃,已有自動規劃,需要進入確認↓
沒有這別需要調整的話,直接點擊DONE(左上角)


進入網路設定↓

點擊Configure設定,於[General] 將 [Automatically …] 選項勾選,此項為開機後自動啟動網卡↓

於 [IPv4 Settings] 設置此CentOS指定的IP↓


開始安裝、並設置root、其他使用帳戶密碼↓

安裝完成、console畫面↓

使用putty軟體,以ssh方式連入Centos↓

ssh是一種加密傳輸協議,首次連線會跳出提示確認是否連線,點擊是[Y]↓


新系統安裝完成,先更新一次↓
#yum update -y

將 centos7 防火牆 firewalld關閉 改用傳統的 iptables↓
關閉firewalld開機自動啟動 # systemctl stop firewalld # systemctl mask firewalld # systemctl disable firewalld 狀態檢查 # systemctl status firewalld 確認 firewalld已停止

安裝iptables #yum install iptables-utils iptables-services -y 啟動iptables,並設置開機自動啟動 #systemctl restart iptables ; systemctl enable iptables

系統版本查看↓
# cat /etc/centos-release CentOS Linux release 7.9.2009 (Core)
TCP Wrappers TCP服務白名單↓
以設定SSH白名單IP為例子,先設置白名單、再設置黑名單(白名單優先於黑名單) #vi /etc/hosts.allow sshd:192.168.1.1:allow #單IP sshd:192.168.1.0/24:allow #子網 sshd:192.168.1.1,192.168.1.2:allow #多筆用 英文半形逗號隔開 [,] 設定SSH黑名單(SSH服務全擋) #vi /etc/hosts.deny sshd:ALL :deny 白名單IP才能訪問sshd服務
更改系統時區↓
#timedatectl set-timezone Asia/Taipei #ls -l /etc/localtime ls -l /etc/localtime lrwxrwxrwx. 1 root root 33 May 11 14:24 /etc/localtime -> ../usr/share/zoneinfo/Asia/Taipei #date date查看系統當前時間,比對時間是否已經是正確時區
防火牆iptables設定↓
#vi /etc/sysconfig/iptables 預設的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 ============================= #開通防火牆port ,要開通其他port修改80為需要開通的port號 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #以22port為例,開通指定IP訪問22port,再禁止所有IP訪問22port #這樣就只有設置了白名單的IP可以訪問22port -A INPUT -s 192.168.1.1 -p tcp --dport 22 -j ACCEPT -A INPUT -p tcp --dport 22 -j DROP
關閉SELinux↓
#vi /etc/selinux/config 預設的selinux config ========== # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=enforcing # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted ========== 將 SELINUX=enforce 修改成: SELINUX=disabled 修改完成後退出 #sync;sync;sync;reboot 寫入系統後,重啟生效 檢查selinux狀態的指令: sestatus