From owner-freebsd-questions@FreeBSD.ORG Mon Oct 13 07:32:41 2003 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 CF51E16A4B3 for ; Mon, 13 Oct 2003 07:32:41 -0700 (PDT) Received: from bmyster.com (loqtis.bmyster.com [65.162.190.7]) by mx1.FreeBSD.org (Postfix) with ESMTP id 06D2143F75 for ; Mon, 13 Oct 2003 07:32:40 -0700 (PDT) (envelope-from mrb@bmyster.com) Received: from loqtis.bmyster.com (localhost.bmyster.com [127.0.0.1]) by bmyster.com (8.12.10/8.12.10) with ESMTP id h9DEXHva094882; Mon, 13 Oct 2003 10:33:17 -0400 (EDT) Received: (from www@localhost) by loqtis.bmyster.com (8.12.10/8.12.10/Submit) id h9DEXCt2094881; Mon, 13 Oct 2003 10:33:12 -0400 (EDT) X-Authentication-Warning: loqtis.bmyster.com: www set sender to mrb@bmyster.com using -f Received: from 192.168.25.10 (SquirrelMail authenticated user mrb) by bmyster.com with HTTP; Mon, 13 Oct 2003 10:33:12 -0400 (EDT) Message-ID: <1132.192.168.25.10.1066055592.squirrel@bmyster.com> In-Reply-To: <20031013140026.GC543@dds.nl> References: <20031013140026.GC543@dds.nl> Date: Mon, 13 Oct 2003 10:33:12 -0400 (EDT) From: "Brent Bailey" To: "Alex de Kruijff" User-Agent: SquirrelMail/1.4.0 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 X-Priority: 3 Importance: Normal cc: Sean Noonan cc: freebsd-questions@freebsd.org Subject: Re: NAT and PPPoE problems X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: mrb@bmyster.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Oct 2003 14:32:42 -0000 Here are the docs i used when using ADSL w/ PPPoE and NAT w/ IPFW there are 2 writeups here ...first is PPPoE (im assuming you already know how to compile your kerel ?) 2nd is Duel Home host ...and how to setup NAT. hope this helps -- Brent Bailey CCNA Bmyster LLC Computer Networking and Webhosting Network Engineer, Webmaster, President http://www.bmyster.com mrb@bmyster.com 207-247-8330 ############################################# FreeBSD PPPoE HOWTO FreeBSD Requirements for PPPoE Be sure that you have a version of userppp that supports PPPoE. Please note that userppp is included in FreeBSD. It is not add-on software. Recent FreeBSD releases should be fine. Any -CURRENT, -STABLE and -RELEASE versions of FreeBSD should be able to support PPPoE. FreeBSD 4.0-CURRENT and 3.3-STABLE releases have been tested and found to work. Configuring FreeBSD Kernel for PPPoE In order to support PPPoE, three lines must be added at the end of the FreeBSD kernel file. Beginners with no idea how to compile a kernel, please read the following carefully. For more experienced users who know how to compile a kernel, just see step 3 below and add the three lines to your kernel. 1. First you must change to the kernel configuration directory: cd /usr/src/sys/i386/conf 2. In the kernel configuration directory, use your favorite text editor and edit the kernel file. For example, if you use emacs, you would type: vi KERNEL 3. Go to the end of the kernel file and add the following three lines: options NETGRAPH options NETGRAPH_PPPOE options NETGRAPH_SOCKET 4. After adding these three lines, save the modified kernel file. 5. Type this command to set the kernel configuration: config KERNEL 6. Now you must change to the kernel setup directory: cd ../../compile/KERNEL 7. In the kernel setup directory, type the following three commands: make depend make make install Your kernel is now ready for PPPoE! Configuring FreeBSD /etc/ppp/ppp.conf File To edit the /etc/ppp/ppp.conf file, just use your favorite text editor. Replace any existing file content with the lines below. Be sure the "set device PPPoE:---" line is correct for your network interface card. (We used ed1 for the NIC in this example.) Change the authname and authkey to your sympatico user id (b1xxxxxx) and your password. # /etc/ppp/ppp.conf default: set log Phase Chat LCP IPCP CCP tun command nat enable yes nat same_ports yes nat use_sockets yes set redial 15 28800 set reconnect 15 28800 pppoe: set device PPPoE:ed1: set mru 1492 set mtu 1492 set speed sync enable lqr set lqrperiod 5 set cd 5 set dial set login set timeout 0 set authname b1xxxxxx@sympatico.ca set authkey yourpassword set ifaddr 10.0.0.1/0 10.0.0.2/0 255.255.255.0 0.0.0.0 add default HISADDR enable dns # end of ppp configuration Configuring FreeBSD /etc/rc.conf File The /etc/rc.conf file should be set up as follows for the ethernet interface that goes to your DSL modem. (Again, this example uses ed1 for the NIC.) # /etc/rc.conf network_interfaces="auto" #Set network interfaces automatically ifconfig_ed1="inet 10.0.0.1 netmask 255.0.0.0 -arp up" ppp_enable="YES" #This enables PPP on startup (recommended) ppp_mode="background" ppp_profile="pppoe" #end of /etc/rc.conf Rebooting the System After you have compiled the kernel to support PPPoE and have edited the /etc/ppp/ppp.conf and /etc/rc.conf files with the right configuration, you can reboot your system. If you enabled ppp in the /etc/rc.conf as recommended, you should be connected and can now enjoy surfing the net on FreeBSD using PPPoE. Starting PPP Manually If you did not enable ppp to automatically connect on startup in the /etc/rc.conf file, you can use this command to connect to the Internet manually: ppp -background pppoe ############################################ ############################################## ######## IPFW & NAT ############################# using IPFW and NATD Applicable to: FreeBSD 4.2 Updated: January 1, 2001 This cheat sheet describes how to set up a dual-homed host (gateway) using kernel packet filtering (IPFW) and the network address traslation daemon (NATD). This procedure assumes the FreeBSD machine is equipped with two ethernet interfaces. If the outside interface is a dial-up connection or a PPP-over-Ethernet (PPPoE) DSL connection, use ppp(8)'s NAT facility instead. Before performing this procedure, you should read the FreeBSD Handbook sections Firewalls and Gateways and Routes, and review the ipfirewall(4), ipfw(8), and natd(8) manual pages. For the purpose of this procedure, the following assumptions have been made: The outside (Internet) interface is device 'dc0' and is assigned the IP address 123.45.67.89/22, either static or dynamic (DHCP). The inside interface is device 'ep0' and is assigned the IP address 10.20.155.0/24. If your outside interface is a DSL connection or a cable modem, please refer to Setting-up a DSL Connection or Setting-up a Cable Modem, as appropriate, before beginning this procedure. Edit the kernel configuration file, /usr/src/sys/i386/conf/YOURKERNEL, and add firewall/NAT support:
options IPFIREWALL #firewall
options IPDIVERT #divert sockets
There are some other options you might want to include as well:
options IPFIREWALL_VERBOSE #print information about
# dropped packets
options "IPFIREWALL_VERBOSE_LIMIT=100" #limit verbosity
options TCP_DROP_SYNFIN #drop TCP packets with SYN+FIN
options TCP_RESTRICT_RST #restrict emission of TCP RST
options "ICMP_BANDLIM"
For more information on these options, please refer to the /usr/src/sys/i386/conf/LINT.

