Answer the question
In order to leave comments, you need to log in
How to dynamically change the default gateway?
There are a lot of lte modems. It is necessary to alternately work with each modem (drive traffic without turning off the rest).
Each modem, when connected, creates an eth interface with an ip address of 192.168.8.100 and is a gateway 192.168.8.1. And configures all settings via dhcp. That is, we have a bunch of identical network interfaces with the same ip-addresses and the same default gateways.
Manually change ip-addresses on network interfaces according to the following scheme.
Next, I work as follows with modems:
for iface in network_list:
os.system("sudo ip route flush all") #удаляем все маршруты
#добавляем маршрут через текущий интерфейс
os.system("sudo route add default gw 192.168.8.1 " + iface)
#добавляем DNS-сервр
os.system("sudo bash -c 'echo nameserver 192.168.8.1 > /etc/resolv.conf'")
#что-то делаем нужное нам
SpeedTest()
SaveResult()
Answer the question
In order to leave comments, you need to log in
Each modem, when connected, creates an eth interface with an ip address of 192.168.8.100 and is a gateway 192.168.8.1. And configures all settings via dhcp.Perhaps this parameter can be changed somehow - configure the modem so that it makes other IP addresses on a USB connection (EVPOCHYA).
os.system("sudo bash -c 'echo nameserver 192.168.8.1 > /etc/resolv.conf'")Why overwrite nameserver every time?
For some reason, the network does not always rise. And most importantly, it would not work stably. And sometimes this approach works, sometimes it doesn't.If you do this remotely (via SSh), then the commands to change the settings should. in a package (command file); and the package must be executed separately from the terminal (nohup for the entire package. If not, then the execution of commands may be interrupted, especially if some message is output to the terminal.
I'll take any advice!Raise several virtual machines. Forward your USB port to each. And test the speed separately for each virtual machine.
And if you don’t reinvent the wheel and use almost any Internet gateway (pfSense / X / Kerio) on which you can already set up a multivan and, depending on the need, switch between networks.
Let's start from the beginning, why do you need this art, it seems to me that everything can be solved in a different way.
What and why are you doing. Why one interface? etc.
Perhaps a much more efficient solution will be proposed
Maybe this approach is right for you?
Isolate an application with an IP address from a VPN other...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question