113f6 [Solved] FreeBSD 9 home webserver, configure a firewall - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Server & Networking > Firewalls

Firewalls IPFW, PF, IPF (but not limited) related discussion

Reply
 
Thread Tools Display Modes
  #1  
Old April 14th, 2012, 13:04
c00kie c00kie is offline
Member
 
Join Date: Mar 2012
Posts: 122
Thanks: 37
Thanked 0 Times in 0 Posts
Default FreeBSD 9 home webserver, configure a firewall

Hi

Background:

I have four machines (one desktop, three laptops) on a home LAN network. The desktop and one of the laptops (FreeBSD 9) are patched in to my home router via ethernet. The remaining laptops connect to the internet wirelessly. The laptop with FreeBSD 9 installed is acting as a public webserver using port forwarding and NAT. Hence I can access my webserver both locally and via the public internet.

On my FreeBSD 9 laptop machine and in file: /etc/rc.conf
Code:
 ifconfig_re0="inet 192.168.0.5 netmask 255.255.255.0"
 default_router="192.168.0.1"
Hence my external interface is: re0

I'm experimenting with firewalls since my webserver is now publicly accessible from the internet. My first attempt with PF failed.

From: http://www.freebsd.org/doc/en_US.ISO...walls-ipf.html

Quote:
With NAT only a single account is needed with your ISP. The other four PCs may then be cabled to a switch and the switch to the NIC in your FreeBSD system which is going to service your LAN as a gateway. NAT will automatically translate the private LAN IP address for each separate PC on the LAN to the single public IP address as it exits the firewall bound for the public Internet. It also does the reverse
translation for returning packets.
I'm not sure if the above really applies to me. I'm not using my FreeBSD box to act as a switch to my LAN. Instead, all laptops (and the desktop) connect to the router independently either wirelessley or ethernet as is the case for the desktop and webserver.

I thought this sounded a little more realistic:
Quote:
Alternatively, a firewall might be configured to protect only the system it is running on--this is called a “host based firewall”, and is particularly appropriate for servers on an untrusted network
Ive tried PF, installed OK, and even rebuilt a custom kernel with support for ALTQ. Using PF and rules from this tutorial:

http://home.nuug.no/~peter/pf/en/lon...l.html#PREFACE

my /etc/pf.conf would look like:
Code:
block all
tcp_services = "{ ssh, smtp, domain, www, pop3, auth, pop3s }"
udp_services = "{ domain }"
pass out proto tcp to port $tcp_services
pass proto udp to port $udp_services
This locks me out however - I can't access the webserver from inside the LAN and webpages didn't load upon browser refresh. I didn't attempt it externally i.e. from the public internet.

I will have a second attempt of course, but could use a little advice on a simple ruleset (easiest to implement for a novice eg. PF or IPF) for a single machine home webserver connected to a router with port forwarding and public internet access.


Thanks in advance.

Last edited by DutchDaemon; April 15th, 2012 at 02:25.
Reply With Quote
  #2  
Old April 14th, 2012, 19:11
c00kie c00kie is offline
Member
 
Join Date: Mar 2012
Posts: 122
Thanks: 37
Thanked 0 Times in 0 Posts
Default

OK

looking at some of the posts on this forum. I've decided to plump for PF. I've

# cp /usr/share/examples/pf/pf.conf /etc/pf.conf

My pf.conf file now looks like:

Code:
#ext_if="ext0"
#int_if="int0"

#table <spamd-white> persist

#set skip on lo

#scrub in

#nat-anchor "ftp-proxy/*"
#rdr-anchor "ftp-proxy/*"
#nat on $ext_if from !($ext_if) -> ($ext_if:0)
#rdr pass on $int_if proto tcp to port ftp -> 127.0.0.1 port 8021
#no rdr on $ext_if proto tcp from <spamd-white> to any port smtp
#rdr pass on $ext_if proto tcp from any to any port smtp \
#	-> 127.0.0.1 port spamd

#anchor "ftp-proxy/*"
#block in
#pass out

#pass quick on $int_if no state
#antispoof quick for { lo $int_if}

#pass in on $ext_if proto tcp to {$ext_if} port ssh
#pass in log on $ext_if proto tcp to {$ext_if} port smtp
#pass out log on $ext_if proto tcp from {$ext_if} to port smtp
#pass in on $ext_if inet proto icmp from any to {$ext_if} icmp-type { unreach, redir, timex }
If I'm using only one machine for all intents and purposes. Are my external and internal interfaces going to be the same?

i.e.

Code:
#ext_if="re0"
#int_if="re0"

Last edited by DutchDaemon; April 15th, 2012 at 02:26.
Reply With Quote
  #3  
