Example svnserve nfsserve iptable ruleset: Difference between revisions

From Research
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 18: Line 18:
  # ==============
  # ==============
  # of course, accepting loopback is a good idea
  # of course, accepting loopback is a good idea
  $IPTABLES -A INPUT -i lo -j ACCEPT  
  $IPTABLES -A INPUT -i lo -j ACCEPT
# we will permit ping, but rate-limit type 8 to prevent DoS-attack
$IPTABLES -A INPUT -p icmp --icmp-type 0 -j ACCEPT
$IPTABLES -A INPUT -p icmp --icmp-type 3 -j ACCEPT
$IPTABLES -A INPUT -p icmp --icmp-type 11 -j ACCEPT
$IPTABLES -A INPUT -p icmp --icmp-type 8 -m limit --limit 1/second -j ACCEPT
   
   
  #  (Applies to packets entering our network interface from the network,  
  #  (Applies to packets entering our network interface from the network,  
  #  and addressed to this host.)
  #  and addressed to this host.)
   
   
  $IPTABLES -A INPUT -m state --state INVALID -j DROP  
  $IPTABLES -A INPUT -m conntrack --ctstate INVALID -j DROP  
  $IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT  
  $IPTABLES -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT  
   
   
  # ssh incoming, including non-standard port (if needed)
  # ssh incoming, including non-standard port (if needed)
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT  
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 22 -j ACCEPT  
   
   
  # web serving, let's allow it!  Both http and https ports
  # web serving, let's allow it!  Both http and https ports
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 80 -j ACCEPT
   
   
  # portmapper, in support of being an NFS-client
  # portmapper, in support of being an NFS-client
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 111 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 111 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m state --state NEW --dport 111 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW --dport 111 -j ACCEPT
   
   
  # NFS serving (NFSv4 server offering NFSv3 back-compat)
  # NFS serving (NFSv4 server offering NFSv3 back-compat)
Line 40: Line 46:
  # /etc/conf.d/nfs, for OPTS_RPC_MOUNTD="-p 4002" and OPTS_RPC_STATD="-p 4000"
  # /etc/conf.d/nfs, for OPTS_RPC_MOUNTD="-p 4002" and OPTS_RPC_STATD="-p 4000"
  # /etc/sysctl.conf, for fs.nfs.nlm_tcpport = 4001 and fs.nfs.nlm_udpport = 4001
  # /etc/sysctl.conf, for fs.nfs.nlm_tcpport = 4001 and fs.nfs.nlm_udpport = 4001
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 2049 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 2049 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m state --state NEW --dport 2049 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW --dport 2049 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 4000 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 4000 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m state --state NEW --dport 4000 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW --dport 4000 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 4001 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 4001 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m state --state NEW --dport 4001 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW --dport 4001 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 4002 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 4002 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m state --state NEW --dport 4002 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW --dport 4002 -j ACCEPT
   
   
  # rsync serving
  # rsync serving
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 873 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 873 -j ACCEPT
   
   
  # svn server
  # svn server
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 3690 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 3690 -j ACCEPT
   
   
  # nagios (5666); monitor time (123), allow snmp (161)
  # nagios (5666); monitor time (123), allow snmp (161)
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 5666 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 5666 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m udp --dport 123 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m udp --dport 123 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m udp --dport 161 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m udp --dport 161 -j ACCEPT
   
   
  # amanda tape-backups; we reach out and tape things from this machine
  # amanda tape-backups; we reach out and tape things from this machine
  $IPTABLES -A INPUT -p udp -m state --state NEW -m udp --dport 10080 -j ACCEPT
  $IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW -m udp --dport 10080 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 10082 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 10082 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 10083 -j ACCEPT
  $IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 10083 -j ACCEPT
   
   
   
   

Latest revision as of 20:51, 18 December 2012

#! /bin/sh
# /etc/iptables.bak

# Let's save typing & confusion with variables
IPTABLES=/sbin/iptables

# Flush active rules and custom tables
$IPTABLES --flush
$IPTABLES --delete-chain

# set the defaults so that by-default incoming packets are dropped, unless explicitly allowed;
# for a desktop workstation, we'll let lots of (unpredictable) outgoing packets go freely.
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD DROP
$IPTABLES -P OUTPUT ACCEPT

# INBOUND POLICY
# ==============
# of course, accepting loopback is a good idea
$IPTABLES -A INPUT -i lo -j ACCEPT

# we will permit ping, but rate-limit type 8 to prevent DoS-attack
$IPTABLES -A INPUT -p icmp --icmp-type 0 -j ACCEPT
$IPTABLES -A INPUT -p icmp --icmp-type 3 -j ACCEPT
$IPTABLES -A INPUT -p icmp --icmp-type 11 -j ACCEPT
$IPTABLES -A INPUT -p icmp --icmp-type 8 -m limit --limit 1/second -j ACCEPT

#   (Applies to packets entering our network interface from the network, 
#   and addressed to this host.)

$IPTABLES -A INPUT -m conntrack --ctstate INVALID -j DROP 
$IPTABLES -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 

# ssh incoming, including non-standard port (if needed)
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 22 -j ACCEPT 

# web serving, let's allow it!  Both http and https ports
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 80 -j ACCEPT

# portmapper, in support of being an NFS-client
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 111 -j ACCEPT
$IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW --dport 111 -j ACCEPT

# NFS serving (NFSv4 server offering NFSv3 back-compat)
# nail down the ports, by editing:
# /etc/conf.d/nfs, for OPTS_RPC_MOUNTD="-p 4002" and OPTS_RPC_STATD="-p 4000"
# /etc/sysctl.conf, for fs.nfs.nlm_tcpport = 4001 and fs.nfs.nlm_udpport = 4001
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 2049 -j ACCEPT
$IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW --dport 2049 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 4000 -j ACCEPT
$IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW --dport 4000 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 4001 -j ACCEPT
$IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW --dport 4001 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 4002 -j ACCEPT
$IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW --dport 4002 -j ACCEPT

# rsync serving
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 873 -j ACCEPT

# svn server
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 3690 -j ACCEPT

# nagios (5666); monitor time (123), allow snmp (161)
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 5666 -j ACCEPT
$IPTABLES -A INPUT -p udp -m udp --dport 123 -j ACCEPT
$IPTABLES -A INPUT -p udp -m udp --dport 161 -j ACCEPT

# amanda tape-backups; we reach out and tape things from this machine
$IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW -m udp --dport 10080 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 10082 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW --dport 10083 -j ACCEPT


# OUTBOUND POLICY
# ===============
# of course, accepting loopback is a good idea
$IPTABLES -A OUTPUT -o lo -j ACCEPT

#   (Applies to packets sent to the network interface from local processes)

$IPTABLES -A OUTPUT -j ACCEPT