ホームインターネット:Bird Routing Daemonに基づく2つ(およびそれ以上)のプロバイダーのルーティング

おそらく、ホームインターネットの多くのユーザーは、ホームネットワーク内の2つ以上のインターネットチャネルを並列化する方法に直面していました。

この問題は、ハードウェア(安価または高価な機器を使用)とソフトウェアの両方で解決できます。

選択するルーティングモデル RIP / OSPF / BGPはすぐにドロップできます。これはホームインターネットであり、プロバイダー側​​で無料でサポートしたくないことが確実だからです(私の場合は検証済みです)。

鳥を選んだ。



したがって、開始位置:





私のネットワーク構成:





私はapt好きですが、結局のところ、aptバージョンにはかなり古いバージョンのbird(1.2.5-1)があり、マルチパスのサポートはありません。

あなたの手でそれを収集する必要があります。 debianをslackwareにしないために、事前に故意にフレームを省略しています。



# mkdir -p /usr/local/src/bird && cd /usr/local/src/bird # wget ftp://bird.network.cz/pub/bird/bird-1.3.8.tar.gz # tar xf bird-1.3.8.tar.gz # cd bird-1.3.8 # ./configure --prefix=/usr --sysconfdir=/etc/bird --localstatedir=/var # make # make install
      
      







結局のところ、Debianのスタートアップスクリプトはありません。

起動スクリプトを生成します(aptの同じ古いパッケージから取得し、わずかに修正しました) /etc/init.d/birdに次の内容を追加します。



 #! /bin/sh ### BEGIN INIT INFO # Provides: bird # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 ### END INIT INFO # Author: Ondřej Surý <ondrej@sury.org> # # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="Internet routing daemon" NAME=bird DAEMON=/usr/sbin/$NAME DAEMON_ARGS="-c /etc/bird/bird.conf" #PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions # # Function that starts the daemon/service # do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon --start --quiet --name $NAME --exec $DAEMON --test > /dev/null \ || return 1 start-stop-daemon --start --quiet --name $NAME --exec $DAEMON -- \ $DAEMON_ARGS \ || return 2 # Add code here, if necessary, that waits for the process to be ready # to handle requests from services started subsequently which depend # on this one. As a last resort, sleep for some time. } # # Function that stops the daemon/service # do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --name $NAME --exec $DAEMON RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 # Wait for children to finish too if this is a daemon that forks # and if the daemon is only ever run from this initscript. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --name $NAME --exec $DAEMON [ "$?" = 2 ] && return 2 return "$RETVAL" } # # Function that sends a SIGHUP to the daemon/service # do_reload() { # # If the daemon can reload its configuration without # restarting (for example, when it is sent a SIGHUP), # then implement that here. # start-stop-daemon --stop --signal 1 --quiet --name $NAME --exec $DAEMON return 0 } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; reload|force-reload) # # If do_reload() is not implemented then leave this commented out # and leave 'force-reload' as an alias for 'restart'. # log_daemon_msg "Reloading $DESC" "$NAME" do_reload log_end_msg $? ;; restart) log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 exit 3 ;; esac
      
      







起動スクリプトの準備ができたら、自動起動に追加します。

 # chmod +x /etc/init.d/bird # update-rc.d bird enable update-rc.d: using dependency based boot sequencing
      
      







ログファイル用のディレクトリを作成します。

 # mkdir /var/log/bird
      
      







それでは、鳥自体の設定を始めましょう。



始めるには、bakapimの元の構成を作成し、新しい構成を作成します。

 # cd /etc/bird # mv bird.conf bird-orig.conf # :> bird.conf
      
      







次に、編集用に開きます。

 # # Logging # #  . # all  { debug, trace, info, remote, warning, error, auth, fatal, bug } # ,    2      (  ,     ): # log "/var/log/bird/debug.log" { debug }; # log "/var/log/bird/warning.log" { warning }; log "/var/log/bird/bird.log" all; # Router ID: #   IP-   ,      ( !) . router id 192.168.254.254; # # Debugging # #  : # all | off | { states, routes, filters, interfaces, events, packets } debug protocols { routes, interfaces }; # # Protocols # #  ,        (   -  eth0  eth2) protocol direct { interface "eth0", "eth2"; } # # Tables # #    #   ISP1  ISP2: table ISP_ISP1; table ISP_ISP2; #  "": table other; #  "master" -    (main). ,  main ! table master; # # Protocol 'static' # protocol static { table ISP_ISP1; description "Home internet ISP1"; check link on; preference 100; route 0.0.0.0/0 via 10.10.10.1; } protocol static { table ISP_ISP2; description "Home internet ISP2"; check link on; preference 150; route 0.0.0.0/0 via 172.17.5.1; } protocol static { table other; description "Other custom static routes"; preference 200; #    (   )  /etc/bird/static_route.d/ include "/etc/bird/static_route.d/*.conf"; } protocol static { table master; description "Common Table"; #   ,    default- route 0.0.0.0/0 multipath via 10.10.10.1 via 172.17.5.1; } # # Protocol 'kernel' # #      'debug all'.        . #    'all'  .   ,  -    ,    . # #  'persist' -   bird  ,  ,   (  "") bird. #  'learn' - ,  bird  ""  ,      #   10/11/254 (  ,   10, 11, 254). # protocol kernel { table ISP_ISP1; persist; learn; scan time 20; kernel table 10; export all; # debug all; } protocol kernel { table ISP_ISP2; persist; learn; scan time 20; kernel table 11; export all; # debug all; } protocol kernel { table master; persist; learn; scan time 20; kernel table 254; export all; # debug all; } # # Protocol 'pipe. # #   (default). #   ,     master    ,    ,   ISP_ISP1, ISP_ISP2  other. protocol pipe { table master; peer table ISP_ISP1; peer table ISP_ISP2; peer table other; import all; # debug all; }
      
      







