When no dhcp server answer, how can I force dhclient to use the static lease from dhclient.conf instead of a previous dhcp lease?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have a piece of equipment I would like to default to a specific IP address when no dhcp servers are available.



I have set the following static lease in /etc/dhcp/dhclient.conf:



timeout 30;

lease
interface "eth0";
fixed-address 192.168.1.254;
option subnet-mask 255.255.255.0;
option routers 127.0.0.1;
expire never;



It works, but eth0 will only get this IP when dhclient.eth0.leases and dhclient.leases in /var/lib/dhcp/ are empty.



Unless you guys have a good reason to advise against it, I would prefer if the static lease from dhclient.conf was assigned when a dhcp server doesn't reply instead of using old leases. It would make the troubleshooting process easier and allow some way to reach the equipment which is only accessible via ssh and has no display to print out the current ip.



I read through the dhclient manual and a lot of google search results but couldn't find a built in way or any suggestions on how to do this.



Solutions I thought of:



1-Empty dhclient.leases and set permissions so it can't be modified

2-Link dhclient.leases to /dev/null and set permissions so it can't be modified

3-Same as #1 but instead of setting up the static lease in dhclient.conf, manually add it to dhclient.leases before setting permissions.



Of course I will try those but please advise.



Thank you.










share|improve this question























  • I tested option #1 and set attributes using chattr -i which caused dhclient to give out errors about being unable to write to the dhcp.eth0.leases file but it wrote to it anyways even though the wait it read it seemed it wouldnt!
    – TCZ8
    Dec 15 '15 at 17:55










  • Just tested option #2 but didn't change its attributes as dhclient doesn't seem to care about respecting these. The good thing is It works and doesn't give errors. My only concern is making sure the soft link doesn't get replaced when dhclient decides it's time to rotate the file. I couldn't find any info on what triggers the file to be replaced. So I have no clue what and when it will happen. How am I going to test this? Is waiting and hoping for the best my only option?
    – TCZ8
    Dec 15 '15 at 18:01











  • I meant, I gave no clue if and when it will happen. So far so good.
    – TCZ8
    Dec 21 '15 at 14:32














up vote
1
down vote

favorite












I have a piece of equipment I would like to default to a specific IP address when no dhcp servers are available.



I have set the following static lease in /etc/dhcp/dhclient.conf:



timeout 30;

lease
interface "eth0";
fixed-address 192.168.1.254;
option subnet-mask 255.255.255.0;
option routers 127.0.0.1;
expire never;



It works, but eth0 will only get this IP when dhclient.eth0.leases and dhclient.leases in /var/lib/dhcp/ are empty.



Unless you guys have a good reason to advise against it, I would prefer if the static lease from dhclient.conf was assigned when a dhcp server doesn't reply instead of using old leases. It would make the troubleshooting process easier and allow some way to reach the equipment which is only accessible via ssh and has no display to print out the current ip.



I read through the dhclient manual and a lot of google search results but couldn't find a built in way or any suggestions on how to do this.



Solutions I thought of:



1-Empty dhclient.leases and set permissions so it can't be modified

2-Link dhclient.leases to /dev/null and set permissions so it can't be modified

3-Same as #1 but instead of setting up the static lease in dhclient.conf, manually add it to dhclient.leases before setting permissions.



Of course I will try those but please advise.



Thank you.










share|improve this question























  • I tested option #1 and set attributes using chattr -i which caused dhclient to give out errors about being unable to write to the dhcp.eth0.leases file but it wrote to it anyways even though the wait it read it seemed it wouldnt!
    – TCZ8
    Dec 15 '15 at 17:55










  • Just tested option #2 but didn't change its attributes as dhclient doesn't seem to care about respecting these. The good thing is It works and doesn't give errors. My only concern is making sure the soft link doesn't get replaced when dhclient decides it's time to rotate the file. I couldn't find any info on what triggers the file to be replaced. So I have no clue what and when it will happen. How am I going to test this? Is waiting and hoping for the best my only option?
    – TCZ8
    Dec 15 '15 at 18:01











  • I meant, I gave no clue if and when it will happen. So far so good.
    – TCZ8
    Dec 21 '15 at 14:32












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a piece of equipment I would like to default to a specific IP address when no dhcp servers are available.



