# Help with natd & ipfw



## WhyCan'tI (Jan 4, 2008)

I have two networks in my location.

The first is a *100*Mbps wired & 802.11*g* wireless network operating on subnet 192.168.*1* with subnet mask 255.255.255.0.

The second is a *10*Mbps wired & 802.11*b* wireless network operating on subnet 192.168.*2* with subnet mask 255.255.255.0.

A MacBook is on the 802.11g network and has address 192.168.1.100.

Another machine is on the 10 Mbps wired network and has address 192.168.2.229.

A Mac mini is on *both* networks.  Interface en0 has IP address 192.168.*1*.226.  Interface en1 has IP address 192.168.*2*.200.

Here is a picture:






I am trying to use natd & ipfw on the Mac mini to create a bridge between the two networks.  I want to be able to ping from all directions, and for the devices on the 192.168.2 network to be able to reach the internet.

So far I have been using

$ sysctl -w net.inet.ip.forwarding=1
$ natd -v -interface en0
$ ipfw add divert natd all from any to any via en0

But it doesn't appear to be routing any of the traffic.

Any ideas?


----------



## WhyCan'tI (Jan 5, 2008)

Nevermind.  Got it working.


----------



## UserB93 (Apr 15, 2008)

Hi, I am wondering how you got it to work. I have been struggling with an similar setup.

Thanks!


----------



## WhyCan'tI (May 11, 2008)

UserB93 said:


> Hi, I am wondering how you got it to work. I have been struggling with an similar setup.
> 
> Thanks!



Here you go...


```
#!/bin/sh

. /etc/rc.common

ConsoleMessage "Configuring Network Bridge"

IPFW=/sbin/ipfw

# Enabling IP Forwarding
sysctl -w net.inet.ip.forwarding=1

# Starting NAT
natd -interface en0

StartService ()
{
   if [ "${FIREWALL:=-YES-}" = "-YES-" ]; then

   CheckForNetwork

   # check for network
   if [ "${NETWORKUP}" = "-NO-" ]; then exit; fi

   # clear all rules
   ConsoleMessage "Flushing IPFW Ruleset"
   ${IPFW} -f flush

   ConsoleMessage "Starting IPFW"

   # Allow loopback traffic; deny spoofing

   ConsoleMessage "Starting NAT"

   # Start NAT diverting
   ${IPFW} add divert natd all from any to any via en0
   ${IPFW} add divert natd all from any to any via en1

   # Allow outgoing traffic
   #${IPFW} add 65535 allow all from any to any

   fi
}

StopService ()
{
   ConsoleMessage "Stopping Bridge"
}

RestartService () { StopService; StartService; }

RunService "$1"
```


----------

