# Firewall

O firewall é uma solução de segurança que permite criar regras para monitorar e/ou bloquear a entrada e saída de uma rede. O firewall no Linux vem por padrão aceitando qualquer entrada e saída, você deverá configurar da forma que for necessária.

A forma mais "correta" de usar o firewall é bloquear tudo e liberar manualmente apenas o que for necessário. Para visualizar como estão as regras do firewall, utilizamos o comando a seguir.

```
root@server5:/# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 
```

Este é um caso onde está mal configurado, estão todas com regras para aceitar o tráfego. Se quisermos aplicar a política para dropar tudo na entrada, utilizamos o comando a seguir.

```
root@server5:/# iptables -P INPUT DROP
```

Vale lembrar que é bloqueado qualquer tipo de pacote, se tentarmos pingar, por exemplo, não irá funcionar. Para liberarmos determinadas portas, fazemos dessa forma.

```
root@server5:/# iptables -A INPUT -p TCP — dport 80 -j ACCEPT
```

Para aplicar a regra para especificamente um host utilizamos o comando a seguir.

```
root@server5:/# iptables -A INPUT -p TCP — dport 80 -s <ip> -j ACCEPT
```

Para bloquear determinada porta, utilizamos.

```
root@server5:/# iptables -A INPUT -p tcp —dport 80 -j DROP
```

Para apagar todas as regras, basta utilizar.

```
root@server5:/# iptables -F
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nicollaslopes.gitbook.io/estudos/master/scanning/firewall.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
