iptables에서 addrtype의 정의는 무엇입니까?

iptables에서 addrtype의 정의는 무엇입니까?

addrtype나는 이것을 내 필터 체인 중 하나에 결합하여 다음과 같은 일부 Bogon IP를 제거하고 싶습니다 .-src

-A INPUT -p tcp --dport 80 -m addrtype --src-type UNICAST ! -s 127.0.0.0/8 -j WEB

매뉴얼 페이지는 다음을 보여줍니다

주소 유형
이 모듈은 주소 유형에 따라 패킷을 일치시킵니다. 주소 유형은 커널 네트워크 스택에서 사용되며 주소를 다른 그룹으로 그룹화합니다. 이 그룹의 정확한 정의는 특정 계층 3 프로토콜에 따라 다릅니다.

다음 주소 유형이 가능합니다.

  • UNSPEC 지정되지 않은 주소(예: 0.0.0.0)
  • UNICAST 유니캐스트 주소
  • LOCAL 로컬 주소
  • BROADCAST 방송 주소
  • ANYCAST 애니캐스트 패킷
  • MULTICAST 멀티캐스트 주소
  • BLACKHOLE 블랙홀 주소
  • UNREACHABLE 연결할 수 없는 주소
  • PROHIBIT 금지된 주소
  • 나를 고쳐줘
  • NAT 복구
  • 해결책

특정 레이어 3 프로토콜에 따라 다르다는 점에서 정확한 정의가 무엇인지는 불분명합니다. 그렇게 생각해요:

  • 유니캐스트(!브로드캐스트, !멀티캐스트, !ANYCAST)
  • 현지의( 127.0.0.0/8)
  • 방송 ( *.*.*.255)
  • 애니캐스트( *.*.*.*)
  • 멀티캐스트( 224.0.0.0/4)

이것이 무엇을 의미하는지 그리고 iptables가 이를 어떻게 구현하는지 아는 사람이 있습니까(예: 블랙홀이 실제로 어디에 있는지 어떻게 알 수 있습니까?)

답변1

나는 그것이 블랙홀 주소 유형이 무엇인지 커널에 알려주는 것에 달려 있다고 생각합니다.

~에서xt_addrtype.hiptables 소스 코드에서 파일을 보면 다음을 볼 수 있습니다.

/* rtn_type enum values from rtnetlink.h, but shifted */                        
enum {                                                                          
    XT_ADDRTYPE_UNSPEC = 1 << 0,                                                
    XT_ADDRTYPE_UNICAST = 1 << 1,   /* 1 << RTN_UNICAST */                      
    XT_ADDRTYPE_LOCAL  = 1 << 2,    /* 1 << RTN_LOCAL, etc */                   
    XT_ADDRTYPE_BROADCAST = 1 << 3,                                             
    XT_ADDRTYPE_ANYCAST = 1 << 4,                                               
    XT_ADDRTYPE_MULTICAST = 1 << 5,                                             
    XT_ADDRTYPE_BLACKHOLE = 1 << 6,                                             
    XT_ADDRTYPE_UNREACHABLE = 1 << 7,                                           
    XT_ADDRTYPE_PROHIBIT = 1 << 8,                                              
    XT_ADDRTYPE_THROW = 1 << 9,                                                 
    XT_ADDRTYPE_NAT = 1 << 10,                                                  
    XT_ADDRTYPE_XRESOLVE = 1 << 11,                                             
};

에서 rtnetlink.h동일한 정의를 볼 수 있습니다.

enum {                                                                          
    RTN_UNSPEC,                                                                 
    RTN_UNICAST,        /* Gateway or direct route  */                          
    RTN_LOCAL,      /* Accept locally       */                                  
    RTN_BROADCAST,      /* Accept locally as broadcast,                         
                   send as broadcast */                                         
    RTN_ANYCAST,        /* Accept locally as broadcast,                         
                   but send as unicast */                                       
    RTN_MULTICAST,      /* Multicast route      */                              
    RTN_BLACKHOLE,      /* Drop             */                                  
    RTN_UNREACHABLE,    /* Destination is unreachable   */                      
    RTN_PROHIBIT,       /* Administratively prohibited  */                      
    RTN_THROW,      /* Not in this table        */                              
    RTN_NAT,        /* Translate this address   */                              
    RTN_XRESOLVE,       /* Use external resolver    */                          
    __RTN_MAX                                                                   
};

iptables커널 TCP 네트워크 스택에서 동일한 주소 유형 정의가 사용되는 것을 볼 수 있습니다 .

그런 다음 man ip:

Route types:

      unicast - the route entry describes real paths to the destinations covered by the route prefix.

      unreachable  - these destinations are unreachable.  Packets are discarded and the ICMP message host unreachable is generated.
               The local senders get an EHOSTUNREACH error.

      blackhole - these destinations are unreachable.  Packets are discarded silently.  The local senders get an EINVAL error.

      prohibit - these destinations are unreachable.  Packets are discarded and the  ICMP  message  communication  administratively
               prohibited is generated.  The local senders get an EACCES error.

      local - the destinations are assigned to this host.  The packets are looped back and delivered locally.

      broadcast - the destinations are broadcast addresses.  The packets are sent as link broadcasts.

      throw  - a special control route used together with policy rules. If such a route is selected, lookup in this table is termi‐
               nated pretending that no route was found.  Without policy routing it is equivalent to the absence of the route in the routing
               table.   The  packets  are  dropped  and the ICMP message net unreachable is generated.  The local senders get an ENETUNREACH
               error.

      nat - a special NAT route.  Destinations covered by the prefix are considered to  be  dummy  (or  external)  addresses  which
               require  translation  to  real  (or  internal)  ones  before forwarding.  The addresses to translate to are selected with the
               attribute Warning: Route NAT is no longer supported in Linux 2.6.

               via.

      anycast - not implemented the destinations are anycast addresses assigned to this host.  They are mainly equivalent to  local
               with one difference: such addresses are invalid when used as the source address of any packet.

      multicast - a special type used for multicast routing.  It is not present in normal routing tables.

따라서 네트워크에 대한 경로를 정의 ip하고 명령을 통해 이를 블랙홀 경로로 표시하면 커널은 이제 이 네트워크 주소를 블랙홀 유형으로 만듭니다.

ip route add blackhole X.X.X.X/24

관련 정보