Wait for right IP / Restart network after boot

Hi,
I have a quite simple problem, but can’t figure it out myself, I appreciate any help.

I have a Turris Omnia 2020. As I have fiber and the ISP doesn’t allow to go directly in the Turris router, I have their super old router/modem from Genexisas bridge in front of it.
Every now and then there is a blackout, reboot, new IP or I simply work with the electricity. Then I get a new public IP (or sometimes the same IP) from the Genexis, but it comes with a delay. First it’s a 192.168… address and after a while it switches to the public IP, like 128.xxx.xxx.xxx

The Turris boots faster and gets this 192.xxx… address, doesn’t immediately care for the IP and takes the 192.168 without changing it along the way.

Is there a way to check every 15 minutes as well as 3 minutes after boot for the IP, if it starts with “192.168.” or not and reboot the network? Or any other, smarter way to get the public IP and not the local one, that is completely offline.
I tried crontab in LuCI, but my googled command doesn’t work.

Currently I have to manually reboot the router to go online again.

Thank you so much for your help!

You can use info from https://www.linuxtrainingacademy.com/determine-public-ip-address-command-line-curl/ to create cron script…

Hi, thank you for your link. Unfortunately it doesn’t really help me.
When the router is offline, I don’t have the possibility to check my public IP, so I have to check my WAN IP, but that’s not as straightforward as I thought… My local subnet is also starting with 192.168.
So when just filtering for 192.168. I always get a positive result - simply from the other devices connected to the router.

Is there a way to filter for the WAN interface?

Maybe I dont understand it correctly, but when the device from the provider is in bridge mode, DHCP should be running on the Turris Omnia (the same is in my case).
But I have no problem when device from internet provider is disconnected, there is just no internet, but IP addresses in my LAN are given from the TO.

I agree, it doesn’t make sense, but this old ISP router is really weird and I’d love to use the SPF-slot in the Omnia instead… Only two of the ethernet ports in the ISP router are actually usable for a public IP, the rest isn’t, even in bridge mode. I think there’s some other things happening in the background. Maybe because it’s (passive) fiber?

However I found the solution, just by luck I guess, ChatGPT helped as well. Maybe this helps someone with the same issue:

#!/bin/bash

# Get the IP address without "addr:" prefix
ip_address=$(ifconfig eth2 | grep 'inet ' | awk '{sub(/addr:/, ""); print $2}' | cut -c 1-8)

# Check if the IP address starts with "192.168."
if [[ "$ip_address" == "192.168."* ]]; then
    echo "IP address starts with 192.168."

    # Restart the network
    echo "Restarting network..."
    sudo  /etc/init.d/network restart
else
    echo "IP address does not start with 192.168."
fi

Then I added two lines to crontab. One for checking every 15 minutes, in case the ISP router restarts for some reason and throws a 192.168...-IP, the second one 3 minutes after boot.

I was trying for a while to only restart eth2, but ifdown eth2 && ifup eth2 didn’t work…

Thank you @jada4p and @michalko58 for your help!

Well, in my gpon convertor, only one port is used for public IP. SPF is no-go for 99% of ISPs. Maybe, you can ask for newer convertor exchnage…

But, if your solution is working, then you have sold it :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.