Note, that this recipe is not updated long time and could be outdated!
Got it.

Iptables inicializācijas skripts

Ubuntu distributīvos, uzstādot Iptables pakešu filtrēšanas pārvaldības lietotne, netiek izveidots inicializācijas skripts. Tāpēc šo failu nepieciešams izveidot un tā izsaukšanu nokonfigurēt manuāli.
  1. Izveido init skriptu:

    sudo touch /etc/init.d/iptables
    sudo chmod 755 /etc/init.d/iptables
  2. Izpilda komandu 

    sudo gedit /etc/init.d/iptables
  3. Failā ieliek tajā sekojošu saturu:

    # see:
    #This is a ubuntu adapted iptables script from gentoo
    #( which was originally distributed
    # under the terms of the GNU General Public License v2
    #and was Copyrighted 1999-2004 by the Gentoo Foundation
    #This adapted version was intended for and ad-hoc personal
    #situation and as such no warranty is provided.


    checkrules() {
      if [[ ! -f $>{IPTABLES_SAVE} ]]
        echo "Not starting iptables. First create some rules then run"
        echo ""/etc/init.d/iptables save""
        return 1

    save() {
      echo "Saving iptables state"
      /sbin/iptables-save ${SAVE_RESTORE_OPTIONS} > ${IPTABLES_SAVE}

      checkrules || return 1
        echo  "Loading iptables state and starting firewall"
        echo -n "Restoring iptables ruleset"
        # Enable forwarding (if necessary)
        echo 1 >/proc/sys/net/ipv4/ip_forward
        start-stop-daemon --start --quiet --exec /sbin/iptables-restore — ${SAVE_RESTORE_OPTIONS} < ${IPTABLES_SAVE}

    case "$1" in
            echo "."

      echo "."
        if [[ "$>{SAVE_ON_STOP}" = "yes" ]]; then
          save || exit 1
        echo -n "Stopping firewall"
        for a in `cat /proc/net/ip_tables_names`; do
          /sbin/iptables -F -t $a
          /sbin/iptables -X -t $a

          if [[ $a == nat ]]; the>n
            /sbin/iptables -t nat -P PREROUTING ACCEPT
            /sbin/iptables -t nat -P POSTROUTING ACCEPT
            /sbin/iptables -t nat -P OUTPUT ACCEPT
          elif [[ $a == mangle ]]; the>n
            /sbin/iptables -t mangle -P PREROUTING ACCEPT
            /sbin/iptables -t mangle -P INPUT ACCEPT
            /sbin/iptables -t mangle -P FORWARD ACCEPT
            /sbin/iptables -t mangle -P OUTPUT ACCEPT
            /sbin/iptables -t mangle -P POSTROUTING ACCEPT
          elif [[ $a == filter ]]; the>n
            /sbin/iptables -t filter -P INPUT ACCEPT
            /sbin/iptables -t filter -P FORWARD ACCEPT
            /sbin/iptables -t filter -P OUTPUT ACCEPT
        start-stop-daemon --stop --quiet --pidfile /var/run/ --exec /sbin/iptables
        echo "."

        echo -n "Flushing firewall"
          for a in `cat /proc/net/ip_tables_names`; do
            /sbin/iptables -F -t $a
              /sbin/iptables -X -t $a
        echo "."
        echo "Usage: /etc/init.d/iptables {start|stop|restart|save}" >&2
        exit 1

    exit 0
  4. Pievieno init skripta izsaukumu:

    sudo update-rc.d iptables start 37 S . stop 37 0 .
  5. Saglabā tekošos iestatījumus:

    /etc/init.d/iptables save
  6. Pārstartē iptables:

    /etc/init.d/iptables restart

Created by Valdis Vītoliņš on 2008-08-09 13:31
Last modified by Valdis Vītoliņš on 2013-09-09 13:48
Xwiki Powered
Creative Commons Attribution 3.0 Unported License