# PF: NAT, Bridge on the same machine



## Magnesik (Jul 31, 2011)

So far on the router(on freebsd) was set Nat between rl0 (wan) and rl1 (lan). Unfortunately I need to connect one computer directly to router by next network card. I put it in to machine and set bridge between rl1(this card has address) and rl2 (new card). On pf I allowed trafic on rl2. 
The problem is that computers behind rl2 can ping gatway which is rl1 but cant ping computers behind rl1. In "clear bridge" when none of card has address (rl1 rl2) then connections beetwen computers behind rl1 and rl2 are possible but of course there is no access to WAN. 

How to make working bridge between r1(gate/lan side) and rl2 (free) and NAT between rl0(wan) and rl1 ?


----------



## icer (Aug 1, 2011)

You have 3 lans (wan, lan1, lan2) and you want that lan1 will be communicate with lan2? If I am understood you correct you don't need bridge.


----------



## Magnesik (Aug 1, 2011)

```
rl0 (internet) ---NAT ---- rl1 --> LAN
                       | 
                       |
                      rl2 -------> LAN
```

between rl1 and rl2 I'd like to make bridge. 

Lan which goes out from rl1 and rl2 is the same network (I want it to be)

ps. wlan? I mean WAN 

####EDITED####

I've set bridge on rl1 and rl2 and address for it (bridge0):


```
#ifconfig bridge0 addm rl1 addm rl2 up
#ifconfig rl1 up
#ifconfig rl2 up
#ifconfig bridge0 inet 192.168.0.100/24
```
In general it's sick! After this configuration I was not able to connect to bridge. Only when I diseabled pf I was able to reach machine. What is more I can ping server from any card: rl1 or rl2 but when I try to ping from server I cant... It seems like enablig pf is disenabling bridge. I need to mix NAT with bridge. Maybe there are other solutions?


----------



## SirDice (Aug 2, 2011)

NAT works on layer 3 and a bridge works on layer 2. Learn a bit about TCP/IP and you'll notice that it isn't the best of solutions you thought of.

What exactly are you trying to archive?


----------



## Magnesik (Aug 2, 2011)

Unfortunately I dont have another switch. I'm trying to connect one computer directly into FreeBSD machine and I want it to be a member of existing LAN. 

I got the idea to connect this one computer as diffrent subnet. Next problem is - how to configure altq to shape traffic so that the sum of download traffic from rl1 and rl2 was the sum of download of rl0 (WAN). In my pf.conf altq is assgined to particular interface with particular bandwidth.


----------



## icer (Aug 2, 2011)

You have 2 nics and 2 lans what the problems? Build router on youre freebsd machine.


----------



## Magnesik (Aug 2, 2011)

Can you give me some tips? I'm little confused about difference between Nat and route.

Now I have two networks at rl1 and rl2. rl1 - 10.0.0.0/24 and rl2 - 192.168.0.0/24. Only way what I saw to communicate computers together in this networks was Nat on rl1 and rl2. I think there are better way to do this? am I right?


----------



## icer (Aug 2, 2011)

Find this book "Building Firewalls With OpenBSD and PF - 2nd Edition"


----------



## Magnesik (Aug 2, 2011)

Ok I found this book but I still don't know what I really need. I tought that you meant fastroute or route-to - but it doesn't work.


----------



## Magnesik (Aug 3, 2011)

Ok everything works. The problem was that I've been pinging small home router but it has no route to default gateway in case to response to computer from different network.


----------