I have set the following static lease in /etc/dhcp/dhclient.conf:



timeout 30;

lease
interface "eth0";
fixed-address 192.168.1.254;
option subnet-mask 255.255.255.0;
option routers 127.0.0.1;
expire never;



It works, but eth0 will only get this IP when dhclient.eth0.leases and dhclient.leases in /var/lib/dhcp/ are empty.



Unless you guys have a good reason to advise against it, I would prefer if the static lease from dhclient.conf was assigned when a dhcp server doesn't reply instead of using old leases. It would make the troubleshooting process easier and allow some way to reach the equipment which is only accessible via ssh and has no display to print out the current ip.



I read through the dhclient manual and a lot of google search results but couldn't find a built in way or any suggestions on how to do this.



Solutions I thought of:



1-Empty dhclient.leases and set permissions so it can't be modified

2-Link dhclient.leases to /dev/null and set permissions so it can't be modified

3-Same as #1 but instead of setting up the static lease in dhclient.conf, manually add it to dhclient.leases before setting permissions.



Of course I will try those but please advise.



Thank you.










share|improve this question















I have a piece of equipment I would like to default to a specific IP address when no dhcp servers are available.



I have set the following static lease in /etc/dhcp/dhclient.conf:



timeout 30;

lease
interface "eth0";
fixed-address 192.168.1.254;
option subnet-mask 255.255.255.0;
option routers 127.0.0.1;
expire never;



It works, but eth0 will only get this IP when dhclient.eth0.leases and dhclient.leases in /var/lib/dhcp/ are empty.



Unless you guys have a good reason to advise against it, I would prefer if the static lease from dhclient.conf was assigned when a dhcp server doesn't reply instead of using old leases. It would make the troubleshooting process easier and allow some way to reach the equipment which is only accessible via ssh and has no display to print out the current ip.



I read through the dhclient manual and a lot of google search results but couldn't find a built in way or any suggestions on how to do this.



Solutions I thought of:



1-Empty dhclient.leases and set permissions so it can't be modified

2-Link dhclient.leases to /dev/null and set permissions so it can't be modified

3-Same as #1 but instead of setting up the static lease in dhclient.conf, manually add it to dhclient.leases before setting permissions.



Of course I will try those but please advise.



Thank you.







debian ubuntu raspbian dhcp dhclient






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 21 '15 at 14:31

























asked Dec 15 '15 at 16:48









TCZ8

5293819




5293819











  • I tested option #1 and set attributes using chattr -i which caused dhclient to give out errors about being unable to write to the dhcp.eth0.leases file but it wrote to it anyways even though the wait it read it seemed it wouldnt!
    – TCZ8
    Dec 15 '15 at 17:55










  • Just tested option #2 but didn't change its attributes as dhclient doesn't seem to care about respecting these. The good thing is It works and doesn't give errors. My only concern is making sure the soft link doesn't get replaced when dhclient decides it's time to rotate the file. I couldn't find any info on what triggers the file to be replaced. So I have no clue what and when it will happen. How am I going to test this? Is waiting and hoping for the best my only option?
    – TCZ8
    Dec 15 '15 at 18:01











  • I meant, I gave no clue if and when it will happen. So far so good.
    – TCZ8
    Dec 21 '15 at 14:32
















  • I tested option #1 and set attributes using chattr -i which caused dhclient to give out errors about being unable to write to the dhcp.eth0.leases file but it wrote to it anyways even though the wait it read it seemed it wouldnt!
    – TCZ8
    Dec 15 '15 at 17:55










  • Just tested option #2 but didn't change its attributes as dhclient doesn't seem to care about respecting these. The good thing is It works and doesn't give errors. My only concern is making sure the soft link doesn't get replaced when dhclient decides it's time to rotate the file. I couldn't find any info on what triggers the file to be replaced. So I have no clue what and when it will happen. How am I going to test this? Is waiting and hoping for the best my only option?
    – TCZ8
    Dec 15 '15 at 18:01











  • I meant, I gave no clue if and when it will happen. So far so good.
    – TCZ8
    Dec 21 '15 at 14:32















