iptables練習

系統的INPUT和OUTPUT默認策略為DROP;

1、限制本地主機的web服務器在周一不允許訪問;新請求的速率不能超過100個每秒;web服務器包含了admin字符串的頁面不允許訪問;web服務器僅允許響應報文離開本機;

系統默認策略設定:

~]# iptables -P INPUT DROP

~]# iptables -P OUPUT DROP

網絡說明:

本地主機網段為192.168.150.0/24

web服務器IP為192.168.150.137


INPUT

~]# iptables -A INPUT -s 192.168.150.0/24 -d 192.168.150.137 -p tcp –dport 80 -m time –weekdays Mon –kerneltz -j DROP

~]# iptables -A INPUT -d 192.168.150.137 -p tcp –dport80 -m limit –limit 100/second -m state –state NEW -j ACCEPT

~]# iptables -A INPUT -s 192.168.150.0/24 -d 192.168.150.137 -p tcp –dport 80 -j ACCEPT


OUTPUT

~]# iptables -A OUTPUT -s 192.168.150.137 -d 0/0 -p tcp –sport 80 -m string –algo bm –string "admin" -j REJECT

~]# iptables -A OUTPUT -s 192.168.150.137 -d 0/0 -p tcp –sport 80 -m state –state ESTABLISHED -j ACCEPT

2、在工作時間,即周一到周五的8:30-18:00,開放本機的ftp服務給172.16.0.0網絡中的主機訪問;數據下載請求的次數每分鐘不得超過5個;

INPUT:

#iptables -A INPUT -s 172.16.0.0/16 -p tcp –dport 21 -m time –timestart 08:30 –timestop 18:00 –weekdays Mon,Tue,Wed,Thu,Fri -m limit –limit-burst 5 –limit 5/minute -j ACCEPT

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

OUTPUT

#iptables -A OUTPUT -p tcp -m multiport –sport 20,21 -m state –state ESTABLISHED,RELATED -j ACCEPT

3、開放本機的ssh服務給172.16.x.1-172.16.x.100中的主機,x為你的座位號,新請求建立的速率一分鐘不得超過2個;僅允許響應報文通過其服務端口離開本機;

INPUT:

#iptables -A INPUT -d 172.16.100.6 -p tcp –dport 22 -m iprange –src-range 172.16.100.1-172.16.100.100 -m limit –limit 2/minute -j ACCEPT

OUTPUT:

# iptables -A OUTPUT -s 172.16.100.6 -p tcp –sport 22 -m iprange –dst-range 172.16.100.1-172.16.100.100 -m state –state ESTABLISHED -j ACCEPT

4、拒絕TCP標志位全部為1及全部為0的報文訪問本機;

# iptabels -A INPUT -d 192.168.150.137 -p tcp –tcp-flags ALL ALL -j DROP

# iptables -A INPUT -d 192.168.150.137 -p tcp –tcp-flags ALL NONE -j DROP

5、允許本機ping別的主機;但不開放別的主機ping本機;

# iptables -A OUTPUT -s 192.168.150.138 -p icmp –icmp-type 8 -j ACCEPT     請求包

# iptables -A INPUT -d 192.168.150.138 -p icmp –icmp-type 0 -j ACCEPT     回包

6、判斷下述規則的意義:

 

# iptables -N clean_in

     創建自定義鏈clean_in

  # iptables -A clean_in -d 255.255.255.255 -p icmp -j DROP     丟棄不定向廣播ping包

  # iptables -A clean_in -d 172.16.255.255 -p icmp -j DROP     丟棄定向廣播ping包

     禁止廣播探測本網絡主機在線情況

  # iptables -A clean_in -p tcp ! –syn -m state –state NEW -j DROPQ      丟棄syn標志不為1的包和追蹤狀態為新連接的包

  # iptables -A clean_in -p tcp –tcp-flags ALL ALL -j DROP     標志位全1的丟棄,全1肯定是不正常的包

  # iptables -A clean_in -p tcp –tcp-flags ALL NONE -j DROP     標志位全0的丟棄,全0肯定是不正常的包

  # iptables -A clean_in -d 172.16.100.7 -j RETURN     正常的報文RETURN

     定義一個清理鏈

  # iptables -A INPUT -d 172.16.100.7 -j clean_in     到目的主機的報文過來轉給自定義鏈clean_in

  # iptables -A INPUT  -i lo -j ACCEPT     允許數據報文流入環回口

  # iptables -A OUTPUT -o lo -j ACCEPT     允許數據報文流出環回口

     開放本地環回口

  # iptables -A INPUT  -i eth0 -m multiport -p tcp –dports 53,113,135,137,139,445 -j DROP     指定流入報文接口為eth0,協議為tcp,目標端口為53,113,135,137,139,445,報文丟棄

  # iptables -A INPUT  -i eth0 -m multiport -p udp –dports 53,113,135,137,139,445 -j DROP     指定流入報文接口為eth0,協議為udp,目標端口為53,113,135,137,139,445,報文丟棄

  # iptables -A INPUT  -i eth0 -p udp –dport 1026 -j DROP     流入eth0的udp,端口為1026報文丟棄

  # iptables -A INPUT  -i eth0 -m multiport -p tcp –dports 1433,4899 -j DROP     流入eth0的tcp,端口為1433,4899報文丟棄

  # iptables -A INPUT  -p icmp -m limit –limit 10/second -j ACCEPT     限制ping包個數每秒最多10個