次に、手動設定用のディレクトリを作成し、たとえば、いくつかのルートを追加します。



 # mkdir /etc/bird/static_route.d/ # cat << EOF >/etc/bird/static_route.d/ISP1_LAN.conf route 10.0.5.0/24 via 10.10.10.1; route 175.5.25.0/27 via 10.10.10.1; #   " ", ,     IP  ISP1 EOF # cat << EOF >/etc/bird/static_route.d/ISP2_LAN.conf route 194.22.253.23/27 via 172.17.5.1; #   " ", ,     IP  ISP2 route 5.9.0.0/16 via 172.17.5.1; #   " ", ,     IP  ISP2 EOF
      
      







これで、鳥のセットアップは完了です。

それでは、ルーティングテーブルのセットアップに移りましょう。



/ etc / iproute2 / rt_tablesにテーブルを追加します。

 # cat << EOF >>/etc/iproute2/rt_tables 10 ISP1 11 ISP2 EOF
      
      







ここで、ISP1ネットワークから要求するときに、パケットが別のインターフェイスを経由せずにISP1に戻ることを確認する必要があります。

これを行うには、IPルールを追加します:

これを行うには、iprulesスクリプトを作成します。



コード/etc/network/if-up.d/iprules:

 #!/bin/bash ISP1_NETWORKS="10.0.5.0/24 175.5.25.0/27" ISP2_NETWORKS="194.22.253.23/27 5.9.0.0/16" if [ "${LOGICAL}" = "eth0" ]; then for NET in ${ISP1_NETWORKS}; do ip ru a from ${NET} table ISP1 2>/dev/null 1>/dev/null done fi if [ "${LOGICAL}" = "eth2" ]; then for NET in ${ISP2_NETWORKS}; do ip ru a from ${NET} table ISP2 2>/dev/null 1>/dev/null done fi
      
      







コード/etc/network/if-down.d/iprules:

 #!/bin/bash ISP1_NETWORKS="10.0.5.0/24 175.5.25.0/27" ISP2_NETWORKS="194.22.253.23/27 5.9.0.0/16" if [ "${LOGICAL}" = "eth0" ]; then for NET in ${ISP1_NETWORKS}; do ip ru d from ${NET} table ISP1 2>/dev/null 1>/dev/null done fi if [ "${LOGICAL}" = "eth2" ]; then for NET in ${ISP2_NETWORKS}; do ip ru d from ${NET} table ISP2 2>/dev/null 1>/dev/null done fi
      
      







チェックボックス+ x:

 # chmod +x /etc/network/if-{up,down}.d/iprules
      
      







今、すべての反論を実行します:



コマンドをコピーアンドペーストしないように、よりトリッキーにします。

 # LOGICAL=eth0 /etc/network/if-up.d/iprules # LOGICAL=eth2 /etc/network/if-up.d/iprules
      
      







打ち上げ鳥:

 # invoke-rc.d bird start
      
      







私たちはチェックします:

 # ip r 10.0.5.0/24 via 10.10.10.1 dev eth0 proto bird 175.5.25.0/27 via 10.10.10.1 dev eth0 proto bird 194.22.253.23/27 via 172.17.5.1 dev eth2 proto bird 5.9.0.0/16 via 172.17.5.1 dev eth2 proto bird 10.10.10.0/24 dev eth0 proto kernel scope link src 10.10.10.106 172.17.5.0/24 dev eth2 proto kernel scope link src 172.17.5.105 192.168.254.0/24 dev eth1 proto kernel scope link src 192.168.254.254 default proto bird nexthop via 10.10.10.1 dev eth0 weight 1 nexthop via 172.17.5.1 dev eth2 weight 1
      
      







ここで、コード引き出し 、ISP1(eth0)からネットワークケーブルを取り外し、変更内容を確認します。

 # ip r | grep -E "(default|nexthop)" default proto bird nexthop via 10.10.10.1 dev eth0 weight 1 dead nexthop via 172.17.5.1 dev eth2 weight 1
      
      







つまり、プロバイダーの1つが誤って切断され、トラフィックが別のプロバイダーを通過した場合、切断されたプロバイダーは20秒ごとに監視され(カーネルプロトコルのスキャン時間20オプションを参照)、表示されると自動的に「デッド」が削除されます。



結論として:同様に、10個のプロバイダーを追加できます。



All Articles