I tested option #1 and set attributes using chattr -i which caused dhclient to give out errors about being unable to write to the dhcp.eth0.leases file but it wrote to it anyways even though the wait it read it seemed it wouldnt!
– TCZ8
Dec 15 '15 at 17:55




I tested option #1 and set attributes using chattr -i which caused dhclient to give out errors about being unable to write to the dhcp.eth0.leases file but it wrote to it anyways even though the wait it read it seemed it wouldnt!
– TCZ8
Dec 15 '15 at 17:55












Just tested option #2 but didn't change its attributes as dhclient doesn't seem to care about respecting these. The good thing is It works and doesn't give errors. My only concern is making sure the soft link doesn't get replaced when dhclient decides it's time to rotate the file. I couldn't find any info on what triggers the file to be replaced. So I have no clue what and when it will happen. How am I going to test this? Is waiting and hoping for the best my only option?
– TCZ8
Dec 15 '15 at 18:01





Just tested option #2 but didn't change its attributes as dhclient doesn't seem to care about respecting these. The good thing is It works and doesn't give errors. My only concern is making sure the soft link doesn't get replaced when dhclient decides it's time to rotate the file. I couldn't find any info on what triggers the file to be replaced. So I have no clue what and when it will happen. How am I going to test this? Is waiting and hoping for the best my only option?
– TCZ8
Dec 15 '15 at 18:01













I meant, I gave no clue if and when it will happen. So far so good.
– TCZ8
Dec 21 '15 at 14:32




I meant, I gave no clue if and when it will happen. So far so good.
– TCZ8
Dec 21 '15 at 14:32










2 Answers
2






active

oldest

votes

















up vote
0
down vote













Then there is AVAHI whose primary purpose is to assign an IP address when all else fails.



AVAHI should hand out an impractical 169.254.x.x address.



RFC 5735 specifies 169.254.0.0/16 as the ""link local"" block as described in RFC3927. This is the address range to be used by hosts' auto-configuration, such as when a DHCP server cannot be found.



https://help.ubuntu.com/community/HowToZeroconf





share








