I cannot get FreeBSD to correctly NAT / forward packets while acting as my front-facing firewall and gateway. Hopefully someone here can assist me in fine tuning this setup.
Problem: FreeBSD forwards packets from interface_0 to interface_1 correctly - but does not change the source IP of the packet. This causes the packets sent to the internet to have internal (non-routable) IP addresses.
Background: I am setting up my new network at my house for personal use. Being the nerdy guy I am, I want to implement my own manageable (Firewall / VPN / DNS / IDS) server on the outside of my internal network. I am currently running FreeBSD 9.1-RELEASE on a box that is going to act as the gateway for my private internal network to the external internet. I have attached a quick network diagram to assist describing this.
Question 0: Why won't FreeBSD NAT packets correctly for the wireless router? The FreeBSD gateway can access the internet, and anything 'behind' it. Anything 'behind' the FreeBSD gateway can access up to the FreeBSD gateway, on either IP.
I have included below:
Question 1: Kind of a side question, MUCH more interested in the above.
Do I need to keep the FreeBSD gateway and the wireless router on different sub-nets? Could I make the FreeBSD gateway 192.168.1.2 and the wireless router 192.168.1.1?
NOTE: For reasons I won't get into, the wireless router MUST remain as 192.168.1.1
Problem: FreeBSD forwards packets from interface_0 to interface_1 correctly - but does not change the source IP of the packet. This causes the packets sent to the internet to have internal (non-routable) IP addresses.
Background: I am setting up my new network at my house for personal use. Being the nerdy guy I am, I want to implement my own manageable (Firewall / VPN / DNS / IDS) server on the outside of my internal network. I am currently running FreeBSD 9.1-RELEASE on a box that is going to act as the gateway for my private internal network to the external internet. I have attached a quick network diagram to assist describing this.
Question 0: Why won't FreeBSD NAT packets correctly for the wireless router? The FreeBSD gateway can access the internet, and anything 'behind' it. Anything 'behind' the FreeBSD gateway can access up to the FreeBSD gateway, on either IP.
I have included below:
- Network Diagram
- /etc/rc.conf
- /etc/pf.conf
- tcpdump that shows the external interface.
Code:
# /etc/rc.conf
# NETWORKING - IPv4 configuration
ifconfig_bge0="inet 192.168.2.1 netmask 255.255.255.0"
ifconfig_bge1="inet A.B.C.D netmask 255.255.224.0"
defaultrouter="E.F.G.H"
static_routes="internal"
route_internal="-net 192.168.1.0/24 192.168.2.2"
gateway_enable="YES"
# Firewall Configuration
pf_enable="yes" # Enables Packet Filter (PF) Firewall
pf_rules="/etc/pf.conf" # Sets the location of the pf rules file
pflog_enable="yes" # Enables Packet Logging from pf
pflog_logfile="/var/log/pf/pf.log" # Destination for the log file
Code:
# /etc/pf.conf
# Variables
internal_if = "bge0"
internal_gw = "192.168.2.2"
external_if = "bge1"
# Tables
table <internal> const { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 }
# Options
set skip on lo
set block-policy drop
set fingerprints "/etc/pf.os"
set optimization conservative
# Translation
no rdr on { lo0, lo1 } from any to any
nat on $external_if from <internal> to any -> ($external_if)
# Packet Filtering - Testing purpose only
pass all
Code:
# tcpdump -ni bge1 icmp - Capture all ICMP packets on the EXTERNAL Interface.
# From behind Wireless Router
IP 192.168.2.2 > E.F.G.H: ICMP echo request, id 30161, seq 0, length 64
IP 192.168.2.2 > E.F.G.H: ICMP echo request, id 30161, seq 1, length 64
IP 192.168.2.2 > E.F.G.H: ICMP echo request, id 30161, seq 2, length 64
# From FreeBSD Gateway
IP A.B.C.D > E.F.G.H: ICMP echo request, id 30161, seq 0, length 64
IP E.F.G.H > A.B.C.D: ICMP echo reply, id 30161, seq 0, length 64
IP A.B.C.D > E.F.G.H: ICMP echo request, id 30161, seq 1, length 64
IP E.F.G.H > A.B.C.D: ICMP echo reply, id 30161, seq 1, length 64
IP A.B.C.D > E.F.G.H: ICMP echo request, id 30161, seq 2, length 64
IP E.F.G.H > A.B.C.D: ICMP echo reply, id 30161, seq 2, length 64
Question 1: Kind of a side question, MUCH more interested in the above.
Do I need to keep the FreeBSD gateway and the wireless router on different sub-nets? Could I make the FreeBSD gateway 192.168.1.2 and the wireless router 192.168.1.1?
NOTE: For reasons I won't get into, the wireless router MUST remain as 192.168.1.1