Advertisement
sergio_educacionit

firewall-gateway

Nov 15th, 2023
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.59 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. func_erase () {
  5.  
  6.     # Politicas por defecto
  7.     /usr/sbin/iptables -P INPUT ACCEPT
  8.     /usr/sbin/iptables -P FORWARD ACCEPT
  9.     /usr/sbin/iptables -P OUTPUT ACCEPT
  10.  
  11.     # Flusheo de reglas y tablas
  12.     /usr/sbin/iptables -t nat -F
  13.     /usr/sbin/iptables -F
  14.     /usr/sbin/iptables -X
  15.  
  16.     # Mostar como queda el firewall
  17.     /usr/sbin/iptables -L
  18. }
  19.  
  20.  
  21. func_apply (){
  22.  
  23.     # Configuracion NAT
  24.     /usr/sbin/iptables -A FORWARD -i enp0s8 -o enp0s3 -j ACCEPT
  25.     /usr/sbin/iptables -A FORWARD -i enp0s3 -o enp0s8 -m state --state ESTABLISHED,RELATED -j ACCEPT
  26.     /usr/sbin/iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE
  27.  
  28.     # Reenvio de puertos ssh al host 190.0.0.4
  29.     /usr/sbin/iptables -t nat -A PREROUTING -i enp0s3 -p tcp --dport 2022 -j DNAT --to-destination 190.0.0.4:22
  30.     /usr/sbin/iptables -A FORWARD -i enp0s3 -o enp0s8 -p tcp --dport 2022 -j ACCEPT
  31.  
  32.     # Reenvio de puertos ssh al host 190.0.0.15
  33.     /usr/sbin/iptables -t nat -A PREROUTING -i enp0s3 -p tcp --dport 3022 -j DNAT --to-destination 190.0.0.15:22
  34.     /usr/sbin/iptables -A FORWARD -i enp0s3 -o enp0s8 -p tcp --dport 3022 -j ACCEPT
  35.  
  36.     # Reenvio de puertos http al host 190.0.0.4
  37.    
  38.     /usr/sbin/iptables -t nat -A PREROUTING -i enp0s3 -p tcp --dport 80 -j DNAT --to-destination 190.0.0.4:80
  39.     /usr/sbin/iptables -A FORWARD -i enp0s3 -o enp0s8 -p tcp --dport 80 -j ACCEPT
  40.  
  41.     # Mostrar estado actual
  42.     /usr/sbin/iptables -L
  43.  
  44. }
  45.  
  46.  
  47.  
  48. argumento=$1
  49.  
  50. case $argumento in
  51.  
  52.     "erase")
  53.         func_erase
  54.         ;;
  55.     "apply")
  56.         func_apply
  57.         ;;
  58.     "export")
  59.         /usr/sbin/iptables-save
  60.         ;;
  61.  
  62.     *)
  63.         echo -e "\nModo de uso:\n\t$0 erase|apply|export\n"
  64.         ;;
  65.  
  66. esac
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement