Results 1 to 5 of 5

Thread: Saving IPTables rules

  1. #1
    Join Date
    May 2012
    Beans
    304

    Saving IPTables rules

    Hello everybody,

    Is there any bash script to save IPTables rules before rebooting a server??

    Thanks in advance

  2. #2
    Join Date
    Sep 2006
    Beans
    7,344
    Distro
    Lubuntu Development Release

    iptables-save

    Usually you could use iptables-save to save them and then iptables-restore to load them back in.

    There are some tricks that you can do to load them automatically when starting up:
    https://help.ubuntu.com/community/Ip...ion_on_startup

  3. #3
    Join Date
    May 2012
    Beans
    304

    Re: Saving IPTables rules

    perfect, I did not get this part of code:

    Code:
    if [ -f /etc/iptables.downrules ]; then
    from:

    Code:
    #!/bin/sh
    iptables-save -c > /etc/iptables.rules
    if [ -f /etc/iptables.downrules ]; then
       iptables-restore < /etc/iptables.downrules
    fi
    exit 0

  4. #4
    Join Date
    Sep 2006
    Beans
    7,344
    Distro
    Lubuntu Development Release

    Re: Saving IPTables rules

    The -f is a test to see if the file exists and is a regular file, not a directory, device, symbolic link or FIFO pipe or other.

  5. #5
    Join Date
    May 2012
    Beans
    304

    Re: Saving IPTables rules

    Oh thanks Lars Noodén, if it exists, we restore it

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •