Configurando script de inicialização no openSUSE
Publicado por Wagner Souza em 11/03/2016
[ Hits: 8.422 ]
Blog: https://medium.com/@souzaw
#!/bin/bash
#
# firewall Start iptables firewall
#
# chkconfig: 2345 08 92
# description: Starts, stops and saves iptables firewall
#
# Source function library.
. /etc/init.d/functions
iniciar(){
#------------- [ Configurações Gerais ] -------------
# Definição das configurações de rede
WAN=enp0s3
LAN=enp0s8
REDE="192.168.10.0"
MASK="255.255.255.0"
# Carregamento de módulos
modprobe ip_tables
modprobe ip_conntrack
modprobe iptable_filter
modprobe iptable_mangle
modprobe iptable_nat
modprobe ipt_LOG
modprobe ipt_limit
modprobe ipt_state
modprobe ipt_REDIRECT
modprobe ipt_owner
modprobe ipt_REJECT
modprobe ipt_MASQUERADE
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
echo "--> Carregamento de módulos [ OK ]"
# Limpa as regras
iptables -X
iptables -Z
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -F -t nat
iptables -F -t mangle
echo "--> Limpando as chains [ OK ]"
# Politicas padrão
iptables -t filter -P INPUT DROP
iptables -t filter -P OUTPUT DROP
iptables -t filter -P FORWARD DROP
echo "--> Definicao das policies [ OK ]"
# Compartilhar a internet
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE
echo "--> Compartilhamento da internet [ OK ]"
#---------------------- [ FIM ] ----------------------
#------------------- [ Liberações ] ------------------
# Liberando a conexão loopbak
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT
echo "--> Liberando a interface de loopback [ OK ]"
# Permitindo acesso SSH
iptables -t filter -A INPUT -p tcp --dport 22 -j LOG --log-level 6 --log-prefix "SSH: "
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --sport 22 -j ACCEPT
echo "--> Permitindo acesso SSH [ OK ]"
# Liberar acesso do servidor a internet
iptables -t filter -A INPUT -m multiport -p tcp --sport 80,443,53,20,21 -j ACCEPT
iptables -t filter -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A INPUT -p udp --sport 53 -j ACCEPT
iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
echo "--> Liberando a internet para o servidor [ OK ]"
# Liberar o servidor DHCP
iptables -t filter -A INPUT -m multiport -p tcp --dport 67,68 -j ACCEPT
iptables -t filter -A INPUT -m multiport -p udp --dport 67,68 -j ACCEPT
# Liberação de portas TCP para a rede local
PORTAS_LIBERADAS="20 21 25 53 80 81 110 443 465 587 995 993"
for i in $PORTAS_LIBERADAS
do
iptables -t filter -A FORWARD -s $REDE/$MASK -p tcp --dport $i -j ACCEPT
iptables -t filter -A FORWARD -d $REDE/$MASK -p tcp --sport $i -j ACCEPT
done
# Liberação de portas UDP para a rede local
PORTAS_LIBERADAS="20 21 53 587 993 465"
for i in $PORTAS_LIBERADAS
do
iptables -t filter -A FORWARD -s $REDE/$MASK -p udp --dport $i -j ACCEPT
iptables -t filter -A FORWARD -d $REDE/$MASK -p udp --sport $i -j ACCEPT
done
echo "--> Liberando portas TCP/UDP para a LAN [ OK ]"
# Liberando ICMP para o servidor e a rede local
iptables -t filter -I INPUT -p icmp --icmp-type echo-reply -j ACCEPT
iptables -t filter -I FORWARD -p icmp --icmp-type echo-reply -j ACCEPT
echo "--> Liberando o ICMP [ OK ]"
#---------------------- [ FIM ] ----------------------
#-------------- [ Regras de Proteção ] --------------
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
iptables -t filter -A INPUT -m state --state INVALID -j DROP
iptables -t filter -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
iptables -t filter -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
iptables -t filter -A FORWARD -m state -p icmp --state INVALID -j DROP
# Impedindo ataque Port Scanners na rede e no Firewall
iptables -t filter -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
iptables -t filter -I INPUT -p udp --dport 33435:33525 -j LOG --log-level info --log-prefix 'SCANNERS DROPADO>'
iptables -t filter -A INPUT -p udp --dport 33435:33525 -j DROP
iptables -t filter -I FORWARD -p udp --dport 33435:33525 -j LOG --log-level info --log-prefix 'SCANNERS DROPADO NA REDE>'
iptables -t filter -A FORWARD -p udp --dport 33435:33525 -j DROP
# Bloquear NetBus na rede
iptables -t filter -I INPUT -p tcp --dport 12345 -j LOG --log-level info --log-prefix 'NETBUS >'
iptables -t filter -A INPUT -p tcp --dport 12345 -j DROP
iptables -t filter -I INPUT -p udp --dport 12345 -j LOG --log-level info --log-prefix 'NETBUS UDP>'
iptables -t filter -A INPUT -p udp --dport 12345 -j DROP
iptables -t filter -I FORWARD -p tcp --dport 12345 -j LOG --log-level info --log-prefix 'NETBUS NA REDE>'
iptables -t filter -A FORWARD -p tcp --dport 12345 -j DROP
iptables -t filter -I FORWARD -p udp --dport 12345 -j LOG --log-level info --log-prefix 'NETBUS UDP>'
iptables -t filter -A FORWARD -p udp --dport 12345 -j DROP
echo "--> Aplicando regras de segurança [ OK ]"
#---------------------- [ FIM ] ----------------------
}
parar(){
iptables -F
iptables -t nat -F
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
echo 0 > /proc/sys/net/ipv4/ip_forward
echo "Regras de firewall e compartilhamento desativados"
}
case "$1" in
"start") iniciar ;;
"stop") parar ;;
"restart") parar; iniciar ;;
*) echo "Use os parâtros start ou stop"
esac
Trabalhando com referências de células no LibreOffice
Reduzindo tempo de boot via otimização do SystemD
Iptables e proxy transparente (Squid) definitivo
Como adicionar placa de rede em servidor CentOS 6x
Como instalar Webmin no Debian/Ubuntu e derivados
IA Turbina o Desktop Linux enquanto distros renovam forças
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Linux em 2025: Segurança prática para o usuário
Desktop Linux em alta: novos apps, distros e privacidade marcam o sábado
IA chega ao desktop e impulsiona produtividade no mundo Linux
Atualizando o Fedora 42 para 43
Como saber se o seu e-mail já teve a senha vazada?
Como descobrir se a sua senha já foi vazada na internet?
Programa fora de escala na tela do pc (33)
Eu queria adicionar a incon do wifi e deixa transparente no fluxbox no... (0)









