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

Code:

iface eth0 inet static
    address 10.0.0.1
    netmask 255.255.255.0
    gateway 10.0.0.254

iface eth1 inet static
    address 20.0.0.1
    netmask 255.255.255.0
    gateway 20.0.0.254

That would be example topology (but more then 2 interfaces is also possible).

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          |
        |                              |
        +------------------------------+

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:

Code:

ipfw_load="YES"
net.fibs=16

It will unfortunately require kernel recompile, but its not as that hard:

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

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:

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 routes
setfib 0 route delete default
setfib 0 route add    default 10.0.0.254
setfib 1 route delete default
setfib 1 route add    default 20.0.0.254

# assing route tables to interfaces
ipfw -f flush
ipfw add allow    ip from any to any via lo0
ipfw add setfib 1 ip from any to any via em0
ipfw add setfib 0 ip from any to any via em1
ipfw add allow    ip from any to any

These would be handy for restarting:

Code:

# /etc/rc.d/netif restart
# /etc/rc.d/local restart

来源: <http://daemonforums.org/showthread.php?t=4610>

来自为知笔记(Wiz)

时间: 2024-07-31 23:09:05

HOWTO: multiple default routes的相关文章

SIMPLE LIFE

SIMPLE LIFE, COMPLICATED MIND Tuesday, January 24, 2012 Multiple default routes gateways with two different ISP ipfw PF setfib load balancing Multiple default routes gateways with two different ISP ipfw PF setfib load balancing Thanks to phoenix help

FreeBSD Set a Default Route / Gateway

FreeBSD Set a Default Route / Gateway by NIXCRAFT on JANUARY 13, 2008 · 7 COMMENTS· LAST UPDATED OCTOBER 31, 2008 in FREEBSD, NETWORKING, TROUBLESHOOTING Q. How do I modify or set a default route for my FreeBSD server? How do I make default route con

GHOST CMS - Custom Routes

Custom Routes Template routes allow you to map individual URLs to specific template files within a Ghost theme. For example: make /custom/ load custom.hbs Using template routes is very minimal. There's no default data associated with them, so there i

Part3 &ndash; OPENVSWICH &ndash; Campus Model with Layer2 Access built with Open-Source Applications

In part one we showed how to create Openvswitch extension and submit it to Microcore repository. There were also presented after-install steps for Openvswitch adapted for specific Core needs. http://brezular.com/2011/09/03/part1-openvswich-creating-a

Policy-Based Routing and IP Service Level Agreement

Topics Policy-Based Routing(PBR): IOS PBR Feature IP Service Level Agreement: Policy-Based Routing (PBR), also sometimes called simply Policy Routing, influences the IP data plane, changing the forwarding decision a router makes,but without first cha

UNREAL ENGINE 4.12 正式发布!下载地址

UNREAL ENGINE 4.12 正式发布! 下载地址:https://www.unrealengine.com/ Alexander Paschall 在 June 1, 2016 |功能新闻社区 Share on Facebook Share on Twitter Share on Google+ Share on LinkedIn 此版本内含虚幻引擎 4 的数百个更新,以及 GitHub 虚幻引擎开发者社区提交的 106 项改良!特此对虚幻引擎 4.12 版本的贡献者们表达诚挚谢意:

自己修改的两个js文件

sea-base.js /** * Sea.js 2.2.3 | seajs.org/LICENSE.md */ (function(global, undefined) { // Avoid conflicting when `sea.js` is loaded multiple times if (global.seajs) { return } var seajs = global.seajs = { // The current version of Sea.js being used

给ubuntu设置静态ip —— How to set static IP Address in Ubuntu Server 16.04

原文: http://www.configserverfirewall.com/ubuntu-linux/ubuntu-set-static-ip-address/ ------------------------------------------------------------------------------------------------- How to set static IP Address in Ubuntu Server 16.04 It is really impo

pppd - 点对点协议守护进程

总览 SYNOPSIS pppd [ tty_name ] [ speed ] [ options ] 描述 点对点协议 (PPP) 提供一种在点对点串列线路上传输资料流 (datagrams)的方法.PPP是由三个部份所组成的:一个在串列线路上封装(encapsulating)资料流的方法,一个可延伸的连结控制协定(LinkControlProtocol:LCP),以及一些用来建立并配置不同网路层协定的网路控制协定(NetworkControlProtocols:NCP) 封装的机制(sche