The Book of Pf
Total Page:16
File Type:pdf, Size:1020Kb
THE BOOK OF PF A No-Nonsense Guide to the OpenBSD Firewall by Peter N.M. Hansteen ® San Francisco THE BOOK OF PF. Copyright © 2008 by Peter N.M. Hansteen. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. Printed on recycled paper in the United States of America 11 10 09 08 07 1 2 3 4 5 6 7 8 9 ISBN-10: 1-59327-165-4 ISBN-13: 978-1-59327-165-7 Publisher: William Pollock Production Editor: Megan Dunchak Cover and Interior Design: Octopod Studios Developmental Editor: Adam Wright Technical Reviewer: Henning Brauer Copyeditor: Linda Recktenwald Compositor: Riley Hoffman Proofreader: Alina Kirsanova Indexers: Karin Arrigoni and Peter N.M. Hansteen For information on book distributors or translations, please contact No Starch Press, Inc. directly: No Starch Press, Inc. 555 De Haro Street, Suite 250, San Francisco, CA 94107 phone: 415.863.9900; fax: 415.863.9950; [email protected]; www.nostarch.com Library of Congress Cataloging-in-Publication Data Hansteen, Peter N. M. The book of PF : a no-nonsense guide to the OpenBSD firewall / Peter N.M. Hansteen. p. cm. Includes index. ISBN-13: 978-1-59327-165-7 ISBN-10: 1-59327-165-4 1. OpenBSD (Electronic resource) 2. TCP/IP (Computer network protocol) 3. Firewalls (Computer security) I. Title. TK5105.585.H385 2008 005.8--dc22 2007042929 No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it. To Gene Scharmann, who all those years ago nudged me in the direction of free software BRIEF CONTENTS Foreword by Bob Beck.................................................................................................... xi Preface ....................................................................................................................... xiii Chapter 1: What PF Is .....................................................................................................1 Chapter 2: Let’s Get On With It ........................................................................................7 Chapter 3: Into the Real World.......................................................................................17 Chapter 4: Wireless Networks Made Easy .......................................................................33 Chapter 5: Bigger or Trickier Networks............................................................................45 Chapter 6: Turning the Tables for Proactive Defense ..........................................................67 Chapter 7: Queues, Shaping, and Redundancy ................................................................87 Chapter 8: Logging, Monitoring, and Statistics ...............................................................107 Chapter 9: Getting Your Setup Just Right........................................................................121 Appendix A: Resources................................................................................................135 Appendix B: A Note on Hardware Support ....................................................................141 Index .........................................................................................................................147 CONTENTS IN DETAIL FOREWORD by Bob Beck xi PREFACE xiii About the Book and Thanks ..................................................................................... xiv If You Came from Elsewhere .................................................................................... xvi PF looks really cool. Can I run PF on my Linux machine? ................................ xvi I know some Linux, but I need to learn some BSD. Any pointers? ..................... xvi Can you recommend a GUI tool for managing my PF rule set? ........................xvii Is there a tool I can use to convert my OtherProduct ® setup to a PF configuration? ........................................................................xviii Where can I find out more? .......................................................................xviii A Little Encouragement: A PF Haiku .......................................................................... xix 1 WHAT PF IS 1 Packet Filter? Firewall? A Few Important Terms Explained .............................................. 3 Network Address Translation ..................................................................................... 3 Why the Internet Lives on a Few White Lies .................................................... 4 Internet Protocol, Version 6 on the Far Horizon ............................................... 4 The Temporary Masquerade Solution Called NAT ........................................... 5 PF Today ................................................................................................................. 6 2 LET’S GET ON WITH IT 7 Simplest Possible PF Setup on OpenBSD ..................................................................... 8 Simplest Possible PF Setup on FreeBSD ....................................................................... 9 Simplest Possible PF Setup on NetBSD ...................................................................... 10 First Rule Set—A Single, Stand-Alone Machine .......................................................... 11 Slightly Stricter, with Lists and Macros ....................................................................... 13 Statistics from pfctl .................................................................................................. 15 3 INTO THE REAL WORLD 17 A Simple Gateway, NAT If You Need It .................................................................... 17 Gateways and the Pitfalls of in, out, and on ................................................ 18 What Is Your Local Network, Anyway? ........................................................ 19 Setting Up ................................................................................................ 19 Testing Your Rule Set ................................................................................. 23 That Sad Old FTP Thing .......................................................................................... 24 FTP Through NAT: ftp-proxy ..................................................................................... 25 FTP, PF, and Routable Addresses: ftpsesame, pftpx, and ftp-proxy ................... 26 New-Style FTP: ftp-proxy ............................................................................. 26 Making Your Network Troubleshooting Friendly ......................................................... 28 Then, Do We Let It All Through? .................................................................. 28 The Easy Way Out: The Buck Stops Here ..................................................... 29 Letting ping Through .................................................................................. 29 Helping traceroute ..................................................................................... 29 Path MTU Discovery .................................................................................. 30 Tables Make Your Life Easier ................................................................................... 31 4 WIRELESS NETWORKS MADE EASY 33 A Little IEEE 802.11 Background .............................................................................. 33 MAC Address Filtering ............................................................................... 34 WEP ........................................................................................................ 35 WPA ....................................................................................................... 35 Picking the Right Hardware for the Task ....................................................... 35 Setting Up a Simple Wireless Network ..................................................................... 36 The Access Point’s PF Rule Set ..................................................................... 38 If Your Access Point Has Three or More Interfaces ......................................... 38 Handling IPsec, VPN Solutions .................................................................... 39 The Client Side ......................................................................................... 40 Guarding Your Wireless Network with authpf ............................................................ 40 A Basic Authenticating Gateway ................................................................. 41 Wide Open but Actually Shut ..................................................................... 43 5 BIGGER OR TRICKIER NETWORKS 45 When Others Need Something in Your Network: Filtering Services