精品丰满熟女一区二区三区_五月天亚洲欧美综合网_亚洲青青青在线观看_国产一区二区精选

  • <menu id="29e66"></menu>

    <bdo id="29e66"><mark id="29e66"><legend id="29e66"></legend></mark></bdo>

  • <pre id="29e66"><tt id="29e66"><rt id="29e66"></rt></tt></pre>

      <label id="29e66"></label><address id="29e66"><mark id="29e66"><strike id="29e66"></strike></mark></address>
      學(xué)習(xí)啦>學(xué)習(xí)電腦>電腦安全>防火墻知識(shí)>

      Linux防火墻iptables簡明教程

      時(shí)間: 林澤1002 分享

        linux下常見的防火墻iptables的一些內(nèi)容,但是無奈網(wǎng)上的很多教程都較為繁瑣,本著簡明化學(xué)習(xí)的目的,微魔為大家剔除了許多冗余的內(nèi)容。下面是學(xué)習(xí)啦小編跟大家分享的是Linux防火墻iptables簡明教程,歡迎大家來閱讀學(xué)習(xí)。

        Linux防火墻iptables簡明教程

        1.安裝iptables

        2.查看現(xiàn)有的iptables規(guī)則

        3.刪除某iptables規(guī)則

        4.清除現(xiàn)有iptables規(guī)則

        5.創(chuàng)建規(guī)則

        6.設(shè)置開機(jī)啟動(dòng)

        7.保存iptables規(guī)則

        8.iptables在手動(dòng)防CC攻擊中的簡單應(yīng)用

        1.安裝iptables

        很多Linux已經(jīng)默認(rèn)安裝iptables,可使用后文的查看命令測試是否安裝

        CentOS/RedHat下執(zhí)行:

        yum install iptablesDebian/Ubuntu下執(zhí)行:

        apt-get install iptables

        2.查看現(xiàn)有的iptables規(guī)則

        命令后面的line-number為顯示行號(hào)(將規(guī)則一則一則輸出,并顯示行號(hào)),可選,方便后文的刪除指令。

        iptables -L -n --line-numbers

        3.刪除某iptables規(guī)則

        例如,刪除第12行的規(guī)則,行號(hào)可由之前的命令查看

        iptables -D INPUT 12

        4.清除現(xiàn)有iptables規(guī)則

        iptables -F

        iptables -X

        iptables -Z

        5.創(chuàng)建規(guī)則

        a).開放端口

        命令iptables -A INPUT -j REJECT將屏蔽其他未授權(quán)的端口,因此請務(wù)必開放22端口以保障SSH連接正常~

        復(fù)制代碼代碼如下:

        #允許本機(jī)訪問

        iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT

        # 允許已建立的或相關(guān)連的通行

        iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

        #允許所有本機(jī)向外的訪問

        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服務(wù)的21和20端口

        iptables -A INPUT -p tcp --dport 21 -j ACCEPT

        iptables -A INPUT -p tcp --dport 20 -j ACCEPT

        #如果有其他端口的話,規(guī)則也類似,稍微修改上述語句就行

        #禁止其他未允許的規(guī)則訪問

        iptables -A INPUT -j REJECT

        iptables -A FORWARD -j REJECT

        b).屏蔽ip

        iptables -I INPUT -s 123.123.123.123 -j DROP可通過更換上述ip為ip段來達(dá)到屏蔽ip段的目的~

        若需屏蔽整個(gè)ip段(123.0.0.1到123.255.255.254)則換為123.0.0.0/8

        若需屏蔽ip段123.123.0.1到123.123.255.254,則換為124.123.0.0/16

        若需屏蔽ip段123.123.123.1到123.123.123.254則換為123.123.123.0/24

        6.設(shè)置開機(jī)啟動(dòng)

        一般在安裝iptables完成后,開機(jī)啟動(dòng)會(huì)自動(dòng)設(shè)置成功,但在個(gè)別CentOS系統(tǒng)上,貌似還有些問題,可以使用如下命令手動(dòng)設(shè)置

        chkconfig --level 345 iptables on

        7.保存iptables規(guī)則

        service iptables save

        8.iptables在手動(dòng)防CC攻擊中的簡單應(yīng)用

        關(guān)于獲取攻擊者ip的方法,可以通過很多方法獲取,如查看網(wǎng)站日志等,本文不再贅述。

        a).建立要屏蔽的ip/ip段文件,名為ip.txt

        #屏蔽的ip

        123.4.5.6

        #屏蔽的ip段(編寫方法,同前文)

        123.4.5.6/24b).建立block_ip.sh腳本文件

        復(fù)制代碼代碼如下:

        #!/bin/sh

        # Filename: block_ip.sh

        # Purpose: blocks all IP address/network found in a text file

        # The text file must have one IP address or network per line

        #################################################################

        # Change the following path/filename to match yours

        IP_LIST_FILE=/path/to/ip.txt

        #################################################################

        # Don't change anything below unless you are a smarty pant!

        #################################################################

        IPTABLES_BIN=/sbin/iptables

        # Get the IP address/network from the file and ignore any line starting with # (comments)

        BAD_IP_ADDR_LIST=$(grep -Ev "^#" $IP_LIST_FILE)

        # Now loop through the IP address/network list and ban them using iptabels

        for i in $BAD_IP_ADDR_LIST

        do

        echo -n "Blocking $i ...";

        $IPTABLES_BIN -A INPUT -s $i -j DROP

        $IPTABLES_BIN -A OUTPUT -d $i -j DROP

        echo "DONE.";

        done

        ##################################################################

        # END OF SCRIPT - NOTHING TO SEE HERE - THAT'S ALL FOLKS!

        ##################################################################

        c).運(yùn)行腳本

        sh /path/to/block_ip.sh

        d).查看iptables規(guī)則是否生效/正確,這一步的命令,之前有提到哦,開動(dòng)腦筋,實(shí)在忘了,點(diǎn)擊此處~

      Linux防火墻iptables簡明教程

      linux下常見的防火墻iptables的一些內(nèi)容,但是無奈網(wǎng)上的很多教程都較為繁瑣,本著簡明化學(xué)習(xí)的目的,微魔為大家剔除了許多冗余的內(nèi)容。下面是學(xué)習(xí)啦小編跟大家分享的是Linux防火墻iptables簡明教程,歡迎大家來閱讀學(xué)習(xí)。 Linux防火墻ip
      推薦度:
      點(diǎn)擊下載文檔文檔為doc格式
      2672674