Linux的一些常用命令
1.查看系統(tǒng)信息 系統(tǒng)版本
uname-a
cat /etc/redhat-release
查看CPU
lscpu
內(nèi)存
free -h
硬盤
df -Th
2.firewall防火墻
啟動(dòng): systemctl start firewalld
查狀態(tài): systemctl status firewalld
停止: systemctl disable firewalld
禁用: systemctl stop firewalld
在開機(jī)時(shí)啟用一個(gè)服務(wù): systemctl enable firewalld.service
在開機(jī)時(shí)禁用一個(gè)服務(wù): systemctl disable firewalld.service
查看服務(wù)是否開機(jī)啟動(dòng): systemctl is-enabled firewalld.service
查看已啟動(dòng)的服務(wù)列表: systemctl list-unit-files|grep enabled
查看啟動(dòng)失敗的服務(wù)列表: systemctl --failed
查詢端口是否開放: firewall-cmd --query-port=80/tcp
開放80端口: firewall-cmd --permanent --add-port=80/tcp
移除端口: firewall-cmd --permanent --remove-port=8080/tcp
查看開放了那些端口: firewall-cmd --list-ports
重啟防火墻(修改配置后要重啟防火墻): firewall-cmd --reload
重點(diǎn)
# 指定ip訪問某個(gè)端口規(guī)則 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.102" port protocol="tcp" port="80" accept"
# 禁止指定ip 訪問某個(gè)端口 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.200" port protocol="tcp" port="80" reject"
# 禁止某個(gè)段的ip 訪問某個(gè)端口 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.0.0.0/24" port protocol="tcp" port="80" reject"
# 允許指定ip 訪問所有端口 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.100" port protocol="tcp" accept"
3.Nginx啟動(dòng)相關(guān)命令
#先校驗(yàn)配置文件: nginx -t
# 啟動(dòng) nginx:systemctl start nginx
# 設(shè)置開啟自啟動(dòng): systemctl enable nginx
# 查看啟動(dòng)狀態(tài): systemctl status nginx
#修改了配置文件,重啟生效:nginx -s reload
默認(rèn)配置文件路徑:/etc/nginx/
默認(rèn)靜態(tài)文件路徑:/usr/share/nginx/html/
4.關(guān)于tar命令
# 解壓:tar -zxvf FileName.tar.gz
# 將DirName和其下所有文件(夾)壓縮:tar -zcvf FileName.tar.gz DirName
5.關(guān)于zip和unzip
安裝zip指令:apt-get install -y zip 或 yum install -y zip
安裝unzip命令: apt-get install -y unzip 或 yum install -y unzip
rocky安裝sudo dnf install zip unzip -y
6.iptables防火墻策略
# 查看iptables服務(wù)狀態(tài)
service iptables status
# 或
/etc/init.d/iptables status
# 檢查iptables是否安裝
rpm -q iptables
# 查看當(dāng)前iptables規(guī)則
iptables -L -n
開啟iptables防火墻 systemctl enable iptables
查看iptables防火墻狀態(tài) systemctl status iptables
# 允許所有訪問進(jìn)入 iptables -P INPUT ACCEPT
# 清除所有規(guī)則 iptables -F
# 原有連接保持 iptables -I INPUT 1 -m state --state RELATED,ESTABLISHED -j ACCEPT
# 開放22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --sport 22 -j ACCEPT
# 指定端口策略,只允許特定IP訪問2181
iptables -I INPUT -p tcp --dport 2181 -j DROP
iptables -I INPUT -s 127.0.0.1 -p tcp --dport 2181 -j ACCEPT
# redis端口策略,只允許特定IP訪問6776
iptables -I INPUT -p tcp --dport 6776 -j DROP
iptables -I INPUT -s 127.0.0.1 -p tcp --dport 6776 -j ACCEPT
# 開放IOT端口9494,允許所有IP訪問
iptables -I INPUT -p tcp --dport 9494 -j ACCEPT
# 開放數(shù)據(jù)庫3306端口
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
# 開放MQTT端口
iptables -I INPUT -p tcp --dport 1883 -j ACCEPT
iptables -I INPUT -p tcp --dport 18083 -j ACCEPT
iptables -I INPUT -p tcp --dport 11883 -j ACCEPT
iptables -I INPUT -p tcp --dport 4370 -j ACCEPT
# 設(shè)置默認(rèn)所有訪問禁止
iptables -P INPUT DROP
# 保存規(guī)則 service iptables save
# 重啟iptables systemctl restart iptables

浙公網(wǎng)安備 33010602011771號(hào)