Linux時間設定及iptables命令,linuxiptables命令

來源:互聯網
上載者:User

Linux時間設定及iptables命令,linuxiptables命令
Linux時間設定與iptables命令日期與時間設定

timedatectl:顯示目前時區與時間等資訊

eg:

[root@localhost zhang]# timedatectl      Local time: Thu 2018-01-18 10:13:55 UTC  Universal time: Thu 2018-01-18 10:13:55 UTC        RTC time: Thu 2018-01-18 10:13:54        Timezone: UTC (UTC, +0000)     NTP enabled: yesNTP synchronized: yes RTC in local TZ: no      DST active: n/a

時區的調整

timedatectl set-timezone "Asia/Shanghai"設定時區為上海

eg:

timedatectl set-timezone "Asia/Shanghai"[root@localhost zhang]# timedatectl      Local time: Thu 2018-01-18 18:15:46 CST  Universal time: Thu 2018-01-18 10:15:46 UTC        RTC time: Thu 2018-01-18 10:15:46        Timezone: Asia/Shanghai (CST, +0800)     NTP enabled: yesNTP synchronized: yes RTC in local TZ: no      DST active: n/a

時間的調整

timedatectl set-time "2018-01-18 16:18"

eg:

[root@localhost zhang]# timedatectl set-time "2018-01-20 20:20"[root@localhost zhang]# timedatectl      Local time: Sat 2018-01-20 20:20:06 CST  Universal time: Sat 2018-01-20 12:20:06 UTC        RTC time: Sat 2018-01-20 12:20:06        Timezone: Asia/Shanghai (CST, +0800)     NTP enabled: yesNTP synchronized: no RTC in local TZ: no      DST active: n/a

hwcdate:自動更新時間

eg:

[root@localhost zhang]# hwclockThu 18 Jan 2018 06:21:41 PM CST  -0.896079 seconds
防火牆設定

iptables命令

iptables命令時Linux上常用的防火牆軟體,是netfilter項目的一部分。可以直接配置,也可以通過許多前端和圖形介面配置。

iptables文法:

iptables (選項)(參數)

iptables選項和參數

-t :指定要操作的表 -A:向規則鏈中添加條目 -D:從規則鏈中刪除條目 -i:向規則鏈中插入條目 -R:替換規則鏈中的條目 -L:顯示規則鏈中已有的條目 -F:清楚規則鏈中已有的條目 -Z:清空規則鏈中的資料包計算機和位元組計數器 -N:建立新的使用者自訂規則鏈 -P:定義規則鏈中的預設目標 -h:顯示協助資訊 -p:指定要匹配的資料包協議類型 -s:指定要匹配的資料包源ip地址 -j <目標>:指定要跳轉的目標 -i <網路介面>:指定資料包進入原生網路介面 -o <網路介面>:指定資料包要離開本機所使用的的網路介面

iptables命令選項輸入順序

iptables -t 表名 <-A/I/D/R> 規則鏈名 [規則號] <-i/o 網卡名> -p 協議名 <-s 源IP/源子網> --sport 源連接埠 <-d 目標IP/目標子網> --dport 目標連接埠 -j 動作

iptables的表名包括:

raw:進階功能。如:網址過濾

mangle:資料包修改,用於實現服務品質

net:地址轉換,用於網關路由器。

filter:包過濾,用於防火牆規則。

規則鏈名包括:

INPUT鏈:處理輸入資料包

OUTPUT鏈:處理輸出資料包

PORWARE鏈:處理轉寄資料包

PREROUTING鏈:用於目標地址轉換(DNAT)

POSTOUTING鏈:用於源地址轉換(SNAT)

動作包括:

ACCEPT:接收資料包 DROP:丟棄資料包 REDIRECT:重新導向、映射、透明代理。 SNAT:源地址轉換 DNAT:目標地址轉換 MASQUERADE:IP偽裝(NAT),用於ADSL。 LOG:日誌記錄

執行個體

清除已有iptables規則:

iptables -Fiptables -Xiptables -Z

開放指定的連接埠

# 允許本地迴環地址介面(即運行本機訪問本機)iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT# 允許已建立的或相關聯的通行iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT# 允許所有本機向外的訪問iptables -A OUTPUT -j ACCEPT# 允許訪問22連接埠iptables -A INPUT -p tcp --dport 22 -j ACCEPT#允許訪問80連接埠iptables -A INPUT -p tcp --dport 80 -j ACCEPT    #允許ftp服務的21連接埠iptables -A INPUT -p tcp --dport 21 -j ACCEPT    #允許FTP服務的20連接埠iptables -A INPUT -p tcp --dport 20 -j ACCEPT  #禁止其他未允許的規則訪問iptables -A INPUT -j reject#禁止其他未允許的規則訪問iptables -A FORWARD -j REJECT     

屏蔽IP

#屏蔽單個IPiptables -I INPUT -s 192.168.170.131 -j DROP#封整個段即從192.0.0.1到192.255.255.254的命令iptables -I INPUT -s 192.0.0.0/8 -j DROP     #封IP段即從192.168.0.1到192.168.255.254的命令iptables -I INPUT -s 192.168.0.0/16 -j DROP  #封IP段即從192.168.170.1到192.168.170.254的命令是iptables -I INPUT -s 192.168.170.0/24 -j DROP    

查看已添加的iptables規則

[root@localhost zhang]# iptables -L -n -v Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target     prot opt in     out     source               destination             1    56 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED    1    84 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0               5  1645 INPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0               5  1645 INPUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0               5  1645 INPUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0               0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0               5  1645 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibitedChain 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   ...

將所有iptables以序號標記顯示,執行

[root@localhost zhang]# iptables -L -n --line-numbersChain INPUT (policy ACCEPT)num  target     prot opt source               destination         1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           3    INPUT_direct  all  --  0.0.0.0/0            0.0.0.0/0           4    INPUT_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           5    INPUT_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           6    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           7    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT)num  target     prot opt source               destination         1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           3    FORWARD_direct  all  --  0.0.0.0/0            0.0.0.0/0           4    FORWARD_IN_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           5    FORWARD_IN_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           6    FORWARD_OUT_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           7    FORWARD_OUT_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           8    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           9    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited...

刪除已添加的iptables規則

iptables -D INPUT 8

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.