New contributor




Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote













    I've created '/etc/sysconfig/network-scripts/ifcfg-eth0:0' :



    DEVICE=eth0:0
    BOOTPROTO=none
    ONBOOT=yes
    NETWORK=192.168.222.0
    NETMASK=255.255.255.0
    IPADDR=192.168.222.22
    USERCTL=no


    This just binds a 2nd static IP to the NIC, using an alias. Not really what I wanted, but will work until I figure out the dhclient.conf stuff.



    Alternatively, you can hook up a second network interface card for that static purpose.






    share|improve this answer










    New contributor




    Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f249527%2fwhen-no-dhcp-server-answer-how-can-i-force-dhclient-to-use-the-static-lease-fro%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      Then there is AVAHI whose primary purpose is to assign an IP address when all else fails.



      AVAHI should hand out an impractical 169.254.x.x address.



      RFC 5735 specifies 169.254.0.0/16 as the ""link local"" block as described in RFC3927. This is the address range to be used by hosts' auto-configuration, such as when a DHCP server cannot be found.



      https://help.ubuntu.com/community/HowToZeroconf





      share








      New contributor




      Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





















        up vote
        0
        down vote













        Then there is AVAHI whose primary purpose is to assign an IP address when all else fails.



        AVAHI should hand out an impractical 169.254.x.x address.



        RFC 5735 specifies 169.254.0.0/16 as the ""link local"" block as described in RFC3927. This is the address range to be used by hosts' auto-configuration, such as when a DHCP server cannot be found.



        https://help.ubuntu.com/community/HowToZeroconf





        share








        New contributor




        Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.



















          up vote
          0
          down vote










          up vote
          0
          down vote









          Then there is AVAHI whose primary purpose is to assign an IP address when all else fails.



          AVAHI should hand out an impractical 169.254.x.x address.



          RFC 5735 specifies 169.254.0.0/16 as the ""link local"" block as described in RFC3927. This is the address range to be used by hosts' auto-configuration, such as when a DHCP server cannot be found.



          https://help.ubuntu.com/community/HowToZeroconf





          share








          New contributor




          Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          Then there is AVAHI whose primary purpose is to assign an IP address when all else fails.



          AVAHI should hand out an impractical 169.254.x.x address.



          RFC 5735 specifies 169.254.0.0/16 as the ""link local"" block as described in RFC3927. This is the address range to be used by hosts' auto-configuration, such as when a DHCP server cannot be found.



          https://help.ubuntu.com/community/HowToZeroconf






          share








          New contributor




          Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.








          share


          share






          New contributor




          Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 9 mins ago









          Egbert S

          1114




          1114




          New contributor




          Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






















              up vote
              0
              down vote













              I've created '/etc/sysconfig/network-scripts/ifcfg-eth0:0' :



              DEVICE=eth0:0
              BOOTPROTO=none
              ONBOOT=yes
              NETWORK=192.168.222.0
              NETMASK=255.255.255.0
              IPADDR=192.168.222.22
              USERCTL=no


              This just binds a 2nd static IP to the NIC, using an alias. Not really what I wanted, but will work until I figure out the dhclient.conf stuff.



              Alternatively, you can hook up a second network interface card for that static purpose.






              share|improve this answer










              New contributor




              Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





















                up vote
                0
                down vote













                I've created '/etc/sysconfig/network-scripts/ifcfg-eth0:0' :



                DEVICE=eth0:0
                BOOTPROTO=none
                ONBOOT=yes
                NETWORK=192.168.222.0
                NETMASK=255.255.255.0
                IPADDR=192.168.222.22
                USERCTL=no


                This just binds a 2nd static IP to the NIC, using an alias. Not really what I wanted, but will work until I figure out the dhclient.conf stuff.



                Alternatively, you can hook up a second network interface card for that static purpose.






                share|improve this answer










                New contributor




                Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.



















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  I've created '/etc/sysconfig/network-scripts/ifcfg-eth0:0' :



                  DEVICE=eth0:0
                  BOOTPROTO=none
                  ONBOOT=yes
                  NETWORK=192.168.222.0
                  NETMASK=255.255.255.0
                  IPADDR=192.168.222.22
                  USERCTL=no


                  This just binds a 2nd static IP to the NIC, using an alias. Not really what I wanted, but will work until I figure out the dhclient.conf stuff.



                  Alternatively, you can hook up a second network interface card for that static purpose.






                  share|improve this answer










                  New contributor




                  Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  I've created '/etc/sysconfig/network-scripts/ifcfg-eth0:0' :



                  DEVICE=eth0:0
                  BOOTPROTO=none
                  ONBOOT=yes
                  NETWORK=192.168.222.0
                  NETMASK=255.255.255.0
                  IPADDR=192.168.222.22
                  USERCTL=no


                  This just binds a 2nd static IP to the NIC, using an alias. Not really what I wanted, but will work until I figure out the dhclient.conf stuff.



                  Alternatively, you can hook up a second network interface card for that static purpose.







                  share|improve this answer










                  New contributor




                  Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer








                  edited 7 mins ago





















                  New contributor




                  Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 13 mins ago









                  Egbert S

                  1114




                  1114




                  New contributor




                  Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Egbert S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f249527%2fwhen-no-dhcp-server-answer-how-can-i-force-dhclient-to-use-the-static-lease-fro%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)