WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: eth0 and (nodhcp vs. kill udhcpc) for use with a static ip address  (Read 6450 times)

Offline tohox

  • Newbie
  • *
  • Posts: 25
Hi,

I'm running 8beta3 and in order to start eth0 with a static IP I did the following:

- Edited bootlocal.sh to start a script called eth0.sh
- eth0.sh contained this:
Code: [Select]
#!/bin/sh
pkill udhcpc
ifconfig eth0 192.168.0.254 netmask 255.255.255.0 broadcast 192.168.0.255 up
route add default gw 192.168.0.1
echo nameserver 192.168.0.17 >> /etc/resolv.conf
- I then made eth0.sh executable
- Backed up and rebooted.

This worked as expected for several weeks but this morning after installing a package and backing up, the eth0 script was no longer able to set the static IP address. I then noticed that udhcpc was still running while it should have been killed by the script. Perhaps something changed in the boot order or timing and udhcpc is not up by the time the script tries to kill it?

Anyway, I decided to proceed differently and added nodhcp to cmdline.txt and removed pkill udhcpc from my script but this didn't seem to prevent the dhcp service from starting and I still couldn't set the static IP address unless I manually ran my script.

Some my questions are:
- Why can't my script kill the dhcp service anymore?
- What is the correct way of disabling dhcp and setting a static address?

Thanks!

Offline tohox

  • Newbie
  • *
  • Posts: 25
Re: eth0 and (nodhcp vs. kill udhcpc) for use with a static ip address
« Reply #1 on: August 05, 2016, 01:34:43 PM »
It turns out my script was still working but I had to move it closer to the end of bootlocal.sh. Still don't know why it stopped working in the first place though...

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1267
Re: eth0 and (nodhcp vs. kill udhcpc) for use with a static ip address
« Reply #2 on: August 05, 2016, 04:09:00 PM »
Yes, bootlocal can run before all of the hardware is detected.    Network is commonly not ready.   If you need to start something in bootlocal, you need to wait for the hardware to become responsive before continuing

An option is to add the    waitusb=5 to the commandline.    Or just check that eth0 exists before continuing your script


Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 722
Re: eth0 and (nodhcp vs. kill udhcpc) for use with a static ip address
« Reply #3 on: August 05, 2016, 05:55:31 PM »
Add nodhcp to cmdline to not start dhcp server.

Offline tohox

  • Newbie
  • *
  • Posts: 25
Re: eth0 and (nodhcp vs. kill udhcpc) for use with a static ip address
« Reply #4 on: August 08, 2016, 10:07:01 AM »
Yes, as mentioned above I did try adding nodhcp to cmdline.txt but it had no effect.

Does the position of the nodhcp flag within the cmdline have any importance? I put it at the very end.

I did take care not to insert any additional NL or CR in the line as I read it may cause problems.

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 722
Re: eth0 and (nodhcp vs. kill udhcpc) for use with a static ip address
« Reply #5 on: August 08, 2016, 11:11:57 AM »
Not any NL CR in line.
I always use nano -w to disable the auto(cr).

Offline andriusr

  • Newbie
  • *
  • Posts: 34
Re: eth0 and (nodhcp vs. kill udhcpc) for use with a static ip address
« Reply #6 on: August 08, 2016, 12:33:32 PM »
Instead of bootlocal.sh, it would be better to place ipconfig command into bootsync.sh . Then the system will wait until eth0 is available. This should be more reliable way to setup static IP.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1267
Re: eth0 and (nodhcp vs. kill udhcpc) for use with a static ip address
« Reply #7 on: August 08, 2016, 10:47:48 PM »
Instead of bootlocal.sh, it would be better to place ipconfig command into bootsync.sh . Then the system will wait until eth0 is available. This should be more reliable way to setup static IP.

Not always.   On a rpi, Ethernet is a USB device.   Usb items will occur when they become detected.   Bootsync may still run before Ethernet is up.