Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/bin/sh
#Change the part after the = to the where you IPTABLES is on your system
IPTABLES=/sbin/iptables
case "$1" in
start|reload|restart)
#flush existing rules
${IPTABLES} -F INPUT
#This allows all data that has been sent out to get reply's back.
${IPTABLES} -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p icmp
${IPTABLES} -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p tcp
${IPTABLES} -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p udp
#Allow incoming SSH requests
${IPTABLES} -A INPUT -p tcp --dport ssh -j ACCEPT
#Allow incoming NTP - Disabled because I'm not running a time server:)
#${IPTABLES} -A INPUT -p udp --dport ntp -j ACCEPT
#Allow incoming netbios and microsoft-ds for Samba
#Someday I might experiement to see which of these is actually required.
#so I can close off the rest.
${IPTABLES} -A INPUT -p tcp --dport netbios-ssn -j ACCEPT
${IPTABLES} -A INPUT -p tcp --dport microsoft-ds -j ACCEPT
${IPTABLES} -A INPUT -p udp --dport netbios-ns -j ACCEPT
${IPTABLES} -A INPUT -p udp --dport netbios-dgm -j ACCEPT
#Allow incoming ipp connections for network printing
${IPTABLES} -A INPUT -p tcp --dport ipp -j ACCEPT
${IPTABLES} -A INPUT -p udp --dport ipp -j ACCEPT
#Drop and log all other data
#The logging is set so if more than 5 packets are dropped in
#three seconds they will be ignored. This helps to prevent a DOS attack
#Crashing the computer the firewall is running on
${IPTABLES} -A INPUT -m limit --limit 3/second --limit-burst 5 -i ! lo -j LOG
${IPTABLES} -A INPUT -i ! lo -j DROP
;;
stop)
#flush existing rules
${IPTABLES} -F INPUT
;;
status)
${IPTABLES} -L -v -n
;;
*)
echo "Usage: $0 {start|restart|reload|stop|status}"
exit 1
esac
exit 0
That is the script I use. The logging is pretty self explainitory, it logs everything that is dropped unless the packets are coming to fast (don't want a DOS attack!).
If you want to add/remove ports just add/remove rules.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.