Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2014
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.58 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Simple Firewall configuration.
  4. #
  5. # Author: eXorus
  6. #
  7. # chkconfig: 2345 9 91
  8. # description: Activates/Deactivates the firewall at boot time
  9. #
  10. ### BEGIN INIT INFO
  11. # Provides:          firewall.sh
  12. # Required-Start:    $syslog $network
  13. # Required-Stop:     $syslog $network
  14. # Default-Start:     2 3 4 5
  15. # Default-Stop:      0 1 6
  16. # Short-Description: Start firewall daemon at boot time
  17. # Description:       Custom Firewall script
  18. ### END INIT INFO
  19.  
  20. ##########################
  21. # Configuration
  22. ##########################
  23.  
  24. SSH_PORT="xxxx"
  25. FTP_PORT="21"
  26. DNS_PORT="53"
  27. MAIL_PORT="25"
  28. NTP_PORT="123"
  29. HTTP_PORT="80"
  30. HTTPS_PORT="443"
  31.  
  32. HN_IP="xx.xx.xx.xx"
  33.  
  34.  
  35. ##########################
  36. # Start the Firewall rules
  37. ##########################
  38.  
  39. fw_start(){
  40.         # Ne pas casser les connexions etablies
  41.         iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  42.         iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  43.  
  44.         # Autoriser loopback
  45.         iptables -t filter      -A INPUT        -i lo -s 127.0.0.0/8 -d 127.0.0.0/8 -j ACCEPT
  46.         iptables -t filter      -A OUTPUT       -o lo -s 127.0.0.0/8 -d 127.0.0.0/8 -j ACCEPT
  47.  
  48.         # Autoriser le ping
  49.         iptables -t filter      -A INPUT        -p icmp -j ACCEPT
  50.         iptables -t filter      -A OUTPUT       -p icmp -j ACCEPT
  51.  
  52.         # Autoriser SSH
  53.         iptables -t filter      -A INPUT        -p tcp --dport $SSH_PORT -j ACCEPT
  54.         iptables -t filter      -A OUTPUT       -p tcp --dport $SSH_PORT -j ACCEPT
  55.  
  56.         # Autoriser NTP
  57.         iptables -t filter      -A OUTPUT       -p udp --dport $NTP_PORT -j ACCEPT
  58.  
  59.         # Autoriser DNS
  60.         iptables -t filter -A OUTPUT -p tcp --dport $DNS_PORT -j ACCEPT
  61.         iptables -t filter -A OUTPUT -p udp --dport $DNS_PORT -j ACCEPT
  62.         iptables -t filter -A INPUT -p tcp --dport $DNS_PORT -j ACCEPT
  63.         iptables -t filter -A INPUT -p udp --dport $DNS_PORT -j ACCEPT
  64.  
  65.         # Autoriser HTTP et HTTPS
  66.         iptables -t filter -A OUTPUT -p tcp --dport $HTTP_PORT -j ACCEPT
  67.         iptables -t filter -A INPUT -p tcp --dport $HTTP_PORT -j ACCEPT
  68.         iptables -t filter -A OUTPUT -p tcp --dport $HTTPS_PORT -j ACCEPT
  69.         iptables -t filter -A INPUT -p tcp --dport $HTTPS_PORT -j ACCEPT
  70.  
  71. }
  72.  
  73. fw_stop(){
  74.         # Vidage des tables et des regles personnelles
  75.         iptables -t filter      -F
  76.         iptables -t nat         -F
  77.         iptables -t mangle      -F
  78.         iptables -t filter      -X
  79.  
  80.         # Interdire toutes connexions entrantes et sortantes
  81.         iptables -t filter      -P INPUT DROP
  82.         iptables -t filter      -P FORWARD DROP
  83.         iptables -t filter      -P OUTPUT DROP
  84. }
  85. fw_clear(){
  86.         # Vidage des tables et des regles personnelles
  87.         iptables -t filter      -F
  88.         iptables -t nat         -F
  89.         iptables -t mangle      -F
  90.         iptables -t filter      -X
  91.  
  92.         # Accepter toutes connexions entrantes et sortantes
  93.         iptables -t filter      -P INPUT ACCEPT
  94.         iptables -t filter      -P FORWARD ACCEPT
  95.         iptables -t filter      -P OUTPUT ACCEPT
  96. }
  97.  
  98. fw_stop_ip6(){
  99.         # Vidage des tables et des regles personnelles
  100.         ip6tables -t filter     -F
  101.         ip6tables -t mangle     -F
  102.         ip6tables -t filter     -X
  103.  
  104.                 # Interdire toutes connexions entrantes et sortantes
  105.         ip6tables -t filter     -P INPUT DROP
  106.         ip6tables -t filter     -P FORWARD DROP
  107.         ip6tables -t filter     -P OUTPUT DROP
  108. }
  109.  
  110. fw_clear_ip6(){
  111.         # Vidage des tables et des regles personnelles
  112.         ip6tables -t filter      -F
  113.         ip6tables -t mangle      -F
  114.         ip6tables -t filter      -X
  115.  
  116.         # Accepter toutes connexions entrantes et sortantes
  117.         ip6tables -t filter      -P INPUT ACCEPT
  118.         ip6tables -t filter      -P FORWARD ACCEPT
  119.         ip6tables -t filter      -P OUTPUT ACCEPT
  120. }
  121.  
  122. case "$1" in
  123.         start|restart)
  124.                 echo -n "Starting firewall.."
  125.                 fw_stop_ip6
  126.                 fw_stop
  127.                 fw_start
  128.                 echo "done."
  129.                 ;;
  130.         stop)
  131.                 echo -n "Stopping firewall.."
  132.                 fw_stop_ip6
  133.                 fw_stop
  134.                 echo "done."
  135.                 ;;
  136.         clear)
  137.                 echo -n "Clearing firewall rules.."
  138.                 fw_clear_ip6
  139.                 fw_clear
  140.                 echo "done."
  141.                 ;;
  142.         *)
  143.                 echo "Usage: $0 {start|stop|restart|clear}"
  144.                 exit 1
  145.                 ;;
  146. esac
  147.  
  148. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement