Results 1 to 5 of 5

Thread: Ubuntu Linux /etc/init.d/iptables start|stop|restart script

  1. #1
    Member valerio's Avatar
    Join Date
    Oct 2010
    Location
    Varese
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Ubuntu Linux /etc/init.d/iptables start|stop|restart script

    Is it possible make a service with start|stop|restart like apache or ssh?
    Sorry i mean that i have my script start.fw and i want include it into the service like /etc/init.d/iptables
    Thanks
    Last edited by valerio; 20th October 2010 at 09:53 PM.

  2. #2
    Is that all you got? rockdalinux's Avatar
    Join Date
    May 2005
    Location
    Planet Vegeta
    Posts
    987
    Thanks
    27
    Thanked 71 Times in 62 Posts
    Rep Power
    20

    Default

    Why scripts? You need to use ufw - https://help.ubuntu.com/community/UFW
    Rocky Jr.
    What's wrong? I hope I am not making you uncomfortable...

    Never send a boy to do a mans job.

  3. #3
    Member valerio's Avatar
    Join Date
    Oct 2010
    Location
    Varese
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    ok i will lunch manualy my iptables.
    Thanks

  4. #4
    Is that all you got? rockdalinux's Avatar
    Join Date
    May 2005
    Location
    Planet Vegeta
    Posts
    987
    Thanks
    27
    Thanked 71 Times in 62 Posts
    Rep Power
    20

    Default

    Code:
    #!/bin/bash
    IPT=/sbin/iptables
    IPT6=/sbin/ip6tables
    IPTR=/sbin/iptables-restore
    IPTCONFIG=/root/.config/fw/firewall.conf
    PROG=iptables
    
    _stop(){
    	### reset ipv4 iptales ###
    	        echo "Stopping iptables..."	
                    $IPT -F
                    $IPT -X
                    $IPT -Z
                    for table in $(</proc/net/ip_tables_names)
                    do
                            $IPT -t $table -F
                            $IPT -t $table -X
                            $IPT -t $table -Z
                    done
                    $IPT -P INPUT ACCEPT
                    $IPT -P OUTPUT ACCEPT
                    $IPT -P FORWARD ACCEPT
                    ### reset ipv6 iptales ###
                    $IPT6 -F
                    $IPT6 -X
                    $IPT6 -Z
                    for table in $(</proc/net/ip6_tables_names)
                    do
                            $IPT6 -t $table -F
                            $IPT6 -t $table -X
                            $IPT6 -t $table -Z
                    done
                    $IPT6 -P INPUT ACCEPT
                    $IPT6 -P OUTPUT ACCEPT
                    $IPT6 -P FORWARD ACCEPT
    
    }
    
    _start(){
        ### add your commands here ###
    	        echo "Starting iptables..."
        		$IPTR < "$IPTCONFIG"
    }
    
    
    # See how we were called.
    case "$1" in
      start)
            _start
            ;;
      stop)
            _stop
            ;;
      restart)
            _stop
            _start
            ;;
      *)
            echo $"Usage: $PROG {start|stop|restart}"
            exit 1
    esac
    Based on /etc/init.d/iptables source from RHEL. Try it and let me know. Save your existing firewall rules to /root/.config/fw/firewall.conf
    Code:
    mkdir -p /root/.config/fw/
    iptables-save > /root/.config/fw/firewall.conf
    Last edited by rockdalinux; 20th October 2010 at 10:32 PM.
    Rocky Jr.
    What's wrong? I hope I am not making you uncomfortable...

    Never send a boy to do a mans job.

  5. #5
    Member valerio's Avatar
    Join Date
    Oct 2010
    Location
    Varese
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Wow beautiful.
    Seems functional
    Thank you a lot......

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. /etc/init.d/network restart New ip Address Adding
    By aeboi80 in forum Linux software
    Replies: 2
    Last Post: 7th May 2010, 01:45 PM
  2. Replies: 9
    Last Post: 19th March 2010, 05:08 PM
  3. start up and stop the running script
    By mala_un in forum Shell scripting
    Replies: 9
    Last Post: 26th July 2006, 07:10 AM
  4. ubuntu linux start, stop, restart networking
    By toor in forum Linux software
    Replies: 3
    Last Post: 17th July 2006, 11:32 AM
  5. typing init 5 to start x-windows
    By in forum Linux software
    Replies: 1
    Last Post: 9th January 2006, 09:56 PM

Tags for this Thread

Posting Permissions

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