Recompile the kernel, but do not reboot yet. Refer to Building a Custom Kernel for information on recompiling your kernel.

Edit /etc/rc.conf:
gateway_enable="YES" # Set to YES if this host will be a gateway.
firewall_enable="YES" # Set to YES to enable firewall functionality
firewall_script="/etc/rc.firewall" # Which script to run to set up the firewall
firewall_type="open" # Firewall type (see /etc/rc.firewall)
firewall_quiet="NO" # Set to YES to suppress rule display
natd_program="/sbin/natd" # path to natd, if you want a different one.
natd_enable="YES" # Enable natd (if firewall_enable == YES).
natd_interface="dc0" # Public interface or IPaddress to use.
natd_flags="-f /etc/natd.conf" # Additional flags for natd.


Create /etc/natd.conf:
dynamic yes (If you are using DHCP)
use_sockets yes
same_ports yes


Verify that the following line appears in /etc/services:
natd 8668/divert # Network Address Translation

Shutdown and reboot.
At this point, you should have a working gateway machine. Test to make sure machines on the local network can access the Internet.
Check your firewall rules:
# ipfw list

You should see something like:

00100 divert 8668 ip from any to any via dc0
00100 allow ip from any to any via lo0
00200 deny ip from any to 127.0.0.0/8
65000 allow ip from any to any

