Tuesday, October 3, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  8] [ 0]  / answers: 1 / hits: 5062  / 7 Months ago, thu, march 9, 2023, 11:42:07

I'm trying to setup a Ubuntu hardware firewall (just for fun :D) and I was wondering if Ubuntu's network scripts could automatically reconnect to the wired interface (eth0) when the connection is dropped?

My ISP's modem is pretty bad and requires a reset once in a while. It's annoying to go to basement with a keyboard and blindly login and type /etc/init.d/networking restart.

More From » networking


Have a look at cron and crontab. What you need to do is create a script that you can insert into cron that...

  • checks every x minutes if the connection is down.

    • if is not down do nothing.

    • if it is down reconnect.

Example of such a script:


( ! ping -c1 $IP_ADRESS >/dev/null 2>&1 ) && service network restart >/dev/null 2>&1

Put this in a scrip (set the IP adress to what you want to check), make it executable with

chmod +x /usr/local/bin/check_network

and run the script from crontab. You can edit this line into it with the command crontab -e:

*/2 * * * * root /usr/local/bin/check_network

  • */2 makes it check 30 times an hour.

[#44446] Friday, March 10, 2023, 7 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 407
Total Questions: 127
Total Answers: 121

Location: Saint Helena
Member since Fri, Mar 26, 2021
3 Years ago