Old April 15th, 2012, 14:15
c00kie c00kie is offline
Member
 
Join Date: Mar 2012
Posts: 122
Thanks: 37
Thanked 0 Times in 0 Posts
Default

I'll keep reading with http://www.openbsd.org/faq/pf/filter.html

So far I have a basic ruleset:

Code:
# Pass traffic in on dc0 from the local network, 192.168.0.0/24,
# to the OpenBSD machine's IP address 192.168.0.1. Also, pass the
# return traffic out on dc0.
pass in  on dc0 from 192.168.0.0/24 to 192.168.0.1
pass out on dc0 from 192.168.0.1 to 192.168.0.0/24


# Pass TCP traffic in on fxp0 to the web server running on the
# OpenBSD machine. The interface name, fxp0, is used as the
# destination address so that packets will only match this rule if
# they're destined for the OpenBSD machine.
pass in on fxp0 proto tcp from any to fxp0 port www
Very basic and this security thing makes one very paranoid. Not sure about how secure this is, but baby steps.
Reply With Quote
  #4  
Old April 15th, 2012, 22:19
plamaiziere plamaiziere is offline
Member
 
Join Date: Jan 2009
Location: Rennes, France
Posts: 174
Thanks: 1
Thanked 39 Times in 29 Posts
Default

Quote:
Originally Posted by c00kie View Post
I'll keep reading with http://www.openbsd.org/faq/pf/filter.html

So far I have a basic ruleset:
I guess, because no one replies, that nobody understands what you want to achieve. I've understood in your previous posts that your web server is under FreeBSD and connected to a router. Now I see that this host has two interfaces and is protecting an OpenBSD behind one.

A small description of the topology of your network will be helpful...

Regards.
Reply With Quote
  #5  
Old April 16th, 2012, 08:06
SirDice's Avatar
SirDice SirDice is offline
Moderator
 
Join Date: Nov 2008
Location: Rotterdam, Netherlands
Posts: 13,713
Thanks: 47
Thanked 2,022 Times in 1,861 Posts
Default

A really simple ruleset to protect one host and allow ssh and web.

Code:
set skip on lo0

block all

# We allow everything to go out
pass out from any to any keep state

# incoming rules
# ssh
pass in proto tcp from any to any port 22 keep state
# web
pass in proto tcp from any to any port 80 keep state
__________________
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
Reply With Quote
The Following User Says Thank You to SirDice For This Useful Post:
c00kie (April 16th, 2012)
  #6  
Old April 16th, 2012, 11:05
c00kie c00kie is offline
Member
 
Join Date: Mar 2012
Posts: 122
Thanks: 37
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by plamaiziere View Post

A small description of the topology of your network will be helpful...

Regards.
Sure. http://drupal876.co.uk/img/network.jpg

It's a very simple home network. I've ommitted the other computers on the LAN for brevity. The FreeBSD box is on all the time and in /etc/rc.conf I've ensured the macine has a static ip address with the following:

Code:
ifconfig_re0="inet 192.168.0.5 netmask 255.255.255.0"
as opposed to

Code:
ifconfig_re0="DHCP"
No switches, hubs or bridges and as far as I'm aware the FreeBSD box (laptop) has one NIC namely: re0.

Last edited by DutchDaemon; April 16th, 2012 at 15:29.
Reply With Quote
  #7  
Old April 16th, 2012, 11:09
c00kie c00kie is offline
Member
 
Join Date: Mar 2012
Posts: 122
Thanks: 37
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by SirDice View Post
A really simple ruleset to protect one host and allow ssh and web.

Code:
set skip on lo0

block all

# We allow everything to go out
pass out from any to any keep state

# incoming rules
# ssh
pass in proto tcp from any to any port 22 keep state
# web
pass in proto tcp from any to any port 80 keep state
That's perfect thanks. I only need basic protection until the time comes when I become network admin.
Reply With Quote
Reply

Tags
firewall, ip address, lan, router, webserver

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Solved] Home server on FreeBSD pkubaj System Hardware 12 February 15th, 2012 09:58
[Solved] Not able to access home page (www.freebsd.org) Rax General 8 March 6th, 2011 18:49
WebServer With FreeBSD ... Exist a guide? rokpa92 Web & Network Services 14 November 25th, 2010 12:56
Folding@home SMP2 in FreeBSD 32 bit Ralph_Ellis Howtos & FAQs (Moderated) 7 September 24th, 2010 06:25
I don't want to configure my own firewall. I want a good firewall.What can I do? drp Firewalls 11 July 26th, 2010 21:07


All times are GMT +1. The time now is 06:51.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0