7、通過tcp_wrapper控制vsftpd僅允許172.16.0.0/255.255.0.0網絡中的主機訪問,但172.16.100.3除外;對所被被拒絕的訪問嘗試都記錄在/var/log/tcp_wrapper.log日志文件中;

~]# vim /etc/hosts.allow

#

# hosts.allow    This file contains access rules which are used to

#        allow or deny connections to network services that

#        either use the tcp_wrappers library or that have been

#        started through a tcp_wrappers-enabled xinetd.

#

#        See 'man 5 hosts_options' and 'man 5 hosts_access'

#        for information on rule syntax.

#        See 'man tcpd' for information on tcp_wrappers

#

vsftpd:192.168.150.0/255.255.255.0 EXCEPT 192.168.150.138

~]# vim /etc/hosts.deny

[root@localhost ~]# cat /etc/hosts.deny

#

# hosts.deny    This file contains access rules which are used to

#        deny connections to network services that either use

#        the tcp_wrappers library or that have been

#        started through a tcp_wrappers-enabled xinetd.

#

#        The rules in this file can also be set up in

#        /etc/hosts.allow with a 'deny' option instead.

#

#        See 'man 5 hosts_options' and 'man 5 hosts_access'

#        for information on rule syntax.

#        See 'man tcpd' for information on tcp_wrappers

#

vsftpd:ALL :spawn /bin/echo `date` login attempt from %c to %s, %d >> /var/log/tcp_wrapper.log

執行結果

192.168.150.136主機

[root@localhost ~]# ftp 192.168.150.137

Connected to 192.168.150.137 (192.168.150.137).

220 (vsFTPd 3.0.2)

Name (192.168.150.137:root):

192.168.150.138主機

~]# ftp 192.168.150.137

Connected to 192.168.150.137 (192.168.150.137).

421 Service not available.

日志信息:

~]# cat /var/log/tcp_wrapper.log

2016年 12月 25日 星期日 16:41:17 CST login attempt from 192.168.150.138 to vsftpd@192.168.150.137, vsft

pd2016年 12月 25日 星期日 16:44:10 CST login attempt from 192.168.150.138 to vsftpd@192.168.150.137, vsft

pd

 

原創文章,作者:N23-蘇州-void,如若轉載,請注明出處:http://www.www58058.com/65032

(0)
N23-蘇州-voidN23-蘇州-void
上一篇 2016-12-27 19:26
下一篇 2016-12-27 21:23

相關推薦

  • CentOS7的虛擬機安裝

    剛學習linux下CentOS7的操作,熟悉一下CentOS7的安裝,所以寫一下CentOS7的安裝教程,如果那里有寫的不對的話希望得到指正。 我是在VMware下裝的CentOS7 第一步配置硬件 先創建一個虛擬機 這里我選擇的典型模式,新手嘛,新手難度的創建就好,高手難度的等新手難度熟練了再去碰好了,當然這是我的建議… 下一步然后光盤選擇稍后…

    2017-07-15
  • 馬哥教育網絡班21期+第六周課程練習

    第六周作業 1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#; cp /etc/rc.d/rc.sysinit /tmpvim /tmp/rc.sysinit # 命令模式下,輸入一下內容:%s@\(^[[:space:]]…

    Linux干貨 2016-10-17
  • linux基礎第二周

    1.?用chattr命令防止系統中某個關鍵文件被修改:# chattr +i /etc/resolv.conf 然后用mv /etc/resolv.conf等命令操作于該文件,都是得到Operation not permitted 的結果。vim編輯該文件時會提示W10: Warning: Changing a readonly file錯誤。要想修改此文件…

    2017-09-09
  • Linux命令的使用格式以及命令幫助信息的獲取方式

    1.Linux系統上的命令使用格式 2.Linux系統程序文件存放位置 3.Linux獲取命令的幫助信息 區分內部命令和外部命令 內部命令在系統啟動時就調入內存,是常駐內存的,所以執行效率高。 外部命令是系統的軟件功能,用戶需要時才從硬盤中讀入內存。 #type COMMAND 內部命令獲取幫助信息:#help COMMAND 外部命令獲取幫助信息…

    Linux干貨 2016-10-29
  • 馬哥教育網絡班22期+第六周課程練習

    1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#; ]# cp -v  /etc/rc.d/rc.sysinit /tmp/    `/etc/rc.d/rc.sysinit' -> `/tmp/rc.sysinit&…

    Linux干貨 2016-10-17
  • LVM相關使用

    前言: LVM是 Logical Volume Manager(邏輯卷管理)的簡寫,它是Linux環境下對磁盤分區進行管理的一種機制,它由Heinz Mauelshagen在Linux 2.4內核上實現,Linux用戶安裝Linux操作系統時遇到的一個常見的難以決定的問題就是如何正確地評估各分區大小,以分配合適的硬盤空間。普通的磁盤分區管理方式在邏輯分區劃分…

    Linux干貨 2017-08-13

評論列表(1條)

  • 馬哥教育
    馬哥教育 2017-01-03 16:48

    邏輯清晰,備注完整,非常好的作業。這篇作業題目實用性很強,你的完成程序非常好,相信在以后工作中會有很大幫助。

欧美性久久久久