As you might have guessed, this is not a very secure firewall. So let's tighten it up:

Edit /etc/rc.conf and change the line:
firewall_script="/etc/rc.firewall"

to:
firewall_script="/etc/rc.ipfw"
Copy /etc/rc.firewall to /etc/rc.ipfw and edit it to reflect the outside and inside interface addresses and to include the following rules as you see fit: # rc.ipfw - Firewall Rules
#
# This file is a modified version of /etc/rc.firewall.
#
# Maintained by: D. O'Connor
# Modified: 7/18/2000.
#

# Suck in the configuration variables.
if [ -r /etc/defaults/rc.conf ]; then
. /etc/defaults/rc.conf
source_rc_confs
elif [ -r /etc/rc.conf ]; then
. /etc/rc.conf
fi
if [ -n "${1}" ]; then
firewall_type="${1}"
fi

# Firewall program
fwcmd="/sbin/ipfw"

# Outside interface network and netmask and ip
oif="dc0"
onet="x.x.x.x"
omask="255.255.252.0"
oip="x.x.x.x"

# Inside interface network and netmask and ip
iif="ep0"
inet="x.x.x.x"
imask="255.255.255.0"
iip="10.20.155.1"

# My ISP's DNS servers
dns1="207.228.35.42"
dns2="207.228.37.195"

# Flush previous rules
${fwcmd} -f flush

# Allow loopbacks, deny imposters
${fwcmd} add 100 pass all from any to any via lo0
${fwcmd} add 200 deny all from any to 127.0.0.0/8

# If you're using 'options BRIDGE', uncomment the following line to pass ARP
#${fwcmd} add 300 pass udp from 0.0.0.0 2054 to 0.0.0.0

# Stop spoofing
${fwcmd} add deny all from ${inet}:${imask} to any in via ${oif}
${fwcmd} add deny all from ${onet}:${omask} to any in via ${iif}

# Stop RFC1918 nets on the outside interface
${fwcmd} add deny all from any to 10.0.0.0/8 via ${oif}
${fwcmd} add deny all from any to 172.16.0.0/12 via ${oif}
${fwcmd} add deny all from any to 192.168.0.0/16 via ${oif}

# Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1,
# DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E)
# on the outside interface
${fwcmd} add deny all from any to 0.0.0.0/8 via ${oif}
${fwcmd} add deny all from any to 169.254.0.0/16 via ${oif}
${fwcmd} add deny all from any to 192.0.2.0/24 via ${oif}
${fwcmd} add deny all from any to 224.0.0.0/4 via ${oif}
${fwcmd} add deny all from any to 240.0.0.0/4 via ${oif}

# Network Address Translation. This rule is placed here deliberately
# so that it does not interfere with the surrounding address-checking
# rules. If for example one of your internal LAN machines had its IP
# address set to 192.0.2.1 then an incoming packet for it after being
# translated by natd(8) would match the `deny' rule above. Similarly
# an outgoing packet originated from it before being translated would
# match the `deny' rule below.
${fwcmd} add divert natd all from any to any via ${natd_interface}

# Stop RFC1918 nets on the outside interface
${fwcmd} add deny all from 10.0.0.0/8 to any via ${oif}
${fwcmd} add deny all from 172.16.0.0/12 to any via ${oif}
${fwcmd} add deny all from 192.168.0.0/16 to any via ${oif}

# Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1,
# DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E)
# on the outside interface
${fwcmd} add deny all from 0.0.0.0/8 to any via ${oif}
${fwcmd} add deny all from 169.254.0.0/16 to any via ${oif}
${fwcmd} add deny all from 192.0.2.0/24 to any via ${oif}
${fwcmd} add deny all from 224.0.0.0/4 to any via ${oif}
${fwcmd} add deny all from 240.0.0.0/4 to any via ${oif}

