Centos7 最小安裝

Centos7 最小安裝

1.ifconfig

? yum install net-tools [它提供 ifconfig 工具,如果你不習(xí)慣 ip 命令,還可以使用它]

? ifconfig

2.設(shè)置服務(wù)器的主機(jī)名稱

? hostnamectl set-hostname mini

? echo $HOSTNAME [檢查主機(jī)名]

? [root@mini ~]# echo $HOSTNAME
? mini

3.更新或升級最小化安裝的 CentOS

? yum update -y

4.關(guān)閉SELINUX

? sestatus [查看selinux狀態(tài)]

? vi /etc/selinux/config

? SELINUX=disabled
重啟生效

5.設(shè)置靜態(tài)IP地址

? vi /etc/sysconfig/network-scripts/ifcfg-eno16777736

? BOOTPROTO="static"
? IPADDR="192.168.1.101"
? NETMASK="255.255.255.0"
? NM_CONTROLLED="no"
? ONBOOT="yes"

? “NM_CONTROLLED=no”表示該接口將通過該配置文件進(jìn)行設(shè)置,而不是通過網(wǎng)絡(luò)管理器進(jìn)行管理?!癘NBOOT=yes”告訴我們,系統(tǒng)將在啟動(dòng)時(shí)開啟該接口

? 重啟網(wǎng)絡(luò)服務(wù)

? systemctl restart network.service

? 驗(yàn)證接口是否配置正確

? ip add

? 因?yàn)槲业腄NS沒有設(shè)置所以導(dǎo)致了ping外網(wǎng)ping不通

? vi /etc/resolv.conf

? search localdomain
? nameserver 8.8.8.8
? nameserver 114.114.114.114

? service network restart

? ping -c 3 www.baidu.com[測試]

6.修改ssh端口

? 修改端口

? vi /etc/ssh/sshd_config

? 修改去掉port前面注釋,修改port值為21622

? 使用密鑰登陸

? mkdir ~/.ssh

? chmod 755 ~/.ssh

? vi ~/.ssh/authorized_keys

? chmod 600 ~/.ssh/authorized_keys

? vi /etc/ssh/sshd_config

? RSAAuthentication yes

? PubkeyAuthentication yes

? AuthorizedKeysFile

? .ssh/authorized_keys

? 禁止密碼登陸

? vi /etc/ssh/sshd_config

? PasswordAuthentication no

? 重啟ssh

? service sshd restart

6.安裝iptables

? 首先要停止 firewalld 服務(wù)

? systemctl stop firewalld.service

? 禁止 firewalld 服務(wù)在系統(tǒng)啟動(dòng)的時(shí)候自動(dòng)啟動(dòng)

? systemctl disable firewalld.server

? 安裝iptables 包

? yum install iptables-services -y

? 設(shè)置iptables 防火墻服務(wù)開機(jī)自動(dòng)啟動(dòng)

? systemctl enable iptables

? 修改iptables配置

? 查看狀態(tài)

? service iptables status

? 查看規(guī)則

? iptables -L -n

? 清除默認(rèn)規(guī)則

? iptables -F

? iptables -X

? iptables -Z

? 建立新的規(guī)則

? 允許本地回環(huán) 127.0.0.1

? iptables -A INPUT -i lo -p all -j ACCEPT

? 允許已經(jīng)建立的所有連接

? iptables -A INPUT -p all -m state --state ESTABLISHED,RELATED -j ACCEPT

? 允許內(nèi)網(wǎng)的所有連接

? iptables -A INPUT -s 10.0.0.0/8 -j ACCEPT

? 允許所有向外發(fā)起的連接

? iptables -A OUTPUT -j ACCEPT

? 拒絕 ping 可選

? iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j REJECT

? 允許 SSH 服務(wù)端口(一定要打開,不然就不能ssh了)

? iptables -A INPUT -p tcp --dport 21622 -j ACCEPT

? 允許 Web 服務(wù)端口

? iptables -A INPUT -p tcp --dport 80 -j ACCEPT

? 允許 https 服務(wù)端口

? iptables -A INPUT -p tcp --dport 443 -j ACCEPT

? 允許返回?cái)?shù)據(jù)給所有ip所有端口 允許所有本機(jī)向外的訪問

? iptables -A OUTPUT -j ACCEPT

? 除上面允許的規(guī)則,拋棄所有INPUT請求 (注意:如果22端口未加入允許規(guī)則,SSH鏈接會(huì)直接斷開。)

? iptables -P INPUT DROP

? 除上面允許的規(guī)則,拋棄所有FORWARD請求

? iptables -P FORWARD DROP

? 除上面允許的規(guī)則,拋棄所有OUTPUT請求

? iptables -P OUTPUT DROP

? 保存(ArchLinux系統(tǒng)下的路徑可能和其他系統(tǒng)下的路徑不同)

? sudo service iptables save

? 重新啟動(dòng)

? sudo service iptables restart

? 列出規(guī)則,供查看

? iptables -L -n

7.更新yum源

? 安裝wget

? yum install wget -y

? 備份一下源

? mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

? 轉(zhuǎn)到源目錄,按照自己的版本下載源

? cd /etc/yum.repos.d/

? wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

? 運(yùn)行以下命令生成緩存:

yum clean all

yum makecache

8.安裝 GCC (GNU 編譯器集)

yum install gcc -y

gcc --version

[root@mini yum.repos.d]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright ? 2015 Free Software Foundation, Inc.
本程序是自由軟件;請參看源代碼的版權(quán)聲明。本軟件沒有任何擔(dān)保;
包括沒有適銷性和某一專用目的下的適用性擔(dān)保。

9.安裝 7-zip 工具(壓縮和解壓所有已知類型文件的工具)

? yum install p7zip -y

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容