Linux security seems to purely revolve around IPTABLES so googling helped find a few commands to start me off in the right direction which is worth reading imo.
https://help.ubuntu.com/community/IptablesHowTo
Trial and error (please correct me if anything is wrong) I build a script containing my firewall rules which allow unlimited local network access to SSH & WWW while blocking external access.
ssh = port 22
www = port 80
Home network is designed as follows
192.168.1.1 DSL modem router (linksys wag54gs)
192.168.1.60 static IP for RPi (below 100 I leave for static addressing)
192.168.1.100 - 200 DHCP used for laptop, desktop, phone etc
Code: Select all
# default policy
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# drop broadcast (do not log)
iptables -A INPUT -i eth0 -d 255.255.255.255 -j DROP
iptables -A INPUT -i eth0 -d 192.168.255.255 -j DROP
iptables -A INPUT -i eth0 -d 192.168.1.255 -j DROP
# accept ssh / www connections from local ranges
iptables -A INPUT -p tcp -m tcp --dport 22 -m iprange --src-range 192.168.1.10-192.168.1.200 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 -m iprange --src-range 192.168.1.10-192.168.1.200 -j ACCEPT
# accept everything from loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# accept ICMP packets (ping)
iptables -A INPUT -p icmp -m limit --limit 10/second -j ACCEPT
iptables -A INPUT -p icmp -j DROP
# internet (established and out)
iptables -A OUTPUT -o $int_if -j ACCEPT
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# accept ssh / www connections from local IP ranges
iptables -A INPUT -p tcp -m tcp --dport 22 -m iprange --src-range 192.168.1.10-192.168.1.200 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 -m iprange --src-range 192.168.1.10-192.168.1.200 -j ACCEPT
# log all the rest before dropping
iptables -A INPUT -m limit --limit 6/min -j LOG --log-prefix "IN "
iptables -A INPUT -j REJECT --reject-with icmp-port-unreachable
iptables -A OUTPUT -m limit --limit 6/min -j LOG --log-prefix "OU "
iptables -A OUTPUT -j REJECT --reject-with icmp-port-unreachable
iptables -A FORWARD -m limit --limit 6/min -j LOG --log-prefix "FW "
iptables -A FORWARD -j REJECT --reject-with icmp-port-unreachable
the final step to my rules was updating /etc/init.d/transmission-daemon with iptable rules after the log_end_msg lines.
Code: Select all
start)
iptables -I INPUT -p tcp -m tcp --dport 51413 -j ACCEPT
stop)
iptables -D INPUT -p tcp -m tcp --dport 51413 -j ACCEPT
I know linux securty isnt anything new so keeping it simple for learning I would like to hear from others about securing the RPi.