# Configure different specific default routes, nameserver, searchdomains etc. for different networks, bound to different nics



## freeBSDNew (Sep 10, 2021)

Hello,

sorry, if my question ist stupid.

I want to configure a freebsd-server, that has different nic's, bound to different networks.

For example

em0
- 10.0.1.0 / 24
- defaultrouter 10.0.1.1
- nameserver 8.8.8.8, a.a.a.a, ...
- search domain lan.home.arpa

em1
- 10.1.1.0 / 24
- defaultrouter 10.1.1.1
- nameserver  b.b.b.b, c.c.c.c, ...
- search domain mngmt.home.arpa

em2
- 10.2.1.0 / 24
- defaultrouter 10.2.1.1
- search domain IoT.home.arpa

...

Is ist possible to define different / multiple networks persistent in rc.conf oder resolv.conf or otherwise?

I know, that I can define f. e, one defaultrouter in rc.conf. but what, if i need different routers for different networks, same with searchdomains and nameserver?

Thank you all.


----------



## Alexander88207 (Sep 10, 2021)

Hello freeBSDNew,

as far as I know there is only one DNS configuration for the whole system but not per interface.

The question has also been asked in the past [more or less]: https://forums.freebsd.org/threads/setting-dns-servers-for-a-nic.81163/


----------



## cmoerz (Sep 10, 2021)

If your FreeBSD system is connected to those three LANs directly, wouldn't it already know about the routes? Do you want a DNS to resolve hostnames differently for systems on those LANs or what particular use case are you looking for?

If you are looking for a solution to do multiple uplinks, you could look at something like https://www.quagga.net/


----------



## SirDice (Sep 13, 2021)

freeBSDNew said:


> I know, that I can define f. e, one defaultrouter in rc.conf. but what, if i need different routers for different networks


There's always only _one_ default gateway, that's the definition of a _default_ gateway, it's the one that is used if no other (stricter) static or dynamic routes can be found. I like the definition Cisco uses; gateway of last resort. In other words, it's the gateway that's used if no other routes apply.

Additional _static_ routes can be added like this:

```
static_routes="network1 network2"
route_network1="1.2.3.0/24 10.0.0.1"
route_network2="2.3.4.0/24 10.0.0.2"
```

Note that _directly_ connected networks will already have an _implied_ route. You can check your routing table with `netstat -rn`. And don't forget to enable routing by adding `gateway_enable="YES"` to /etc/rc.conf.


----------



## putney (Sep 13, 2021)

SirDice said:


> route_network1="1.2.3.0/24 10.0.0.1"



I have something like "-net 1.2.3.0/24 10.0.0.1" in those assignments. Is -net optional? I can't make it out from /etc/rc.d/routing.


----------



## zirias@ (Sep 13, 2021)

Wouldn't this thread be related?








						Multi-homed FreeBSD system default gateway question
					

Hi Forum,  I've got a FreeBSD 9.1 system that is attached to two separate /29's connected to different ISPs.  Lets call them NET1/29 and NET2/29.  The system does NAT (via pf) for my private IP space behind this system.  What I would love to happen is have the system select the default gateway...




					forums.freebsd.org


----------



## SirDice (Sep 13, 2021)

putney said:


> I have something like "-net 1.2.3.0/24 10.0.0.1" in those assignments. Is -net optional? I can't make it out from /etc/rc.d/routing.


It just executes route(8) with the value as arguments.


----------

