gnu_linux_server:network_configuration:firewall
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| gnu_linux_server:network_configuration:firewall [2011/11/22 22:57] – Typo guillaume | gnu_linux_server:network_configuration:firewall [2021/01/04 20:41] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 12: | Line 12: | ||
| <code bash> | <code bash> | ||
| deny_everything() { | deny_everything() { | ||
| - | | + | |
| iptables -t filter -P INPUT DROP | iptables -t filter -P INPUT DROP | ||
| Line 18: | Line 18: | ||
| iptables -t filter -P OUTPUT | iptables -t filter -P OUTPUT | ||
| - | | + | |
| } | } | ||
| </ | </ | ||
| Line 25: | Line 25: | ||
| <code bash> | <code bash> | ||
| cleanup_tables() { | cleanup_tables() { | ||
| - | | + | |
| iptables -t filter -F | iptables -t filter -F | ||
| iptables -t filter -X | iptables -t filter -X | ||
| - | | + | |
| } | } | ||
| </ | </ | ||
| Line 37: | Line 37: | ||
| <code bash> | <code bash> | ||
| dont_break_connections() { | dont_break_connections() { | ||
| - | | + | |
| iptables -A INPUT -m state --state RELATED, | iptables -A INPUT -m state --state RELATED, | ||
| iptables -A OUTPUT -m state --state RELATED, | iptables -A OUTPUT -m state --state RELATED, | ||
| - | | + | |
| } | } | ||
| </ | </ | ||
| Line 49: | Line 49: | ||
| <code bash> | <code bash> | ||
| allow_loopback() { | allow_loopback() { | ||
| - | | + | |
| iptables -t filter -A INPUT -i lo -j ACCEPT | iptables -t filter -A INPUT -i lo -j ACCEPT | ||
| iptables -t filter -A OUTPUT -o lo -j ACCEPT | iptables -t filter -A OUTPUT -o lo -j ACCEPT | ||
| - | | + | |
| } | } | ||
| </ | </ | ||
| Line 66: | Line 66: | ||
| Maintenant vous devriez pouvoir comprendre ce script. Il utilise des fonctions pour configurer **iptables**. | Maintenant vous devriez pouvoir comprendre ce script. Il utilise des fonctions pour configurer **iptables**. | ||
| <code bash> | <code bash> | ||
| + | ### BEGIN INIT INFO | ||
| + | # Provides: | ||
| + | # Required-Start: | ||
| + | # Required-Stop: | ||
| + | # Default-Start: | ||
| + | # Default-Stop: | ||
| + | # Short-Description: | ||
| + | # Description: | ||
| + | ### END INIT INFO | ||
| + | |||
| #!/bin/bash | #!/bin/bash | ||
| . / | . / | ||
| + | |||
| + | # In debug mode there will be more outputs | ||
| + | # 0 to disable | ||
| + | # 1 to enable | ||
| + | DEBUG=0 | ||
| + | |||
| + | # Print message only in debug mode | ||
| + | # Usage: print_debug ${message} ${return_code} | ||
| + | # ${return_code} is optional | ||
| + | print_debug() { | ||
| + | [ ${DEBUG} -eq 0 ] && return 0 | ||
| + | [ $# -ne 1 ] && | ||
| + | |||
| + | log_action_begin_msg ${1} | ||
| + | } | ||
| + | |||
| + | end_debug() { | ||
| + | [ ${DEBUG} -eq 0 ] && return 0 | ||
| + | [ $# -ne 1 ] && | ||
| + | |||
| + | log_action_end_msg ${1} | ||
| + | } | ||
| deny_everything() { | deny_everything() { | ||
| - | | + | |
| iptables -t filter -P INPUT DROP | iptables -t filter -P INPUT DROP | ||
| Line 77: | Line 109: | ||
| iptables -t filter -P OUTPUT | iptables -t filter -P OUTPUT | ||
| - | | + | |
| } | } | ||
| accept_everything() { | accept_everything() { | ||
| - | log_action_begin_msg | + | print_debug |
| - | | + | |
| - | iptables -t filter -P FORWARD ACCEPT | + | iptables -t filter -P FORWARD ACCEPT |
| - | iptables -t filter -P OUTPUT | + | iptables -t filter -P OUTPUT |
| - | log_action_end_msg | + | end_debug |
| } | } | ||
| - | |||
| cleanup_tables() { | cleanup_tables() { | ||
| - | | + | |
| iptables -t filter -F | iptables -t filter -F | ||
| iptables -t filter -X | iptables -t filter -X | ||
| - | | + | |
| } | } | ||
| dont_break_connections() { | dont_break_connections() { | ||
| - | | + | |
| iptables -A INPUT -m state --state RELATED, | iptables -A INPUT -m state --state RELATED, | ||
| iptables -A OUTPUT -m state --state RELATED, | iptables -A OUTPUT -m state --state RELATED, | ||
| - | | + | |
| } | } | ||
| allow_loopback() { | allow_loopback() { | ||
| - | | + | |
| iptables -t filter -A INPUT -i lo -j ACCEPT | iptables -t filter -A INPUT -i lo -j ACCEPT | ||
| iptables -t filter -A OUTPUT -o lo -j ACCEPT | iptables -t filter -A OUTPUT -o lo -j ACCEPT | ||
| - | | + | |
| } | } | ||
| deny_spoofing() { | deny_spoofing() { | ||
| - | | + | |
| iptables -N SPOOFED | iptables -N SPOOFED | ||
| Line 128: | Line 159: | ||
| iptables -A SPOOFED -s 10.0.0.0/ | iptables -A SPOOFED -s 10.0.0.0/ | ||
| - | | + | |
| + | } | ||
| + | |||
| + | misc_config() { | ||
| + | print_debug "Misc configurations" | ||
| + | |||
| + | echo 1 > / | ||
| + | echo 0 > / | ||
| + | echo 1 > / | ||
| + | echo 1 >/ | ||
| + | echo 1 > / | ||
| + | echo 1 > / | ||
| + | echo 1 > / | ||
| + | echo 0 > / | ||
| + | echo 0 > / | ||
| + | |||
| + | end_debug | ||
| } | } | ||
| open_input_port() { | open_input_port() { | ||
| - | | + | [ $# -ne 2 ] && |
| - | | + | |
| - | fi | + | |
| - | | + | |
| iptables -t filter -A INPUT -p " | iptables -t filter -A INPUT -p " | ||
| - | | + | |
| } | } | ||
| open_output_port() { | open_output_port() { | ||
| - | | + | [ $# -ne 2 ] && |
| - | | + | |
| - | fi | + | |
| - | | + | |
| iptables -t filter -A OUTPUT -p " | iptables -t filter -A OUTPUT -p " | ||
| - | | + | |
| } | } | ||
| allow_input_protocol() { | allow_input_protocol() { | ||
| - | | + | [ $# -ne 1 ] && |
| - | | + | |
| - | fi | + | |
| - | | + | |
| iptables -t filter -A INPUT -p " | iptables -t filter -A INPUT -p " | ||
| - | | + | |
| } | } | ||
| allow_output_protocol() { | allow_output_protocol() { | ||
| - | | + | [ $# -ne 1 ] && |
| - | | + | |
| - | fi | + | |
| - | | + | |
| iptables -t filter -A OUTPUT -p " | iptables -t filter -A OUTPUT -p " | ||
| - | | + | |
| } | } | ||
| allow_6in4_protocol() { | allow_6in4_protocol() { | ||
| - | | + | [ $# -ne 1 ] && |
| - | | + | |
| - | fi | + | |
| - | | + | |
| iptables -t filter -A INPUT -s ${1} -p 41 -j ACCEPT | iptables -t filter -A INPUT -s ${1} -p 41 -j ACCEPT | ||
| iptables -t filter -A OUTPUT -p 41 -j ACCEPT | iptables -t filter -A OUTPUT -p 41 -j ACCEPT | ||
| - | | + | |
| } | } | ||
| Line 196: | Line 233: | ||
| # Stop fail to ban before configuring firewall | # Stop fail to ban before configuring firewall | ||
| / | / | ||
| - | | + | |
| deny_everything | deny_everything | ||
| Line 249: | Line 286: | ||
| open_output_port tcp 64738 | open_output_port tcp 64738 | ||
| open_output_port udp 64738 | open_output_port udp 64738 | ||
| - | | + | |
| # Bazaar | # Bazaar | ||
| open_input_port | open_input_port | ||
| Line 301: | Line 338: | ||
| deny_spoofing | deny_spoofing | ||
| + | misc_config | ||
| # Starting fail2ban again | # Starting fail2ban again | ||
| / | / | ||
| - | | + | |
| - | exit 0 | + | |
| ;; | ;; | ||
| stop) | stop) | ||
| - | | + | |
| accept_everything | accept_everything | ||
| cleanup_tables | cleanup_tables | ||
| - | | + | |
| - | exit 0 | + | |
| ;; | ;; | ||
| Line 322: | Line 358: | ||
| exit 1 | exit 1 | ||
| ;; | ;; | ||
| + | esac | ||
| + | |||
| + | exit 0 | ||
| </ | </ | ||
gnu_linux_server/network_configuration/firewall.1322002648.txt.gz · Last modified: 2021/01/04 20:40 (external edit)
