-
Notifications
You must be signed in to change notification settings - Fork 0
/
ufw.sh
executable file
·79 lines (62 loc) · 4.1 KB
/
ufw.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
# Script desenvolvido por João Rodrigues - Contato: [email protected]
# Licença: MIT
#
# Permissão é concedida, gratuitamente, a qualquer pessoa que obtenha uma cópia deste software e arquivos de documentação associados
# (o "Software"), para lidar no Software sem restrição, incluindo, sem limitação, os direitos de usar, copiar, modificar, mesclar,
# publicar, distribuir, sublicenciar e/ou vender cópias do Software, sujeita às seguintes condições:
#
# A licença acima deve ser incluída em todas as cópias ou partes substanciais do Software.
#
# O SOFTWARE É FORNECIDO "NO ESTADO EM QUE SE ENCONTRA", SEM GARANTIAS DE QUALQUER TIPO, EXPRESSAS OU IMPLÍCITAS, INCLUINDO, MAS NÃO SE LIMITANDO ÀS GARANTIAS DE
# COMERCIALIZAÇÃO, ADEQUAÇÃO A UM FIM ESPECÍFICO E NÃO VIOLAÇÃO. EM NENHUM CASO OS AUTORES OU TITULARES DOS DIREITOS AUTORAIS SERÃO RESPONSÁVEIS POR QUALQUER RECLAMAÇÃO,
# DANO OU OUTRA RESPONSABILIDADE, SEJA EM AÇÃO DE CONTRATO, AGRAVO OU OUTRA AÇÃO, DECORRENTE DE OU EM CONEXÃO COM O SOFTWARE OU O USO OU OUTRAS NEGOCIAÇÕES NO SOFTWARE.
# Programa desenvolvido para automatizar configuração do firewall - Uncomplicated Firewall - ufw
# Este script permite configurar o firewall para serviços básicos de um usuário, liberação de acessos SSH, FTP,
# liberação de navegação de internet, acessos remotos através do Teamviewer, Anydesk e para serviços avançados em ambientes Kubernetes usando Kubeadm
# Este script destina-se a usuários intermediários e avançados que estão utilizando o Kubernetes com kubeadm para estudos ou em ambientes de produção.
# Definir cores para o terminal
red='\033[0;31m'
green='\033[0;32m'
orange='\033[0;33m'
close='\033[0m'
# Verificar se o script está sendo executado como root
[[ "$UID" -ne "0" ]] && { echo -e "${red}\nExecute como root!${close}" ; exit 1; }
echo -e "${orange}\nDefinindo a política padrão para bloquear todas as conexões de entrada...${close}"
ufw default deny incoming
echo -e "${orange}\nDefinindo a política padrão para permitir todas as conexões de saída...${close}"
ufw default allow outgoing
# Permitir acesso SSH apenas da rede local (192.168.0.0/24) na porta 3390
echo -e "${orange}\nPermitindo o acesso SSH apenas da rede local (192.168.0.0/24) na porta 3390...${close}"
ufw allow from 192.168.0.0/24 to any port 3390 proto tcp
# Permitir acesso FTP apenas da rede local (192.168.0.0/24) na porta 21
echo -e "${orange}\nPermitindo o acesso FTP apenas da rede local (192.168.0.0/24) na porta 21 (controle e dados)...${close}"
ufw allow from 192.168.0.0/24 to any port 21 proto tcp
# Permitir acesso HTTP na porta 80 para navegação na web
echo -e "${orange}\nPermitindo o acesso HTTP na porta 80 para navegação na web...${close}"
ufw allow http
# Permitir acesso HTTPS na porta 443 para navegação segura na web
echo -e "${orange}\nPermitindo o acesso HTTPS na porta 443 para navegação segura na web...${close}"
ufw allow https
# Permitir acesso Kubernetes API Server na porta 6443
echo -e "${orange}\nPermitindo o acesso Kubernetes API Server na porta 6443...${close}"
ufw allow 6443/tcp
# Permitir acesso às portas do Kubelet (10250-10255)
echo -e "${orange}\nPermitindo o acesso às portas do Kubelet (10250-10255)...${close}"
ufw allow 10250:10255/tcp
# Permitir acesso às portas NodePort Services (30000-32767)
echo -e "${orange}\nPermitindo o acesso às portas NodePort Services (30000-32767)...${close}"
ufw allow 30000:32767/tcp
# Permitir acesso ao etcd nas portas 2379-2380
echo -e "${orange}\nPermitindo o acesso ao etcd nas portas 2379-2380...${close}"
ufw allow 2379:2380/tcp
# Permitir acesso TCP e UDP nas portas 1714-1764 - KDEConnet
echo -e "${orange}\nPermitindo o acesso TCP e UDP nas portas 1714-1764...${close}"
ufw allow 1714:1764/tcp
ufw allow 1714:1764/udp
# Habilitar o Uncomplicated Firewall (UFW) com todas as regras configuradas
echo -e "${orange}\nHabilitando o Uncomplicated Firewall (UFW) com todas as regras configuradas...${close}"
ufw --force enable
# Exibir o status do UFW após a configuração
echo -e "${red}\nStatus do UFW após a configuração:${close}"
ufw status verbose