Iptables com o parâmetro -m e -p

8

Eu tenho esta regra no meu iptables:

iptables -A INPUT -p tcp -m tcp --dport 9191 -j DROP

Eu realmente preciso de "-m tcp"? Eu já estou usando "-p tcp", então devo usar "-m tcp" para ser mais seguro?

    
por Samul 06.01.2016 / 14:12

1 resposta

7

Com a opção -p tcp , o módulo tcp já está carregado e, portanto, é um pouco redundante e não é necessário usar a opção -m tcp e não vejo motivo para usar essa opção para tornar a regra mais segura .

Por favor, veja a página man iptables para uma melhor compreensão e comparação:

-p, --protocol [!] protocol

The protocol of the rule or of the packet to check. The specified protocol can be one of tcp, udp, icmp, or all, or it can be a numeric value, representing one of these protocols or a different one. A protocol name from /etc/protocols is also allowed. A "!" argument before the protocol inverts the test. The number zero is equivalent to all. Protocol all will match with all protocols and is taken as default when this option is omitted.

...

Match Extensions

iptables can use extended packet matching modules. These are loaded in two ways: implicitly, when -p or --protocol is specified, or with the -m or --match options, followed by the matching module name; after these, various extra command line options become available, depending on the specific module. You can specify multiple extended match modules in one line, and you can use the -h or --help options after the module has been specified to receive help specific to that module.

E para uma lista de opções disponíveis com -p tcp , veja aqui:

link

Como dito acima, com o uso da opção -m , é possível adicionar módulos de extensão e mais opções de correspondência são disponibilizadas. Por exemplo, o módulo cpu :

cpu

[!] --cpu number

Match cpu handling this packet. cpus are numbered from 0 to NR_CPUS-1 Can be used in combination with RPS (Remote Packet Steering) or multiqueue NICs to spread network traffic on different queues.

Example:

iptables -t nat -A PREROUTING -p tcp --dport 80 -m cpu --cpu 0 -j REDIRECT --to-port 8080

iptables -t nat -A PREROUTING -p tcp --dport 80 -m cpu --cpu 1 -j REDIRECT --to-port 8081

Available since Linux 2.6.36.

Lista completa de extensões iptables.

Pergunta adicional do OP: Eu não entendo o que o -m corresponde. Que corda? -m tcp combina com o que? Ele tenta encontrar a palavra "tcp" onde?

Resposta: -m é para corresponder ao nome do módulo e não à string. Ao usar um determinado módulo, você obtém certas opções para correspondência. Veja o exemplo do módulo cpu acima. Com o -m tcp , o módulo tcp é carregado. O módulo tcp permite certas opções: --dport, --sport, --tcp-flags, --syn, --tcp-option para usar nas regras do iptables. Mas usar -p tcp já habilita o módulo tcp, e é por isso que ainda é possível usar essas opções mesmo sem usar -m tcp . Espero que isso limpe toda a sua confusão.

    
por 06.01.2016 / 14:29