5

Upon reboot and login, I want to check to see if a remote computer (10.1.0.53) is listening for UDP on port 2222. I have tried adding the following line to ~/.bashrc (later, I tried ~/.profile, with the same result):

nc -z -u -v 10.1.0.53 2222

Upon reboot, I get the message:

nc: connect to 10.1.0.53 port 2222 (UDP) failed: Network is unreachable

If I immediately try source .bashrc at the prompt, it succeeds and outputs:

Connection to 10.1.0.53 2222 port [udp/*] succeeded!

How do I make netcat wait until the network is reachable? (10.1.0.53 is listening the entire time).

0

1 Answer 1

5

Assuming you are using Raspbian, you can use raspi-config to delay boot until the network is up.

start raspi-config with the following:

sudo raspi-config

then select option 4 Wait for network at boot

then select Slow Wait for network connection before completing boot

click Ok

Then Finish

Finally reboot.

5
  • 1
    Is it possible to edit a file by hand instead of running raspi-config? Apr 11, 2018 at 23:42
  • yes, check the raspi-config source that is all it is doing. though raspi-config is easier and far less prone to error. Apr 11, 2018 at 23:44
  • What is this option doing under the hood? Apr 12, 2018 at 14:19
  • Scratch user here, I can't seem to find the option on raspi-config - but if you click on the Raspberry Pi symbol on the taskbar (application menu) and then 'Preferences' -> 'Raspberry Pi Configuration' you can see the option 'wait for network' raspberrypi.org/blog/latest-raspbian-update
    – Dante
    Sep 23, 2018 at 15:13
  • 1
    @JasonFloyd The files raspi-config modifies are shown in this part of the code: github.com/RPi-Distro/raspi-config/blob/…. Alternatively, you can avoid modifying files manually or having to interact with raspi-config by running raspi-config nonint do_boot_wait 0
    – davidjb
    Apr 18, 2019 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.