# NAT box with WLAN



## APz (Jan 9, 2012)

Hi folks,

I have a FreeBSD based NAT-box, which also serves as a WLAN AP. The home network has a file+print server, and my family has couple of desktops, 3 laptops and cellphones, which all connect to the LAN over either wired ethernet or over WLAN.

Currently the machine has 4 network cards:

NATting:
Ethernet 1: connected to my ISP over VDSL2 modem
Ethernet 2: connected to LAN

WLAN:
Ethernet 3: Bridged to WLAN 1
WLAN 1: Bridged to Ethernet 3

The idea is to make the WLAN devices behave like they were directly connected to the LAN, so they can access the file shares and printing which again isn't available on the other side of the NAT.

The question is, can I drop the 3rd Ethernet card, so the 2nd ethernet card would be used on both, NAT box's LAN connection and as a part of the WLAN bridge?

I'm asking this because the hardware is getting old, and I have my eyes on a nano-atx board that has room for 2 ethernet ports and a build-in WLAN, but no room for expansion, except if I buy a rather expensive PCI-E 2 port NIC.


----------



## SirDice (Jan 9, 2012)

APz said:
			
		

> The question is, can I drop the 3rd Ethernet card, so the 2nd ethernet card would be used on both, NAT box's LAN connection and as a part of the WLAN bridge?


Yes, but bridging might not work though. Not all WLAN cards support this. For file and printer sharing it's not needed, you can make it work by using 2 subnets, one for the LAN and one for the WLAN.


----------



## APz (Jan 9, 2012)

I recall my first attempt failed as I couldn't set an IP for the LAN interface as it was part of the bridge, thus the bridge worked but the machine itself had no access to LAN.

I was thinking of creating two virtual interfaces for the interface that's connected to LAN, and using one of them as the NAT box's LAN access and another as a part of the WLAN bridge. However, I'm not familiar with FreeBSD's way of handling this, any pointers?


----------



## bluetick (Jan 9, 2012)

This works for me in 8.2 and 9.0.
Dhcpd server is upstream from this. 

Not all wireless cards will work with this setup.
It's been a while, but I think getting the wired and wireless cards to matching mtu values in bridge mode is the problem.


```
## rc.conf

defaultrouter="192.168.x.x"
gateway_enable="YES"
hostname="wbox.mecasa.org"
ifconfig_dc0="UP"
wlans_ral0="wlan0"
create_args_wlan0="wlanmode hostsp ssid mecasa mode 11g channel 1"
cloned_interfaces="bridge0"
ifconfig_bridge0="addm dc0 addm wlan0"
ifconfig_bridge0_alias0="inet 192.168.x.x/24"
hostapd_enable="YES"

## hostspd.conf

interface=wlan0
debug=1
ctrl_interface=/var/run/hostapd
ctrl_interface_group=wheel
ssid=mecasa
wpa=1
wpa_passphrase=mecasapasswd
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP TKIP

## loader.conf

if_bridge_load="YES"
bridgestp_load="YES"
```


----------



## APz (Jan 29, 2012)

Thanks for the tip, guys! I'm writing this with my new NAT box installed, and I managed to drop the third wired connection. In short, here's how it finally worked:

re0: connected to VDSL
em0: connected to LAN
ath0: bridge to LAN


```
wlans_ath0="wlan0"
create_args_wlan0="wlanmode hostap ssid my-own-wifi mode 11n channel 06 mtu 1500 up"
cloned_interfaces="bridge0"
ifconfig_bridge0="addm wlan0 addm em0 up"
ifconfig_bridge0_alias0="inet 192.168.0.1"
ifconfig_em0="up"
ifconfig_re0="DHCP"
```


----------

