Run a command at boot

Hello all.
I am currently looking for a way to configure my Fedora 36 workstation to begin pinging the gateway continuously at boot time. has anyone else had any success running new commands at start time could help?
thanks in advance. :sunglasses:


At boot time do you mean once logged in to GNOME or during the boot process?

1 Like

Wow. Pinging the gateway continuously will consume an inordinate amount of unnecessary bandwidth both on the interface and on the gateway.

It is easy to write a script to do what you ask. It is also easy to create a crontab entry to do the same with the output going to a log file so you can check it whenever needed.

A crontab entry could run your script or run the command directly.

It is also possible with gnome to configure an app to launch when you log in.

1 Like

at boot time, I want to start the ping as soon as the computer gets an address from the router.

What are you trying to achieve with this?

its a little old trick i learnt from my friends in networking. its on the internal network of the modem with the wifi etc so it shouldn’t matter if I ping the gateway of the workstation at near the interface speed.

my concern is that if I create a command to run continuously with crontab will it stop at boot time and just keep running that command?

An old trick you learned from friends in networking???
What is the benefit to be gained?

Any time you have a ping running it will consume network resources and will impact the ability for other apps to use the network. It may possibly be negligible in your opinion, but also could potentially slow down all network traffic on the local LAN.

Any experienced network admin would tell you that a short ping is acceptable, but a continuous ping is not normally responsible behavior. On a corporate network the admins would quickly be tracking down the user doing such a trick. Your ‘friends’ IMHO don’t seem to be giving you very good advice. The only similar ‘trick’ I have ever seen is referred to as a ‘ping flood’ and that is totally verbotten. It swamps the network and slows everything down to a standstill.

While I certainly do not care if you shoot your own foot with this behavior on your own local LAN, you really should know if there is a benefit and what that benefit is, as well as understand the potential negative consequences before doing so.

I am in doubt too about the benefit of this, but I have to admit that the PfSense firewall does the same. But in this case, it is listening to the ping responses to evaluate availability of the router and performance monitoring. Anyhow, you can limit the impact of the system by using e.g. “ping -i 30” which sends a ping each 30 seconds. But I do not think that, even with a WiFi connection, there is any need for keep-alive pings. Started from cron, it runs in background and only fills up your mail spool (cron output is mailed).

There are cases where keep-alive pings are necessary: e.g. VPN behind a NAT router. If there is no activity, the return channel is closed and access from the remote site is lost. A ping with e.g. 30 second interval keeps it open. OpenVPN and Wireguard offer configuration options to take care of this.

Once upon a time I had to use something like that, but there was no constant pinging.
I did a job for a contractor who was tasked with deploying automation systems controlling dams and pumping stations. Being the miserly bastard that he was, instead of buying the professional equipment that was required for interconnections over a 3G network, he bought 20€ consumer routers, paired with 15€ 3G dongles. These dongles had a nasty firmware bug and after a while they would hang and had to be re-initialized, i.e. by rebooting the router. Since most of them were installed in remote locations, it wasn’t practical to have someone go over there and do that by hand. I wrote a script that pinged two high-availability external hosts, three times each, every 10 minutes (an acceptable interval for the whole system) and if no ping got a response, the router was rebooted. The script was set to run via a cron job.
That said, I cannot imagine another scenario were such a solution would be the most appropriate one, but necessity is the mother of invention…

I have this question too – where best to run a command at boot time.


Create a systemd service unit.
sudo nano /etc/systemd/system/endlessping.service

Content of such file.

Description=endless ping

ExecStart=/usr/bin/ping -i 5
ExecStop=/bin/kill $MAINPID


Let systemd learn about the new service
sudo systemctl daemon-reload

Enable and start the service
sudo systemctl enable endlessping --now

ExecStart and ExecStop could contain your script. Please read systemd documentation (i.e. systemd.service)

1 Like

Great! Thank you for the example and pointer for more reading. It’s just what I need to begin experimenting on a personal project.

Interestingly enough, on the International Space Station we have to run a continuous ping from a device in one module to a device in another module to keep a piece of network equipment we don’t manage passing data properly. It seems it otherwise has problems managing its arp table and floods the network with arp packets which causes all sorts of congestion which blocks the cyclic data for dozens of devices, creating a cacophony of alarms in the control center.