Setting the IP with dhcpcd

9,768

Solution 1

If you are using dhcpcd (the client daemon, most people here are confusing it with DHCP and DHCPd which is different), then add the following text on the bottom of /etc/dhcpcd.conf

static
interface eth0
static ip_address=192.168.1.135/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8

Of course remember to replace the IP info with your network details.

Solution 2

you need to do MAC reservation, like this:

host vnbandk3920.dsdk12.schoollocal {
   hardware ethernet 00:c0:ee:7d:bc:80;
   fixed-address 172.30.176.243;
}
Share:
9,768

Related videos on Youtube

bosnjak
Author by

bosnjak

Updated on September 18, 2022

Comments

  • bosnjak
    bosnjak over 1 year

    I have a setup where my system is in the regular home network connected to the router. The router assigns the IP to my device without issues.

    I would like to use the same IP every time for my device. Either set it as static or as preferred. This is a fully controlled environment so there should be no problem getting the preferred IP from the DHCP.

    Update: I can not change anything on the DHCP server side, I need to come to a solution from the client side. The server is ICS and can not be configured.

    Questions

    My question is, is this possible via dhcpcd? Can I use a static IP with dhcpcd at all? Or even preferred? I can not avoid the use of dhcpcd because of some unrelated requirements.

    Done so far

    What I have tried so far is to add these lines to the /etc/dhcpcd.conf file:

    interface eth0
            static ip_address=192.168.1.135/24
            static routers=192.168.1.1
            static domain_name_servers=8.8.8.8
    

    This is what the manpages for dhcpcd.conf say:

    static value

             Configures a static value.  If you set ip_address then dhcpcd
             will not attempt to obtain a lease and just use the value for the
             address with an infinite lease time.
    
             Here is an example which configures a static address, routes and
             dns.
                   interface eth0
                   static ip_address=192.168.0.10/24
                   static routers=192.168.0.1
                   static domain_name_servers=192.168.0.1
    

    But the problem is that even when I do it like this, I only get to see my device using that IP for a short while, after which it seems to be lost and replaced with another IP most probably assigned via DHCP (it is next in the pool i guess).

    Here is my complete dhcpcd.conf file contents:

    # Inform the DHCP server of our hostname for DDNS.
    hostname
    
    # Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
    duid
    
    # Persist interface configuration when dhcpcd exits.
    persistent
    
    # Rapid commit support.
    # Safe to enable by default because it requires the equivalent option set
    # on the server to actually work.
    option rapid_commit
    
    # A list of options to request from the DHCP server.
    option domain_name_servers, domain_name, domain_search, host_name
    option classless_static_routes
    # Most distributions have NTP support.
    option ntp_servers
    
    # A ServerID is required by RFC2131.
    require dhcp_server_identifier
    
    # A hook script is provided to lookup the hostname if not set by the DHCP
    # server, but it should not be run by default.
    nohook lookup-hostname
    noipv4ll
    
    interface eth0
            static ip_address=192.168.1.135/24
            static routers=192.168.1.1
            static domain_name_servers=8.8.8.8
    

    Do I need to add some more options to let DHCP know that I don't need a new IP address or something? Or did I completely misunderstand the topic at hand?

    I tried searching for more detailed help online, but either there is not much info on this subject, or more probably, I don't know enough about the topic to perform a valid search.

    Any help is appreciated!

    • Michael Hampton
      Michael Hampton almost 10 years
      You assign reserved IP addresses in the DHCP server, not the client.
    • bosnjak
      bosnjak almost 10 years
      Hmm, i guess. The problem is that I can not change anything on the DHCP server. What can be done from the client side? (The server is a ICS DHCP server which I can not edit) I updated my question with this info..
    • Michael Hampton
      Michael Hampton almost 10 years
      You contact the person who does run the server.
    • Michael Hampton
      Michael Hampton almost 10 years
      No. There is not. Asking the same thing over and over will not get you a different answer.
    • bosnjak
      bosnjak almost 10 years
      I get the feeling there is at least partly misunderstanding, probably because of my lack of knowledge. What is the "static value" option for ? The one from the dhcpcd.conf manpages.
  • bosnjak
    bosnjak almost 10 years
    This must be done on the server side? I forgot to mention that I don't have the possibility to change anything on DHCP server side, because it is an ICS DHCP. Ill update that to my question.
  • Michael Hampton
    Michael Hampton almost 10 years
    This is the way you do it in ISC DHCP. Though, you are still going to have to get the person who runs the server to do it for you.
  • bosnjak
    bosnjak almost 10 years
    Its not an ISC server, rather the ICS (internet connection sharing) setup. Its the most basic fixed setup so I can't change anything on the server side.
  • MariusMatutiae
    MariusMatutiae almost 10 years
    @Lawrence I forgot one command in the manual sequence, please take a look at the revised version.