首页 > 代码库 > HOWTO: multiple default routes
HOWTO: multiple default routes
Thanks to phoenix help I was able to setup multiple default routes, or a default route per network/interface to be precise, in Debian/Linux it is as simple as that:
/etc/network/interfaces
That would be example topology (but more then 2 interfaces is also possible).
Now, You can not use the ‘casual‘ defaultrouter="X" cause it will be only for one network.
We will have to use setfib(1) to create two (or more) separete routing tables per network/interface.
Add these lines to /boot/loader.conf file:
It will unfortunately require kernel recompile, but its not as that hard:
We can of course set 2 instead of 16, but You will at least have to recompile Your kernel again and reboot which is not very handy ...
Nest set your networks/interfaces as usual in /etc/rc.conf file:
All the rest configuration resides in /etc/rc.local file:
These would be handy for restarting:
/etc/network/interfaces
Code:
iface eth0 inet static address 10.0.0.1 netmask 255.255.255.0 gateway 10.0.0.254iface eth1 inet static address 20.0.0.1 netmask 255.255.255.0 gateway 20.0.0.254
Code:
NETWORK0 NETWORK1 \ / \ / \ / \ / \ / ROUTER0 ROUTER1 10.0.0.254 20.0.0.254 \ / +------\----------------/------+ | \ / | | em0 em1 | | 10.0.0.1 20.0.0.1 | | | | FREEBSD BOX | | | +------------------------------+
We will have to use setfib(1) to create two (or more) separete routing tables per network/interface.
Add these lines to /boot/loader.conf file:
Code:
ipfw_load="YES"net.fibs=16
Code:
# cd /usr/src/sys/$( uname -m )/conf# cp GENERIC /root/ROUTES# ln -s /root/ROUTES# echo "options ROUTETABLES=16" >> ROUTES# cd /usr/src# make NO_MODULES=1 kernel KERNCONF=ROUTES KODIR=/boot/routes# mv /boot/routes/kernel /boot/kernel/kernel# reboot
Nest set your networks/interfaces as usual in /etc/rc.conf file:
Code:
ifconfig_em0="inet 10.0.0.1/24"ifconfig_em1="inet 20.0.0.1/24"# check /etc/rc.local for default routes
All the rest configuration resides in /etc/rc.local file:
Code:
# define default routessetfib 0 route delete defaultsetfib 0 route add default 10.0.0.254setfib 1 route delete defaultsetfib 1 route add default 20.0.0.254# assing route tables to interfacesipfw -f flushipfw add allow ip from any to any via lo0ipfw add setfib 1 ip from any to any via em0ipfw add setfib 0 ip from any to any via em1ipfw add allow ip from any to any
Code:
# /etc/rc.d/netif restart# /etc/rc.d/local restart
来源: <http://daemonforums.org/showthread.php?t=4610>
来自为知笔记(Wiz)
HOWTO: multiple default routes
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。