3 # Startup script to implement /etc/sysconfig/ip6tables pre-defined rules.
5 # chkconfig: 2345 08 92
7 # description: Automates a packet filtering firewall with ip6tables.
9 # by bero@redhat.com, based on the ipchains script:
10 # Script Author: Joshua Jensen <joshua@redhat.com>
11 # -- hacked up by gafton with help from notting
12 # modified by Anton Altaparmakov <aia21@cam.ac.uk>:
13 # modified by Nils Philippsen <nils@redhat.de>
15 # config: /etc/sysconfig/ip6tables
17 IPTABLES_CONFIG=/etc/sysconfig/ip6tables
18 if [ ! -f $IPTABLES_CONFIG ]; then
20 start|restart|force-reload)
27 . /etc/rc.d/init.d/functions
29 if [ "$(kernelver)" -lt "002003000" ]; then
33 if /sbin/lsmod 2>/dev/null | grep -q ipchains; then
38 IP6TABLES_SAVE_ON_STOP="no"
39 IP6TABLES_SAVE_COUNTER="no"
40 IP6TABLES_STATUS_NUMERIC="yes"
41 IP6TABLES_STATUS_VERBOSE="no"
42 IP6TABLES_STATUS_LINENUMBERS="yes"
43 [ -f /etc/sysconfig/ip6tables-config ] && . /etc/sysconfig/ip6tables-config
45 is_yes $IP6TABLES_SAVE_COUNTER && _SAVEOPT="-c"
47 if [ "$1" = "--quiet" ]; then
55 if fgrep -qsx $1 /proc/net/ip6_tables_names; then
61 # don't do squat if we don't have the config file
62 if [ -f $IPTABLES_CONFIG ]; then
63 # If we don't clear these first, we might be adding to
65 tables=`cat /proc/net/ip6_tables_names 2>/dev/null`
66 show "Flushing all current rules and user defined chains"
68 for i in $tables; do ip6tables -t $i -F; let ret+=$?; done
69 if [ $ret -eq 0 ]; then
74 show "Clearing all current rules and user defined chains"
76 for i in $tables; do ip6tables -t $i -X; let ret+=$?; done
77 if [ $ret -eq 0 ]; then
83 for i in $tables; do ip6tables -t $i -Z; done
85 show "Applying ip6tables firewall rules"
86 grep -v "^[[:space:]]*#" $IPTABLES_CONFIG | grep -v '^[[:space:]]*$' | /usr/sbin/ip6tables-restore $_SAVEOPT && \
88 touch /var/lock/subsys/ip6tables
93 tables=`cat /proc/net/ip6_tables_names 2>/dev/null`
94 show "Flushing all chains"
96 for i in $tables; do ip6tables -t $i -F; let ret+=$?; done
97 if [ $ret -eq 0 ]; then
103 show "Removing user defined chains"
105 for i in $tables; do ip6tables -t $i -X; let ret+=$?; done
106 if [ $ret -eq 0 ]; then
111 show "Resetting built-in chains to the default ACCEPT policy"
112 iftable filter -P INPUT ACCEPT && \
113 iftable filter -P OUTPUT ACCEPT && \
114 iftable filter -P FORWARD ACCEPT && \
115 iftable nat -P PREROUTING ACCEPT && \
116 iftable nat -P POSTROUTING ACCEPT && \
117 iftable nat -P OUTPUT ACCEPT && \
118 iftable mangle -P PREROUTING ACCEPT && \
119 iftable mangle -P OUTPUT ACCEPT && \
121 rm -f /var/lock/subsys/ip6tables
125 show "Saving current rules to %s" $IPTABLES_CONFIG
126 touch $IPTABLES_CONFIG
127 chmod 600 $IPTABLES_CONFIG
128 /usr/sbin/ip6tables-save $_SAVEOPT > $IPTABLES_CONFIG 2>/dev/null && ok || fail
131 upstart_controlled --except status panic load save clear
138 is_yes $IP6TABLES_SAVE_ON_STOP && save
144 restart|force-reload)
145 # "restart" is really just "start" as this isn't a daemon,
146 # and "start" clears any pre-defined rules anyway.
147 # This is really only here to make those who expect it happy
151 show "Changing target policies to DROP"
152 iftable filter -P INPUT DROP && \
153 iftable filter -P FORWARD DROP && \
154 iftable filter -P OUTPUT DROP && \
155 iftable nat -P PREROUTING DROP && \
156 iftable nat -P POSTROUTING DROP && \
157 iftable nat -P OUTPUT DROP && \
158 iftable mangle -P PREROUTING DROP && \
159 iftable mangle -P OUTPUT DROP && \
161 iftable filter -F INPUT && \
162 iftable filter -F FORWARD && \
163 iftable filter -F OUTPUT && \
164 iftable nat -F PREROUTING && \
165 iftable nat -F POSTROUTING && \
166 iftable nat -F OUTPUT && \
167 iftable mangle -F PREROUTING && \
168 iftable mangle -F OUTPUT && \
170 iftable filter -X INPUT && \
171 iftable filter -X FORWARD && \
172 iftable filter -X OUTPUT && \
173 iftable nat -X PREROUTING && \
174 iftable nat -X POSTROUTING && \
175 iftable nat -X OUTPUT && \
176 iftable mangle -X PREROUTING && \
177 iftable mangle -X OUTPUT && \
184 is_yes $IP6TABLES_STATUS_NUMERIC && _NUMERIC="-n"
185 is_yes $IP6TABLES_STATUS_VERBOSE && _VERBOSE="--verbose"
186 is_yes $IP6TABLES_STATUS_LINENUMBERS && _LINES="--line-numbers"
187 tables=`cat /proc/net/ip6_tables_names 2>/dev/null`
188 for table in $tables; do
190 ip6tables -t $table --list $_NUMERIC $_VERBOSE $_LINES
194 msg_usage "$0 {start|stop|restart|force-reload|panic|load|save|clear|status}"