История изменений
Исправление achilles_85, (текущая версия) :
Соединение модема с провом поднимаю так
[Unit]
Description=Huawei USB modem auto-connect
BindsTo=dev-huawei_mobile_tty.device
After=dev-huawei_mobile_tty.device
[Service]
Type=oneshot
StandardOutput=file:/dev/huawei_mobile_tty
StandardError=journal
EnvironmentFile=/etc/huawei-mobile-helper.conf
ExecStart=/usr/bin/huawei-mobile-helper --ndisdup
RemainAfterExit=false
[Install]
WantedBy=dev-huawei_mobile_tty.device
Настраиваю интерфейс так
cat /etc/systemd/network/wwan0.network
[Match]
Name = wwan0
[Network]
DHCP = ipv4
wwan0 это LTE модем, в зависимости от базовой станции получает адрес то из 10.0.0.0/8, то 100.0.0.0/8, может еще что, это то что я видел. У меня задача стоит такая: если поменяется диапазон, то удалить-добавить маршруты из скрипта
#!/bin/bash
# LTE
IF1=wwan0
IF1_IP=`ip addr | grep $IF1 | awk -F"/" '/inet/{ print gensub (/.* /,"","g",$1)}'`
IF1_GW_IP=`ip route | awk '/default.*'$IF1'/ { print $3 }'`
IF1_NET=`ip route | grep kernel | awk '/'$IF1_IP'/ { print $1 }'`
# Local net
IF3=eth0
IF3_IP=`ip addr | grep $IF3 | awk -F"/" '/inet/{ print gensub (/.* /,"","g",$1)}'`
IF3_GW_IP=`ip route | awk '/'$IF3'/ { print $9 }'`
IF3_NET=`ip route | awk '/'$IF3'/ { print $1 }'`
case "$1" in
"ifup")
ip route add $IF1_NET dev $IF1 src $IF1_IP table LTE
ip route add default via $IF1_GW_IP table LTE
ip route add $IF1_NET dev $IF1 src $IF1_IP
ip route add default via $IF1_GW_IP
ip route add $IF3_NET dev $IF3 table LTE
ip route add $IF3_NET dev $IF3 table WG
ip route add $IF1_NET dev $IF1 table WG
ip route add 127.0.0.0/8 dev lo table LTE
ip route add 127.0.0.0/8 dev lo table WG
ip rule add from $IF1_IP table LTE
ip rule add from all fwmark 400 table WG
;;
"ifdown")
ip route delete $IF1_NET dev $IF1 src $IF1_IP table LTE
ip route delete default via $IF1_GW_IP table LTE
ip route delete $IF1_NET dev $IF1 src $IF1_IP
ip route delete default via $IF1_GW_IP
ip route delete $IF3_NET dev $IF3 table LTE
ip route delete $IF3_NET dev $IF3 table WG
ip route delete $IF1_NET dev $IF1 table WG
ip route delete 127.0.0.0/8 dev lo table LTE
ip route delete 127.0.0.0/8 dev lo table WG
ip rule delete from $IF1_IP table LTE
ip rule delete from all fwmark 400 table WG
;;
*)
echo "Failed"
exit 1
;;
esac
cat /etc/systemd/system/iproute2@.service
[Unit]
Description=iproute2 (%i)
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/conf.d/iproute2/%i/route ifup
ExecStop=/etc/conf.d/iproute2/%i/route ifdown
[Install]
WantedBy=sys-subsystem-net-devices-%i.device
stop iproute2@wwan0
start iproute2@wwan0
Исправление achilles_85, :
Соединение модема с провом поднимаю так
[Unit]
Description=Huawei USB modem auto-connect
BindsTo=dev-huawei_mobile_tty.device
After=dev-huawei_mobile_tty.device
[Service]
Type=oneshot
StandardOutput=file:/dev/huawei_mobile_tty
StandardError=journal
EnvironmentFile=/etc/huawei-mobile-helper.conf
ExecStart=/usr/bin/huawei-mobile-helper --ndisdup
RemainAfterExit=false
[Install]
WantedBy=dev-huawei_mobile_tty.device
Настраиваю интерфейс так
cat /etc/systemd/network/wwan0.network
[Match]
Name = wwan0
[Network]
DHCP = ipv4
wwan0 это LTE модем, в зависимости от базовой станции получает адрес то из 10.0.0.0/8, то 100.0.0.0/8, может еще что, это то что я видел. У меня задача стоит такая: если поменяется диапазон, то удалить-добавить маршруты из скрипта
#!/bin/bash
# LTE
IF1=wwan0
IF1_IP=`ip addr | grep $IF1 | awk -F"/" '/inet/{ print gensub (/.* /,"","g",$1)}'`
IF1_GW_IP=`ip route | awk '/default.*'$IF1'/ { print $3 }'`
IF1_NET=`ip route | grep kernel | awk '/'$IF1_IP'/ { print $1 }'`
# Local net
IF3=eth0
IF3_IP=`ip addr | grep $IF3 | awk -F"/" '/inet/{ print gensub (/.* /,"","g",$1)}'`
IF3_GW_IP=`ip route | awk '/'$IF3'/ { print $9 }'`
IF3_NET=`ip route | awk '/'$IF3'/ { print $1 }'`
case "$1" in
"ifup")
ip route add $IF1_NET dev $IF1 src $IF1_IP table LTE
ip route add default via $IF1_GW_IP table LTE
ip route add $IF1_NET dev $IF1 src $IF1_IP
ip route add default via $IF1_GW_IP
ip route add $IF3_NET dev $IF3 table LTE
ip route add $IF3_NET dev $IF3 table WG
ip route add $IF1_NET dev $IF1 table WG
ip route add 127.0.0.0/8 dev lo table LTE
ip route add 127.0.0.0/8 dev lo table WG
ip rule add from $IF1_IP table LTE
ip rule add from all fwmark 400 table WG
;;
"ifdown")
ip route delete $IF1_NET dev $IF1 src $IF1_IP table LTE
ip route delete default via $IF1_GW_IP table LTE
ip route delete $IF1_NET dev $IF1 src $IF1_IP
ip route delete default via $IF1_GW_IP
ip route delete $IF3_NET dev $IF3 table LTE
ip route delete $IF3_NET dev $IF3 table WG
ip route delete $IF1_NET dev $IF1 table WG
ip route delete 127.0.0.0/8 dev lo table LTE
ip route delete 127.0.0.0/8 dev lo table WG
ip rule delete from $IF1_IP table LTE
ip rule delete from all fwmark 400 table WG
;;
*)
echo "Failed"
exit 1
;;
esac
cat /etc/systemd/system/iproute2@.service
[Unit]
Description=iproute2 (%i)
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/conf.d/iproute2/%i/route ifup
ExecStop=/etc/conf.d/iproute2/%i/route ifdown
[Install]
WantedBy=sys-subsystem-net-devices-%i.device
stop iproute2@wwan0
start iproute2@wwan0
Исходная версия achilles_85, :
Соединение модема с провом поднимаю так
[Unit]
Description=Huawei USB modem auto-connect
BindsTo=dev-huawei_mobile_tty.device
After=dev-huawei_mobile_tty.device
[Service]
Type=oneshot
StandardOutput=file:/dev/huawei_mobile_tty
StandardError=journal
#TTYPath=/dev/huawei_mobile_tty
EnvironmentFile=/etc/huawei-mobile-helper.conf
ExecStart=/usr/bin/huawei-mobile-helper --ndisdup
RemainAfterExit=false
[Install]
WantedBy=dev-huawei_mobile_tty.device
Настраиваю интерфейс так
cat /etc/systemd/network/wwan0.network
[Match]
Name = wwan0
[Network]
DHCP = ipv4
wwan0 это LTE модем, в зависимости от базовой станции получает адрес то из 10.0.0.0/8, то 100.0.0.0/8, может еще что, это то что я видел. У меня задача стоит такая: если поменяется диапазон, то удалить-добавить маршруты из скрипта
#!/bin/bash
# LTE
IF1=wwan0
IF1_IP=`ip addr | grep $IF1 | awk -F"/" '/inet/{ print gensub (/.* /,"","g",$1)}'`
IF1_GW_IP=`ip route | awk '/default.*'$IF1'/ { print $3 }'`
IF1_NET=`ip route | grep kernel | awk '/'$IF1_IP'/ { print $1 }'`
# Local net
IF3=eth0
IF3_IP=`ip addr | grep $IF3 | awk -F"/" '/inet/{ print gensub (/.* /,"","g",$1)}'`
IF3_GW_IP=`ip route | awk '/'$IF3'/ { print $9 }'`
IF3_NET=`ip route | awk '/'$IF3'/ { print $1 }'`
case "$1" in
"ifup")
ip route add $IF1_NET dev $IF1 src $IF1_IP table LTE
ip route add default via $IF1_GW_IP table LTE
ip route add $IF1_NET dev $IF1 src $IF1_IP
ip route add default via $IF1_GW_IP
ip route add $IF3_NET dev $IF3 table LTE
ip route add $IF3_NET dev $IF3 table WG
ip route add $IF1_NET dev $IF1 table WG
ip route add 127.0.0.0/8 dev lo table LTE
ip route add 127.0.0.0/8 dev lo table WG
ip rule add from $IF1_IP table LTE
ip rule add from all fwmark 400 table WG
;;
"ifdown")
ip route delete $IF1_NET dev $IF1 src $IF1_IP table LTE
ip route delete default via $IF1_GW_IP table LTE
ip route delete $IF1_NET dev $IF1 src $IF1_IP
ip route delete default via $IF1_GW_IP
ip route delete $IF3_NET dev $IF3 table LTE
ip route delete $IF3_NET dev $IF3 table WG
ip route delete $IF1_NET dev $IF1 table WG
ip route delete 127.0.0.0/8 dev lo table LTE
ip route delete 127.0.0.0/8 dev lo table WG
ip rule delete from $IF1_IP table LTE
ip rule delete from all fwmark 400 table WG
;;
*)
echo "Failed"
exit 1
;;
esac
cat /etc/systemd/system/iproute2@.service
[Unit]
Description=iproute2 (%i)
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/conf.d/iproute2/%i/route ifup
ExecStop=/etc/conf.d/iproute2/%i/route ifdown
[Install]
WantedBy=sys-subsystem-net-devices-%i.device
stop iproute2@wwan0
start iproute2@wwan0