From owner-freebsd-questions@FreeBSD.ORG Wed May 12 07:24:57 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D32F816A4CE for ; Wed, 12 May 2004 07:24:57 -0700 (PDT) Received: from mta11.adelphia.net (mta11.adelphia.net [68.168.78.205]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5DCA343D2D for ; Wed, 12 May 2004 07:24:56 -0700 (PDT) (envelope-from fbsd_user@a1poweruser.com) Received: from barbish ([67.20.101.71]) by mta11.adelphia.net (InterMail vM.5.01.06.08 201-253-122-130-108-20031117) with SMTP id <20040512142455.FXOX21898.mta11.adelphia.net@barbish> for ; Wed, 12 May 2004 10:24:55 -0400 From: "fbsd_user" To: "freebsd-questions@FreeBSD. ORG" Date: Wed, 12 May 2004 10:24:54 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Importance: Normal Subject: sample ipfilter setup for the archives X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: fbsd_user@a1poweruser.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 May 2004 14:24:57 -0000 This is posted just for the archives so other people can find it during a search. Please take notice that some of the rules may wrap to the next line in this email. You must return the wrapped part to the rule above it so it will work. Well lets start with the kernel. Both ipfw and ipfilter are delivered in the sysinstall process as boot time loadable modules, which means it is not necessary to put any kernel options statements into the kernel and recompile to get it to function. As part of ipfilter setup also configurating ipmon syslog logging. The ipfilter rule set will allow lan and gateway pc's to do both active and passive ftp out to the public internet. *********************************************** In rc.conf add these statements. gateway_enable="YES" ipfilter_enable="YES" ipfilter_rules="/etc/ipf.rules" ipmon_enable="YES" # Start ip monitor log ipmon_flags="-Ds" # D = start as daemon # s = log to syslog ipnat_enable="YES" ipnat_rules="/etc/ipnat.rules" *********************************************** In syslog.conf *.notice;authpriv.none;local0.none;mail.crit /var/log/messages local0.* /var/log/security Note1: local0 is where ipfilter flags option s (ie log to syslog) writes to. Note2: added local0.none to messages so ipfilter log records will not go to messages file also. *********************************************** In newsyslog.conf /var/log/security 600 10 100 * B says auto rotate log when file fills 100 k disk space. *********************************************** /etc/ipf.rules #### Note1: ed0 is the interface name of the Nic card connected to the public internet. Replace it with your interface name. #### #### Note2: this rule set may allow functions out and in which you may not have or want, just comment out those statements or delete them from the file. #### #### Note3. If you want to run an FTP server on your system that is accessible from the public internet, you must add the following rules. Only active mode remote FTP is allowed as passive mode needs all the high value port numbers open and this is an major security risk. # Allow out active FTP data channel pass out quick on ed0 proto tcp from any to any port = 20 flags S keep state # Allow in active FTP control channel pass in quick on ed0 proto tcp from any to any port = 21 flags S keep state ############# End of note3 ################# ################################################################# # For testing only, Bypasses the rest of the rules or just in or out #pass in log quick on ed0 all #pass out log quick on ed0 all #log out quick on ed0 all ################################################################# ################################################################# # No restrictions on Inside Lan Interface for private network # Replace dc0 with the nic interface name of your Lan ################################################################# pass out quick on dc0 all pass in quick on dc0 all ################################################################# # No restrictions on Loopback Interface ################################################################# pass in quick on lo0 all pass out quick on lo0 all ################################################################# # Interface facing Public internet (Outbound Section) # Interrogate session start requests originating from behind the # firewall on the private network # or from this gateway server destine for the public internet. ################################################################# # Allow out access to my ISP's Domain name server. # x.x.x.x must be the IP address of your ISP's DNS. # Dup these lines if your ISP has more than one DNS server # Get the IP addresses from /etc/resolv.conf file #pass out quick on ed0 proto tcp from any to x.x.x.x port = 53 flags S keep state #pass out quick on ed0 proto udp from any to x.x.x.x port = 53 keep state pass out log quick on ed0 proto udp from any to any port = 53 keep state # Allow out access to my ISP's DHCP server for cable or DSL networks. # This rule is not needed for 'user ppp' type connection to the # public internet, so you can delete this whole group. # Use the following rule and check log for IP address. # Then put IP address in commented out rule & delete first rule pass out quick on ed0 proto udp from any to any port = 67 keep state #pass out quick on ed0 proto udp from any to x.x.x.x port = 67 keep state # Allow out non-secure standard www function pass out quick on ed0 proto tcp from any to any port = 80 flags S keep state # Allow out secure www function https over TLS SSL pass out quick on ed0 proto tcp from any to any port = 443 flags S keep state # Allow out send & get email function pass out quick on ed0 proto tcp from any to any port = 25 flags S keep state pass out quick on ed0 proto tcp from any to any port = 110 flags S keep state # Allow out Time pass out quick on ed0 proto tcp from any to any port = 37 flags S keep state # Allow out nntp news pass out quick on ed0 proto tcp from any to any port = 119 flags S keep state # Allow out gateway & LAN users non-secure passive & active modes FTP # This function uses the IPNAT built in FTP proxy function coded in # the nat rules file to make this single rule function correctly. # If you want to use the pkg_add command to install application packages # on your gateway system you need this rule. pass out quick on ed0 proto tcp from any to any port = 21 flags S keep state # Allow out secure FTP, Telnet, and SCP # This function is using SSH (secure shell) pass out quick on ed0 proto tcp from any to any port = 22 flags S keep state # Allow out non-secure Telnet pass out quick on ed0 proto tcp from any to any port = 23 flags S keep state # Allow out FBSD CVSUP function pass out quick on ed0 proto tcp from any to any port = 5999 flags S keep state # Allow out all icmp to public Internet pass out quick on ed0 proto icmp from any to any keep state # Allow out all ident to public Internet #block out quick on ed0 proto tcp from any to any port = 113 # Allow out whois for LAN PC to public Internet pass out quick on ed0 proto tcp from any to any port = 43 flags S keep state # block ports that show on log and are ok to stop logging # Deny tcp port 81 - hosts2 name server. winme is doing this. block out quick on ed0 proto tcp from any to any port = 81 # Block and log only the first occurrence of everything # else that's trying to get out. # This rule enforces the block all by default logic. block out log first quick on ed0 all ################################################################# # Interface facing Public internet (Inbound Section) # Interrogate packets originating from the public internet # destine for this gateway server or the private network. ################################################################# # Block all inbound traffic from non-routable or reserved address spaces block in quick on ed0 from 192.168.0.0/16 to any #RFC 1918 private IP block in quick on ed0 from 172.16.0.0/12 to any #RFC 1918 private IP block in quick on ed0 from 10.0.0.0/8 to any #RFC 1918 private IP block in quick on ed0 from 127.0.0.0/8 to any #loopback block in quick on ed0 from 0.0.0.0/8 to any #loopback block in quick on ed0 from 169.254.0.0/16 to any #DHCP auto-config block in quick on ed0 from 192.0.2.0/24 to any #reserved for doc's block in quick on ed0 from 204.152.64.0/23 to any #Sun cluster interconnect block in quick on ed0 from 224.0.0.0/3 to any #Class D & E multicast ##### Block a bunch of different nasty things. ############ # That I don't want to see in the log # Block frags block in quick on ed0 all with frags # Block short tcp packets block in quick on ed0 proto tcp all with short # block source routed packets block in quick on ed0 all with opt lsrr block in quick on ed0 all with opt ssrr # Block nmap OS fingerprint attempts # Log first occurrence of these so I can get their IP address block in log first quick on ed0 proto tcp from any to any flags FUP # Block anything with special options block in quick on ed0 all with ipopts # Block public pings block in quick on ed0 proto icmp all icmp-type 8 # Block ident block in quick on ed0 proto tcp from any to any port = 113 # Block all Netbios service. 137=name, 138=datagram, 139=session # Netbios is MS/Windows sharing services. # Block MS/Windows hosts2 name server requests 81 block in log first quick on ed0 proto tcp/udp from any to any port = 137 block in log first quick on ed0 proto tcp/udp from any to any port = 138 block in log first quick on ed0 proto tcp/udp from any to any port = 139 block in log first quick on ed0 proto tcp/udp from any to any port = 81 # Allow traffic in from ISP's DHCP server. This rule must contain # the IP address of your ISP's DHCP server as it's the only # authorized source to send this packet type. Only necessary for # cable or DSL configurations. This rule is not needed for # 'user ppp' type connection to the public internet. # This is the same IP address you captured and # used in the outbound section. pass in quick on ed0 proto udp from x.x.x.x to any port = 68 keep state # Allow in standard www function because I have apache server pass in quick on ed0 proto tcp from any to any port = 80 flags S keep state # Allow in non-secure Telnet session from public Internet # labeled non-secure because ID & PW are passed over public internet # as clear text. # Delete this sample group if you do not have telnet server enabled. pass in quick on ed0 proto tcp from any to any port = 23 flags S keep state # Allow in secure FTP, Telnet, and SCP from public Internet # This function is using SSH (secure shell) #pass in quick on ed0 proto tcp from any to any port = 22 flags S keep state # Allow in email SMTP from public Internet if commercial user pass in quick on ed0 proto tcp from any to any port = 25 flags S keep state # Block and log only first occurrence of all remaining traffic # coming into the firewall. The logging of only the first # occurrence stops an 'denial of service' attack targeted # at filling up your log file space. # This rule enforces the block all by default logic. block in log first quick on ed0 all *********************************************** /etc/ipnat.rules # Provide special NAT services for FTP from LAN users. map ed0 10.0.10.0/29 -> 0/32 proxy port 21 ftp/tcp # Provide special NAT services for FTP from gateway system. map ed0 0.0.0.0/0 -> 0/32 proxy port 21 ftp/tcp # Provide Normal NAT services for LAN users. # NAT my private LAN ip address to what every my ISP address is map ed0 10.0.10.0/29 -> 0/32 Note: 10.0.10.0/29 is the private ip address range you assigned to your LAN. Ed0 is the nic interface name facing the public internet.