HOWTO: multiple default routes

來源:互聯網
上載者:User

標籤:des   http   ar   io   color   os   sp   for   on   

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.254iface 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 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
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)

HOWTO: multiple default routes

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.