# Using same IP address on different FIBs



## YoonesR (Jul 28, 2015)

I was wondering is it possible to use same IP address on different FIBs ?
I want to build something like Cisco's VRF with FreeBSD.

Regards


----------



## junovitch@ (Jul 29, 2015)

YoonesR said:


> I was wondering is it possible to use same IP address on different FIBs ?
> I want to build something like Cisco's VRF with FreeBSD.
> 
> Regards


Yes I believe it should.  You'll need to ensure the interface has "fib #"  on it in your rc.conf and `ifconfig` will reflect the correct FIB for the interface.  I just did a quick check on a machine adding an the same IP from one FIB onto another interface in a different FIB and it appears to have worked as intended.  I don't know if you will run into any limitations though as you start to look into the problem as that was just a rather simplistic check.


----------



## YoonesR (Jul 29, 2015)

junovitch said:


> Yes I believe it should.  You'll need to ensure the interface has "fib #"  on it in your rc.conf and `ifconfig` will reflect the correct FIB for the interface.  I just did a quick check on a machine adding an the same IP from one FIB onto another interface in a different FIB and it appears to have worked as intended.  I don't know if you will run into any limitations though as you start to look into the problem as that was just a rather simplistic check.



Thank you for your quick response. There is a problem, consider the following example :

if we have below lines in our rc.conf:

```
ifconfig_em1="inet 192.168.18.2 netmask 255.255.255.0 fib 1"
ifconfig_em2="inet 192.168.18.2 netmask 255.255.255.0 fib 0"
```

FIB 1's routing table is empty and em1 is in FIB 0's routing table.
How can I make it work?


----------



## junovitch@ (Jul 29, 2015)

I'll assume this is starting from scratch so I'll just try to explain it all.  If you've used the Linux implementation of multiple routing tables before keep in mind that it's done a little bit differently in FreeBSD.  The biggest difference here is that FreeBSD doesn't have the same underlying concept of sending from address x.x.x.x to destination y.y.y.y.  Instead it's processes that must be explicitly bound to the FIB that you want them to run on.  If you want the same service on multiple FIBs then multiple instances of the same service must be run.

Set 2 routing tables.  You'll need to reboot after setting this tunable.  You can set up the next three items and reboot afterwards.
`echo 'net.fibs=2' >> /boot/loader.conf`

In this case, prevent device routes being added by default as you have found.
`echo 'net.add_addr_allfibs=0' >> /boot/loader.conf`

Then you'll need to assign the gateway for FIB 1 in /etc/rc.conf.

```
static_routes="fib1default"
route_fib1default="default 192.168.18.1 -fib 1"
```

For an initial test of the configuration, you can do some quick ping checks.  I'm assuming the gateway is 192.168.18.2 in my examples and I am assuming will be the same for both FIBs.  You can test this with:
`ping 192.168.18.2`  (`setfib 0` is implied so you don't need to type it)
and
`setfib 1 pint 192.168.18.2`.

If you have a packet capture running on that device you should see the ping requests and replies on the appropriate interface.  You should be ready to move on to configuring a service or jail to actually use the FIB now.

For a service, set the service you want to use that FIB to use it in /etc/rc.conf.  As an example.

```
nginx_fib="1"
```

For a jail, you'll have to consult the man page for either jail.conf(5) or whatever utility you are using to help configure your jails.


----------