# Allow established connections with minimal overhead
${fwcmd} add pass tcp from any to any established

# Allow IP fragments to pass through
${fwcmd} add pass all from any to any frag

### TCP RULES

# HTTP - Allow access to our web server
${fwcmd} add pass tcp from any to any 80 setup mail
${fwcmd} add pass tcp from any to any 25 setup

# FTP - Allow incoming data channel for outgoing connections,
# reject & log all incoming control connections
${fwcmd} add pass tcp from any 20 to any 1024-65535 setup
${fwcmd} add deny log tcp from any to any 21 in via ${oif} setup

# SSH Login - Allow & Log all incoming
${fwcmd} add pass log tcp from any to any 22 in via ${oif} setup

# IDENT - Reset incoming connections
${fwcmd} add reset tcp from any to any 113 in via ${oif} setup

# Reject&Log all setup of incoming connections from the outside
${fwcmd} add deny log tcp from any to any in via ${oif} setup

# Allow setup of any other TCP connection
${fwcmd} add pass tcp from any to any setup

### UDP RULES

# DNS - Allow queries out in the world
${fwcmd} add pass udp from any to ${dns1} 53
${fwcmd} add pass udp from any to ${dns2} 53
${fwcmd} add pass udp from ${dns1} 53 to any
${fwcmd} add pass udp from ${dns2} 53 to any

# SMB - Allow local traffic
${fwcmd} add pass udp from any to any 137-139 via ${iif}

# SYSLOG - Allow machines on inside net to log to us.
${fwcmd} add pass log udp from any to any 514 via ${iif}

# NTP - Allow queries out in the world
${fwcmd} add pass udp from any 123 to any 123 via ${oif}
${fwcmd} add pass udp from any 123 to any via ${iif}
${fwcmd} add pass udp from any to any 123 via ${iif}

# TRACEROUTE - Allow outgoing
${fwcmd} add pass udp from any to any 33434-33523 out via ${oif}

### ICMP RULES

# ICMP packets
# Allow all ICMP packets on internal interface
${fwcmd} add pass icmp from any to any via ${iif}

# Allow outgoing pings
${fwcmd} add pass icmp from any to any icmptypes 8 out via ${oif}
${fwcmd} add pass icmp from any to any icmptypes 0 in via ${oif}

# Allow Destination Unreachable, Source Quench, Time Exceeded, and Bad Header
${fwcmd} add pass icmp from any to any icmptypes 3,4,11,12 via ${oif}

# Deny the rest of them
${fwcmd} add deny icmp from any to any

### MISCELLANEOUS REJECT RULES

# Reject broadcasts from outside interface
${fwcmd} add 63000 deny ip from any to 0.0.0.255:0.0.0.255 in via ${oif}

# Reject&Log SMB connections on outside interface
${fwcmd} add 64000 deny log udp from any to any 137-139 via ${oif}

# Reject&Log all other connections from outside interface
${fwcmd} add 65000 deny log ip from any to any via ${oif}

# Everything else is denied by default, unless the
# IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel


Load the new firewall rules:
# sh /etc/rc.ipfw
Be sure to do this from the console!
Note: You can reload the firewall rules over a network connection (telnet, ssh) by running the command in the background:
# sh /etc/rc.ipfw &
> On Sun, Oct 12, 2003 at 06:16:34PM -0700, Sean Noonan wrote: >> Hi Folks, >> >> I've used NAT with FreeBSD for years now, but recently had to change my >> ISP. My new ISP, SBC, uses PPPoE (yuck). I've finally got PPPoE >> working, >> but am having a heck of a time getting NAT to work with it. I'm >> tracking >> STABLE and cvsup'd, etc, about two weeks ago to 4.9-PRERELEASE. Here's >> my >> config: >> > Its my experiance that its best if you have some external hardware > that handels this. My provider uses PPTP but my ADSL modum handels this > and routes all the packets to me. > > -- > Alex > > Articles based on solutions that I use: > http://www.kruijff.org/alex/index.php?dir=docs/FreeBSD/ > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" >