1. 程式人生 > >Linux日常運維(二)

Linux日常運維(二)

10.4 Linux的防火牆

SELinux

SELinux是linux系統特有的安全機制,這種機制限制較多,配置也比較繁瑣,所以一般把SELinux關閉。

檢視selinux的狀態有兩種方法:

  • getenforce 命令是單詞get(獲取)和enforce(執行)連寫,可檢視selinux狀態
[[email protected] ~]# getenforce
Enforcing
  • /usr/sbin/sestatus
[[email protected] ~]# /usr/sbin/sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

SELinux status:selinux防火牆的狀態,enabled表示啟用selinux防火牆
Current mode:表示selinux防火牆當前的安全策略,enforcing 表示強

關閉SELinux:

  • 臨時關閉
    setenforce 0 :用於關閉selinux防火牆,但重啟後失效(setenforce 1 用於開啟selinux,重啟失效)
[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce
Permissive
  • 永久關閉
  1. 開啟selinux的配置檔案:
[[email protected] ~]# vim /etc/selinux/config 
  1. 修改selinux的配置檔案:
    將SELINUX=enforcing改為SELINUX=disabled,儲存後退出
# 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 two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
  1. 此時獲取當前selinux防火牆的安全策略仍為Enforcing,配置檔案並未生效
[[email protected] ~]# getenforce
Enforcing
  1. 需要重啟:
[[email protected] ~]# reboot
  1. 驗證:
[[email protected] ~]# getenforce
Disabled

netfilter

在CentOS7之前的CentOS版本的防火牆為netfilter,CentOS7的防火牆為firewalld
iptables是針對防火牆的一個工具,iptables是用來設定、維護和檢查Linux核心的IP包過濾規則的。在瞭解netfilter之前,需要先把firewalld關閉,然後開啟之前版本的iptables。

# systemctl stop firewalld   //關閉firewalld服務
# systemctl disable firewalld   //禁止firewalld服務開機啟動
# yum install -y iptables-services   //安裝iptables-services
# systemctl enable iptables   //讓iptables開機啟動
# systemctl start iptables   //啟動iptables服務

CentOS上預設設有iptables規則,一般建議先清除規則,然後把清除後的規則儲存一下

[[email protected] ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  190 16296 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    2   148 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    1    52 INPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    1    52 INPUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    1    52 INPUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    0     0 FORWARD_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FORWARD_IN_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FORWARD_IN_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FORWARD_OUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FORWARD_OUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 192 packets, 17907 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  192 17907 OUTPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

上面 -nvL選項表示檢視規則,其中 -n表示不針對IP反解析主機名,-L表示列出,-v表示列出的資訊更加詳細

[[email protected] ~]# iptables -F;service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  確定  ]

-F選項表示清除當前所有規則,但清除只是暫時的,重啟iptables服務後還會載入已經儲存的規則,所以使用 service iptables save 儲存一下規則。從上面可以看到,防火牆規則儲存在/etc/sysconfig/iptables中

netfilter的5個表:

1.filter表

filter表 是iptables的預設表,用於過濾包,如果你沒有自定義表,那麼就預設使用filter表,它具有3個內建鏈:

  • INPUT鏈 – 處理來自外部的資料
  • OUTPUT鏈 – 處理向外傳送的資料
  • FORWARD鏈 – 將資料轉發到本機的其他網絡卡裝置上
2.nat表

nat表 用於網路地址轉換,它也有3個內建鏈:

  • PREROUTING鏈 – 處理剛到達本機並在路由轉發前的資料包。它會轉換資料包中的目標IP地址(destination ip address),通常用於DNAT(destination NAT)
  • OUTPUT鏈 – 改變本機產生的包的目的地址
  • POSTROUTING鏈 – 處理即將離開本機的資料包。它會轉換資料包中的源IP地址(source ip address),通常用於SNAT(source NAT)
3.mangle表

mangle表 用於指定如何處理資料包,它能改變TCP頭中的QoS位,Mangle表具有5個內建鏈:

  • PREROUTING鏈
  • INPUT鏈
  • FORWARD鏈
  • OUTPUT鏈
  • POSTROUTING鏈
4.raw表

raw表 可以實現不追蹤某些資料包,預設系統的資料包都會被追蹤,用於處理異常,它具有2個內建鏈:

  • PREROUTING鏈
  • OUTPUT鏈
5.security表

security表 用於強制訪問控制(MAC)的網路規則,在CentOS6中沒有該表

netfilter的5個鏈:

  • PREROUTING:資料包進入路由器之前
  • INPUT:通過路由表後,目的地為本機
  • FORWARD:通過路由表後,目的地不為本機
  • OUTPUT:由本級產生,向外轉發
  • POSTROUTING:傳送到網絡卡介面之前

iptables基本語法:

  1. 檢視規則以及清除規則
[[email protected] ~]# iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 1 packets, 52 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    1    52 PREROUTING_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    1    52 PREROUTING_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    1    52 PREROUTING_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain INPUT (policy ACCEPT 1 packets, 52 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 88 packets, 5914 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   88  5914 OUTPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain POSTROUTING (policy ACCEPT 88 packets, 5914 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   88  5914 POSTROUTING_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   88  5914 POSTROUTING_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   88  5914 POSTROUTING_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0  

-t 選項後面跟表名,不加-t 選項預設指 filter表

[[email protected] ~]# iptables -F
[[email protected] ~]# iptables -Z

-F選項表示刪除所有規則,-Z選項把包以及流量計數器置零
2. 增加/刪除/插入一條規則

[[email protected] ~]# iptables -A INPUT -s 192.168.200.1 -p tcp --sport 1234 -d 192.168.200.200 --dport 80 -j DROP
  • -A/-D/-I:表示增加/刪除/插入一條規則(-I可以插入到最前面,-A只能增加到最後面)
  • -p 指定協議,可以是tcp、udp、icmp或all
  • –dport 必須和-p一起使用,表示指定目標埠
  • –sport 必須和-p一起使用,表示指定源埠
  • -s 指定源ip(可以是一個ip段)
  • -d 指定目的ip(可以是一個ip段)
  • -j 後面跟動作,其中ACCEPT表示允許包,DROP表示丟掉包,REJECT表示拒絕包
  • -i 指定接收進來資料包的網絡卡
  • -o 指定傳送出去資料包的網絡卡
  • –line-number 顯示規則編號(可以根據編號來刪除規則)
  • -P 預設規則,預設為ACCEPT所有包(可以更改為DROP,表示丟棄所有包,不過這是危險操作,儘量不要嘗試)

舉例:

[[email protected] ~]# iptables -I INPUT -s 1.1.1.1 -j DROP

表示插入一條規則,把來自1.1.1.1的資料包全部丟掉

[[email protected] ~]# iptables -D INPUT -s 1.1.1.1 -j DROP

表示刪除把來自1.1.1.1的資料包全部丟掉這條規則(刪除一條規則時,必須和插入或者增加的規則一致,除了-A、-D、-I的區別

[[email protected] ~]# iptables -I INPUT -s 2.2.2.2 -p tcp --dport 80 -j DROP

表示把來自2.2.2.2並且是TCP協議到本機80埠的資料包丟掉(–dport/–sport必須和-p選項一起使用,否則會出錯

[[email protected] ~]# iptables -I OUTPUT -p tcp --dport 22 -d 10.0.1.14 -j DROP

表示把傳送到10.0.1.14的22埠的資料包丟掉

[[email protected] ~]# iptables -A INPUT -s 192.168.1.0/24 -i eth0 -j ACCEPT
[[email protected] ~]# iptables -nvL |grep '192.168.1.0'
    0     0 ACCEPT     all  --  eth0   *       192.168.1.0/24       0.0.0.0/0    

表示把來自192.168.1.0/24這個網段且作用在eth0上的包放行

[[email protected] ~]# iptables -nvL --line-numbers
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1     1594  115K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
2        2   148 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
3       25  1924 INPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
4       25  1924 INPUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
5       25  1924 INPUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
6        0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
7       24  1872 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
8        0     0 ACCEPT     all  --  eth0   *       192.168.1.0/24       0.0.0.0/0           

表示檢視iptables規則,顯示規則編號

[[email protected] ~]# iptables -D INPUT 6
[[email protected] ~]# iptables -nvL --line-numbers
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1     1792  128K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
2        2   148 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
3       25  1924 INPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
4       25  1924 INPUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
5       25  1924 INPUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
6       24  1872 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
7        0     0 ACCEPT     all  --  eth0   *       192.168.1.0/24       0.0.0.0/0

-D 後面依次跟鏈名、規則num,表示刪除對應num的規則

[[email protected] ~]# iptables -P INPUT ACCEPT

-P 表示預設策略,後面跟鏈名,策略內容為ACCEPT,或者是DROP(如果是遠端伺服器時,切勿執行DROP操作,否則遠端連線就會被斷開)

[[email protected] ~]# iptables -I INPUT -m iprange -src 192.168.100.0-192.168.188.255 -j DROP

-m 後面跟模組名字,iprange是一個模組名字,用來支援一個網段
–src-range 指定源ip範圍
–dst-range 指定目標ip範圍

[[email protected] ~]# iptables -I INPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT

–state 指定要匹配包的的狀態

在iptables上有四種狀態:NEW、ESTABLISHED、INVALID、RELATID

  • NEW:conntrack模組看到的某一連線的第一個包
  • ESTABLISHED:只要傳送並接收到應答,連線就是EATABLISHED狀態
  • RELATID:當一個連線和某個已處於EATABLISHED狀態的連線有關係時,就可以認為是RELATID狀態
  • INVALID:INVALID意味著這個包沒有已知的流或連線與之關聯,也可能是它包含的資料或包頭有問題
[[email protected] ~]# iptables -I INPUT -p icmp --icmp-type 8 -j DROP

–icmp-type需要跟-p icmp一起使用,後面指定型別編號,8表示能在本機ping通其他機器,而其他機器無法ping通本機

nat表的應用

A機器兩塊網絡卡ens33(192.168.20.128)、ens37(192.168.100.1),ens33可以上外網,ens37僅僅是內部網路,B機器只有ens34(192.168.100.100),和A機器ens37可以通訊互聯。
A機器配置:

[[email protected] ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.20.128  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::b76:caa8:3d7c:71bc  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e4:fc:a5  txqueuelen 1000  (Ethernet)
        RX packets 313  bytes 28159 (27.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 264  bytes 33270 (32.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.20.130  netmask 255.255.255.0  broadcast 192.168.100.255
        ether 00:0c:29:e4:fc:a5  txqueuelen 1000  (Ethernet)

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.1  netmask 255.255.255.0  broadcast 192.168.133.255
        ether 00:0c:29:e4:fc:af  txqueuelen 1000  (Ethernet)
        RX packets 48  bytes 14388 (14.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 58  bytes 9360 (9.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

B機器配置:

ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.100  netmask 255.255.255.0  broadcast 192.168.133.255
        ether 00:0c:29:e4:fc:af  txqueuelen 1000  (Ethernet)
        RX packets 48  bytes 14388 (14.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 58  bytes 9360 (9.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 需求:可以讓B機器連線外網

A機器上開啟路由轉發 echo “1”>/proc/sys/net/ipv4/ip_forward
A上執行 iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o ens33 -j MASQUERADE
B上設定閘道器為192.168.100.1

 [[email protected] ~]# cat /proc/sys/net/ipv4/ip_forward
0
[[email protected] ~]# echo "1"> /proc/sys/net/ipv4/ip_forward
[[email protected] ~]# cat /proc/sys/net/ipv4/ip_forward
1

表示開啟路由轉發功能

[[email protected] ~]# iptables -t nat -A POSTROUTING -s 192.168.133.0/24 -o ens33 -j MASQUERADE
[[email protected] ~]# iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   42 13256 PREROUTING_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   42 13256 PREROUTING_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   42 13256 PREROUTING_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  104  7831 OUTPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  104  7831 POSTROUTING_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
  104  7831 POSTROUTING_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
  104  7831 POSTROUTING_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 MASQUERADE  all  --  *      ens33   192.168.100.0/24     0.0.0.0/0

iptables對nat表做IP轉發操作,-o 指定傳送出去資料包的網絡卡,這裡就是ens33,MASQUERADE表示偽裝

 [[email protected] ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.20.2   0.0.0.0         UG    100    0        0 ens33
192.168.20.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.100.0   0.0.0.0         255.255.255.0   U     0      0        0 ens34
[[email protected] ~]# route add default gw 198.168.100.1
 [[email protected] ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.1   0.0.0.0         UG    0    0        0 ens34
0.0.0.0         192.168.20.2   0.0.0.0         UG    100    0        0 ens33
192.168.20.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.100.0   0.0.0.0         255.255.255.0   U     0      0        0 ens34

對B機器設定閘道器,route -n 檢視閘道器 ,route add default gw 設定預設閘道器

[[email protected] ~]# ping 192.168.100.1
PING 192.168.100.2 (192.168.100.2) 56(84) bytes of data.
64 bytes from 192.168.100.2: icmp_seq=1 ttl=128 time=0.178 ms
64 bytes from 192.168.100.2: icmp_seq=2 ttl=128 time=0.284 ms
64 bytes from 192.168.100.2: icmp_seq=3 ttl=128 time=0.197 ms
64 bytes from 192.168.100.2: icmp_seq=4 ttl=128 time=0.216 ms
64 bytes from 192.168.100.2: icmp_seq=5 ttl=128 time=0.227 ms
64 bytes from 192.168.100.2: icmp_seq=6 ttl=128 time=0.166 ms
[[email protected]~]#vi /etc/resolv.conf
# Generated by NetworkManager
nameserver 119.29.29.29

給ens34設定DNS:119.29.29.29

[[email protected]~]#ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (115.239.211.112): icmp_seq=1 ttl=128 time=36.10 ms
64 bytes from 14.215.177.38 (115.239.211.112): icmp_seq=2 ttl=128 time=34.81 ms
64 bytes from 14.215.177.38 (115.239.211.112): icmp_seq=3 ttl=128 time=34.07 ms
64 bytes from 14.215.177.38 (115.239.211.112): icmp_seq=4 ttl=128 time=35.81 ms
64 bytes from 14.215.177.38 (115.239.211.112): icmp_seq=5 ttl=128 time=39.24 ms
64 bytes from 14.215.177.38 (115.239.211.112): icmp_seq=6 ttl=128 time=34.4 ms
64 bytes from 14.215.177.38 (115.239.211.112): icmp_seq=7 ttl=128 time=34.27 ms
64 bytes from 14.215.177.38 (115.239.211.112): icmp_seq=8 ttl=128 time=35.25 ms
64 bytes from 14.215.177.38 (115.239.211.112): icmp_seq=9 ttl=128 time=35.89 ms
^C
--- www.a.shifen.com ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 14821ms
rtt min/avg/max/mdev = 34.07/36.770/34.458/33.038 ms

B可以ping通 www.baidu.com,實現B通過nat藉助A來上網,需求滿足

更多資料參考:

相關推薦

Linux日常

10.4 Linux的防火牆 SELinux SELinux是linux系統特有的安全機制,這種機制限制較多,配置也比較繁瑣,所以一般把SELinux關閉。 檢視selinux的狀態有兩種方法: getenforce 命令是單詞get(獲取)和enforce(

日常

iostat ps top tcpdump netstat iostat iostat 直接查看 iostat 1 iostat -x 磁盤使用 %util:表示I/O等待,占用CPU的等待時間,這個數字大,可能硬盤有故障 iotop iotop 磁盤使用y

Linux日常rsync通過服務連接,linux日誌,screen

rsync 通過 服務鏈接 一、rsync通過服務同步分為服務端(server1) 和客戶端(server2)服務端(server1):[root@litongyao ~]# vim /etc/rsyncd.confport=873

教老婆學LinuxLinux常用命令指南【上】

目錄 教老婆學Linux(二)Linux常用命令指南【上】 一、概述 二、常用命令 教老婆學Linux(二)Linux常用命令指南【上】 作者:姚毛毛的部落格 tips:文

linux日常crond,systemd,chkconfing,unit,target)

target unit systemd chkconfing crond 1、任務計劃:crond[root@litongyao ~]# cat /etc/crontab (crontab配置文件) SHELL=/bin/bash

日常

系統命令監控系統狀態 w、uptime 查看系統負載 w 查看系統負載 系統時間、運行時間、登錄用戶數、平均負載1min 5min 15min tty1 系統登錄用戶 pts/0 遠程登錄用戶 cat /proc/cpuinfo 查看cup核數 processor 0 為 1顆 1為2顆 邏

日常

日常運維ifconfig ifconfig 查看網卡IP (yum install -y net-tools) 和 ip add 一樣ifconfig -a 當宕了網卡,沒有IP時,不顯示 ifup / ifdown ifup / ifdown 開啟關閉網卡 用於指定的網卡設定虛擬網卡 將配置文件復制一份

日常

iptablesiptables 規則 默認規則保存在配置文件中/etc/sysconfig/iptables iptables -F 清空規則 service iptables save 保存當前規則到配置文件裏 ###默認規則在 filter 表裏 +t 更改指定的表 默認就是filter表 ipta

日常

firewalledCentOS 7 firewalled 打開firewalled systemctl disable iptables #關閉服務 systemctl stop iptables #停止運行的服務 systemctl enable firewalld

日常

crontab chkconfig systemd unit target crontab crontab 任務計劃 crond服務crontab -u -e -l -r5個*格式:分,時,日,月,周 user command/etc/crontab 配置文件 crontab -e

日常

rsyncrsync 文件同步工具 rsync rsync -av /etc/passwd /tmp/1.txt `-v 可以查看過程` rsync -av /etc/passwd [email protected]:/tmp/1.txt 遠程同步 本機 -

日常

系統日誌系統日誌 /var/log/messages 系統總日誌syslogs /etc/logrotate.conf 日誌切割配置文件 logrotate 參考https://my.oschina.ne00675log/9818 dmesg命令 把系統硬件相關日誌列出來。這些日誌是保存在內存中的

linux安全

系統 gop shutdown ace sim -s user nbsp 服務 1.刪除特殊的用戶和用戶組: linux提供了各種不同角色的系統賬號,在系統安裝完成後,默認會安裝很多不必要的用戶和用戶組,如果不需要某些用戶或用戶組,應立即刪除他們,因為賬號越多,系統就越不

第十章、日常

抓取 進入 fff 0.11 cpu rip 筆記 裏來 ifd 10.1 使用w查看系統負載 10.2 vmstat命令 10.3 top命令 10.4 sar命令 10.5 nload命令 10.6 監控io性能 10.7 free命令 10.8 ps命令 10.9 查

Linux初級——vim編輯器

一、VIM介紹         vim是一個類似於vi的著名的功能強大的、高度可定製的文字編輯器,在vi的基礎上改進和增加了很多特性。vim是自由軟體。vim是從vi發展出來的一個文字編輯器。程式碼補全、編譯及錯誤跳轉等方面

Linux初級——Linux檔案查詢詳解

一、檔案查詢     常用命令:locate,find     1、locate         locate:在全系統查詢檔案的命令。非實

Linux初級十三——RAID及mdadm命令

一、RAID介紹         RAID(Redundant arrays of Independent Drives),有“獨立磁碟構成的具有冗餘能力的陣列”。磁碟陣是由很多價格較便宜的磁碟,組合成一個容量巨大的磁碟組,

自動化——Ansible

23.3 Ansible Ansible和Saltstack比較類似,都是基於Python開發的,Ansible不需要安裝客戶端,通過ssh去通訊。 Ansible有以下優點: 1. 基於模組工作,模組可以由任何語言開發; 2. 支援命令列使用模組,支援編寫ya

PythonDocker虛擬機器

一、Docker 虛擬機器架構 Docker 建立的所有虛擬例項共用同一個Linux核心,對硬體佔用較小,屬於輕量級虛擬機器 二、Docker 映象與容器 容器是從映象中創建出來的虛擬例項 映象是用來安裝程式,是隻讀層 容器是用來執行程式,是隻讀層 倉庫、映象