होम इंटरनेट: बर्ड रूटिंग डेमॉन के आधार पर दो (और अधिक) प्रदाता राउटिंग

शायद, होम इंटरनेट के कई उपयोगकर्ताओं का सामना घर नेटवर्क में दो या अधिक इंटरनेट चैनलों को समानांतर करने के तरीके से किया गया था।
इस समस्या को दोनों हार्डवेयर (किसी सस्ते या महंगे उपकरण का उपयोग करके) और सॉफ्टवेयर से हल किया जा सकता है।
क्या रूटिंग मॉडल चुनना है? आप आरआईपी / ओएसपीएफ / बीजीपी को तुरंत छोड़ सकते हैं, क्योंकि यह होम इंटरनेट है और यह सुनिश्चित करने से अधिक है (मेरे मामले में, यह सत्यापित किया गया है) कि आप मुफ्त में प्रदाता की तरफ से समर्थन नहीं करना चाहेंगे।
पक्षी के लिए चुना गया।

तो, प्रारंभिक स्थिति:


मेरा नेटवर्क कॉन्फ़िगरेशन:


मैं एक उपयुक्त प्रेमी हूं, लेकिन जैसा कि यह निकला, उपयुक्त संस्करण में पक्षी (1.2.5-1) का एक पुराना संस्करण है और कोई बहुपथ समर्थन नहीं है।
इसे अपने हाथों से इकट्ठा करना होगा। मैं जानबूझकर किसी भी लौ को पहले से छोड़ देता हूं, डेबियन को स्लैकवेयर में कैसे नहीं बदल सकता।

# 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 


जैसा कि यह निकला, डेबियन के लिए कोई स्टार्टअप स्क्रिप्ट नहीं है।
हम एक स्टार्टअप स्क्रिप्ट उत्पन्न करते हैं (जो उपयुक्त रूप से उसी पुराने पैकेज से ली गई है और थोड़ा सही किया गया है) /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 


अब चलो पक्षी को ही कॉन्फ़िगर करना शुरू करें।

आरंभ करने के लिए, मूल कॉन्फ़िगर करें और नया बनाएँ:
 # 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 पर वापस जाते हैं, न कि किसी अन्य इंटरफ़ेस के माध्यम से।
ऐसा करने के लिए, आईपी नियम जोड़ें:
ऐसा करने के लिए, 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 


यही है, यदि प्रदाताओं में से कोई गलती से डिस्कनेक्ट हो जाता है, तो ट्रैफ़िक दूसरे के माध्यम से चला जाता है, डिस्कनेक्ट किए गए प्रदाता की हर 20 सेकंड पर निगरानी की जाएगी (कर्नेल प्रोटोकॉल में स्कैन समय 20 विकल्प देखें) और प्रकट होने पर स्वचालित रूप से 'मृत' को हटा देगा।

निष्कर्ष में: उसी तरह, आप 10 प्रदाताओं को जोड़ सकते हैं।

Source: https://habr.com/ru/post/In160047/


All Articles