Nieuws:

Welkom, Gast. Alsjeblieft inloggen of registreren.
Heb je de activerings-mail niet ontvangen?

Auteur Topic: hulp nodig bij uitvoeren iptables script  (gelezen 1209 keer)

Offline Soul-Sing

  • Lid
hulp nodig bij uitvoeren iptables script
« Gepost op: 2012/10/19, 13:07:27 »
gaat het uitvoeren via:
sudo chmod 755 iptables.shsudo ./iptables.shis dit correct?
na reboot actief laten blijven via:
sudo nano /etc/network/interfacespre-up iptables-restore < /etc/iptables.rules  (toevoegen)

het script:

#!/bin/bash
#Simple Firewall Script.


#Setting up default kernel tunings here (don't worry too much about these right now, they are acceptable defaults)
#DROP ICMP echo-requests sent to broadcast/multi-cast addresses.
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
#DROP source routed packets
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
#Enable TCP SYN cookies
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
#Do not ACCEPT ICMP redirect
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
#Don't send ICMP redirect
echo 0 >/proc/sys/net/ipv4/conf/all/send_redirects
#Enable source spoofing protection
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
#Log impossible (martian) packets
echo 1 > /proc/sys/net/ipv4/conf/all/log_martians

#Flush all existing chains
iptables --flush

#Allow traffic on loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT


#Creating default policies
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP #If we're not a router

#Allow previously established connections to continue uninterupted
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

#Allow outbound connections on the ports we previously decided.
iptables -A OUTPUT -p tcp --dport 25 -j ACCEPT #SMTP
iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT #DNS
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT #HTTP
iptables -A OUTPUT -p tcp --dport 110 -j ACCEPT #POP
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 465 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 843 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 993 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 995 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 1023 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 1863 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 4001 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 5222 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 6667 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 7000 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 7070 -j ACCEPT #HTTPS
iptables -A OUTPUT -p tcp --dport 11371 -j ACCEPT #HTTPS
iptables -A OUTPUT -p UDP --dport 67:68 -j ACCEPT #DHCP
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT #DNS
iptables -A OUTPUT -p udp --dport 123 -j ACCEPT #DNS
iptables -A OUTPUT -p udp --dport 1023 -j ACCEPT #DNS
iptables -A OUTPUT -p udp --dport 11371 -j ACCEPT #DNS


#Set up logging for incoming traffic.
iptables -N LOGNDROP
iptables -A INPUT -j LOGNDROP
iptables -A LOGNDROP -j LOG
iptables -A LOGNDROP -j DROP

#Save our firewall rules
iptables-save > /etc/iptables.rules

Re: hulp nodig bij uitvoeren iptables script
« Reactie #1 Gepost op: 2012/11/02, 23:25:23 »
Was je hier nog verder mee gekomen? Volgens mij gaat dat uitvoeren goed. Alleen kun je dan waarschijnlijk niet meer bij deze machine omdat er geen INPUT rules zijn en de default policy voor INPUT drop is.

Offline Ron

  • Forumteam
    • r0n
    • Over Tholen
Re: hulp nodig bij uitvoeren iptables script
« Reactie #2 Gepost op: 2012/11/03, 10:38:44 »
Die "sudo" kan je m.i. beter in het script zetten, dat scheelt je 5 tekens intypen.
Verder, wanneer je de file in de map /home/<naam>/bin zet, dan wordt de map bij het opstarten in het path opgenomen.
Het volstaat dan op alleen de naam van het script in te typen, laat dan ook ".sh" weg, lekker makkelijk .......
Openstandaard Evangelist, OpenSource Promotor, OpenData voorstander.
Xubuntu gebruiker en voorstander
Er is ook nog een andere hobby.

Re: hulp nodig bij uitvoeren iptables script
« Reactie #3 Gepost op: 2012/11/03, 16:52:48 »
Om het script na het herstarten actief te laten zijn zou ik ervoor kiezen om gebruik te maken van upstart, of sys V init.
Ubuntu maakt gebruik van Upstart, maar is compatibel met sys V init. sys V is als het ware een upstart job.

Voor upstart zie: http://upstart.ubuntu.com/getting-started.html

en

http://upstart.ubuntu.com/cookbook/

Je zou als inspiratie volgens mij goed gebruik kunnen maken van /etc/init/ufw.conf, en daar je eigen baksel van maken.

Gebruik maken van sys V init is wellicht makkelijker, je kan gewoon je script in /etc/init.d plaatsen, uitvoerbaar maken, en dan toevoegen met het update-rc.d commando.

Zie voor update-rc.d bijvoorbeeld: http://www.debuntu.org/how-to-manage-services-with-update-rc.d
« Laatst bewerkt op: 2012/11/03, 16:55:07 door Thomas de Graaff »

Re: hulp nodig bij uitvoeren iptables script
« Reactie #4 Gepost op: 2012/11/03, 18:26:36 »
Als je de regels schrijft naar /etc/iptables.rules (zoals je doet) wordt dat al automatisch geladen tijdens het opstarten. Het is dus niet nodig om zelf nog met init-scripts te gaan klooien.
I use a Unix-based system, that means I'll get laid as often as I have to reboot.
LibSylph
SeySayux.net

Re: hulp nodig bij uitvoeren iptables script
« Reactie #5 Gepost op: 2012/11/03, 18:31:24 »
A, dat is idd. veel handiger. Ik had het script zelf niet echt bekeken. :D Ik wist ook niet dat dat /etc/iptables.rules automatisch wort geladen.
« Laatst bewerkt op: 2012/11/03, 18:33:44 door Thomas de Graaff »