Sunday, August 23, 2015

Giới hạn IP truy cập web server IIS 8

Giới hạn IP truy cập IIS


  • Cho phép tất cả, chỉ cấm 1 số ip cố định. trường hợp này thường sử dụng web public, ví dụ chúng ta chặn tất cả các ip kết nối từ china *_*. thi sử dụng trường hợp này.
vào file web.config thêm đoạn code sau:
<security>
   <ipSecurity allowUnlisted="true">    <!-- cho phép tất cả mọi người, trừ các ip bên dưới -->            
       <clear/>     <!-- removes all upstream restrictions -->                
       <add ipAddress="83.116.19.53"/>     <!-- ip mà bạn muốn cấm 83.116.19.53   -->                
       <add ipAddress="83.116.119.0" subnetMask="255.255.255.0"/>     <!--blocks network 83.116.119.0 to 83.116.119.255-->                
       <add ipAddress="83.116.0.0" subnetMask="255.255.0.0"/>     <!--blocks network 83.116.0.0 to 83.116.255.255-->                
       <add ipAddress="83.0.0.0" subnetMask="255.0.0.0"/>     <!--blocks entire /8 network of 83.0.0.0 to 83.255.255.255-->                
   </ipSecurity>
</security>


  • Cấm tất cả, chỉ cho phép vài ip cố định. trường hợp này thường dùng cho web nội bộ. không cần public ra ngoài.
vào file web.config thêm đoạn code sau:
<security>
    <ipSecurity allowUnlisted="false">    <!-- block tất cả mọi người chỉ trừ ip bên dưới -->                
        <clear/> <!-- removes all upstream restrictions -->
        <add ipAddress="127.0.0.1" allowed="true"/>    <!-- allow requests from the local machine -->
        <add ipAddress="83.116.19.53" allowed="true"/>   <!-- allow the specific IP of 83.116.19.53  -->                
        <add ipAddress="83.116.119.0" subnetMask="255.255.255.0" allowed="true"/>   <!--allow network 83.116.119.0 to 83.116.119.255-->                
        <add ipAddress="83.116.0.0" subnetMask="255.255.0.0" allowed="true"/>   <!--allow network 83.116.0.0 to 83.116.255.255-->                
        <add ipAddress="83.0.0.0" subnetMask="255.0.0.0" allowed="true"/>   <!--allow entire /8 network of 83.0.0.0 to 83.255.255.255-->                
    </ipSecurity>
</security>