-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


Linux- NetGWM

, 08 2017 . 08:30 +
. , , Linux.



Open Source- NetGWM . , , .

NetGWM?


Linux, iproute2, :
  • : 2 .
  • .
  • (ip rule), (, / iptables).
  • ifupdown- .

linux policy routing. , , NetGWM:
  1. , .
  2. 3 , , .
  3. . , , - . ifupdown-, .
  4. -. , . . , , ? , , , , VPN- , . . .

, 4 : 2 , . . NetGWM.

GitHub


NetGWM (Network GateWay Manager) , Python GNU GPL v3. driusha ( ).

GitHub, .

GitHub:
##     :
##  iproute2, conntrack,  python-yaml
##    :
$ git clone git://github.com/flant/netgwm.git netgwm
##   (  ):
$ cd netgwm && sudo make install
##    ,    NetGWM
$ sudo sh -c "echo '100    netgwm_check' >> /etc/iproute2/rt_tables"
##   cron  root  netgwm   ,
##         
## (,   ):
$ sudo crontab -e
*/1 * * * * /usr/lib/netgwm/newtgwm.py

, DEB- NetGWM Ubuntu . Ubuntu 14.04 LTS :
##  :
$ sudo wget https://apt.flant.ru/apt/flant.trusty.common.list \
 -O /etc/apt/sources.list.d/flant.common.list
##  :
$ wget https://apt.flant.ru/apt/archive.key -O- | sudo apt-key add -
##  HTTPS-   ,     :
$ sudo apt-get install apt-transport-https
##      netgwm:
$ sudo apt-get update && sudo apt-get install netgwm

cron Ubuntu . . , netgwm, init- shell- /usr/bin/netgwm, , , /etc/default/netgwm INTERVAL ( ) netgwm.py.


NetGWM policy-, .

, 3 , , 1, 2, 3.

eth1, eth2, eth3. 88.88.88.88, 99.99.99.99, 100.100.100.100.

conntrack NetFilter. , , .

conntrack:
iptables -t mangle -A PREROUTING -i eth1 -m conntrack --ctstate NEW,RELATED -j CONNMARK --set-xmark 0x1/0x3
iptables -t mangle -A PREROUTING -i eth2 -m conntrack --ctstate NEW,RELATED -j CONNMARK --set-xmark 0x2/0x3
iptables -t mangle -A PREROUTING -i eth3 -m conntrack --ctstate NEW,RELATED -j CONNMARK --set-xmark 0x3/0x3
iptables -t mangle -A PREROUTING -j CONNMARK --restore-mark --nfmask 0xffffffff --ctmask 0xffffffff
iptables -t mangle -A OUTPUT -o eth1 -m conntrack --ctstate NEW,RELATED -j CONNMARK --set-xmark 0x1/0x3
iptables -t mangle -A OUTPUT -o eth2 -m conntrack --ctstate NEW,RELATED -j CONNMARK --set-xmark 0x2/0x3
iptables -t mangle -A OUTPUT -o eth3 -m conntrack --ctstate NEW,RELATED -j CONNMARK --set-xmark 0x3/0x3
iptables -t mangle -A OUTPUT -j CONNMARK --restore-mark --nfmask 0xffffffff --ctmask 0xffffffff
iptables -t mangle -A POSTROUTING -o eth1 -m conntrack --ctstate NEW,RELATED -j CONNMARK --set-xmark 0x1/0x3
iptables -t mangle -A POSTROUTING -o eth2 -m conntrack --ctstate NEW,RELATED -j CONNMARK --set-xmark 0x2/0x3
iptables -t mangle -A POSTROUTING -o eth3 -m conntrack --ctstate NEW,RELATED -j CONNMARK --set-xmark 0x3/0x3
iptables -t mangle -A POSTROUTING -j CONNMARK --restore-mark --nfmask 0xffffffff --ctmask 0xffffffff

2. . , /etc/network/interfaces post-up lo:

#!/bin/bash
 
/sbin/ip rule flush
 
# operator 1
/sbin/ip rule add priority 8001 iif eth1 lookup main
/sbin/ip rule add priority 10001 fwmark 0x1/0x3 lookup operator1
/sbin/ip rule add from 88.88.88.88 lookup operator1
 
# operator 2
/sbin/ip rule add priority 8002 iif eth2 lookup main
/sbin/ip rule add priority 10002 fwmark 0x2/0x3 lookup operator2
/sbin/ip rule add from 99.99.99.99 lookup operator2

# operator 3
/sbin/ip rule add priority 8002 iif eth3 lookup main
/sbin/ip rule add priority 10002 fwmark 0x3/0x3 lookup operator3
/sbin/ip rule add from 100.100.100.100 lookup operator3

3. /etc/iproute2/rt_tables:
#  :
255    local
254    main
253    default
0    unspec
#  ,   ( dpkg)  :
100  netgwm_check
#   ,     :
101    operator1
102    operator2
103    operator3

4. NetGWM. , netgwm.py /etc/netgwm/netgwm.yml, -c. :
#         
#   ()   . 1 -   
#  ,           
#      .      ( 
#    )      (  ).
#         
# /etc/iproute2/rt_tables
gateways:
  operator1: {ip: 88.88.88.88, priority: 1}
  operator2: {ip: 99.99.99.99, priority: 2}
  operator3: {ip: 100.100.100.100, priority: 3}
 
#     -,  
#  ( ) . 
#      ( ),
#   netgwm  ,   
min_uptime: 900
 
#   ,    netgwm 
#    .      
#     ,      , 
#    .   ,  netgwm  
#       ( AND)  
check_sites:
  - 8.8.8.8 # Google public DNS
  - 4.2.2.2 # Verizon public DNS

#   netgwm      
#  .          ..
#  ,    true,  netgwm 
#      
check_all_gateways: false

5. .
, /etc/netgwm/post-replace.d/*. 6 :
  • $1 ;
  • $2 IP NaN, ;
  • $3 NaN, ;
  • $4 NaN, ;
  • $5 IP NaN, ;
  • $6 NaN, .

( , , ..). shell, :
#!/bin/bash
# ,  :    netgwm
if [ "$4" = 'NaN' ] && [ "$5" = 'NaN' ]
 then
  STATE='start'
 else
  STATE='switch'
fi
#      
case $STATE in
 'start')
   /usr/bin/flant-integration --sms-send="NetGWM on ${HOSTNAME} has been started and now use gw: $1 - $2"
 ;;
 'switch')
   /usr/bin/flant-integration --sms-send="NetGWM on ${HOSTNAME} has switched to new gw: $1 - $2 from gw: $4 - $5"
 ;;
 *)
  /usr/bin/logger -t netgwm "Unknown NetGWM state. Try restarting service fo fix it."
 ;;
esac
exit

6. netgwm Ubuntu, DEB-:
$ sudo service netgwm start

NetGWM GitHub, cron , .


NetGWM /var/log/netgwm:
$ tail -n 3 /var/log/netgwm.log
2017-07-14 06:25:41,554 route replaced to: via 88.88.88.88
2017-07-14 06:27:09,551 route replaced to: via 99.99.99.99
2017-07-14 07:28:48,573 route replaced to: via 88.88.88.88

.

production


4 NetGWM 30+ Linux . . , , 2014 NetGWM 137 - .

, , . NetGWM Python, . , , NetGWM, GitHub feature request .


NetGWM , ( ) , .

NetGWM .

P.S. : Linux- , !
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/335030/

:  

: [1] []
 

:
: 

: ( )

:

  URL