3

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!

6
  • 1
    You assign reserved IP addresses in the DHCP server, not the client. Commented Jun 5, 2014 at 16:51
  • 1
    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..
    – bosnjak
    Commented Jun 5, 2014 at 17:03
  • You contact the person who does run the server. Commented Jun 5, 2014 at 17:10
  • Lets just assume that I can not do anything on the server. The point is, is there anything that can be done on the client to achieve this?
    – bosnjak
    Commented Jun 5, 2014 at 17:36
  • No. There is not. Asking the same thing over and over will not get you a different answer. Commented Jun 5, 2014 at 17:38

4 Answers 4

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;
}
3
  • 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.
    – bosnjak
    Commented Jun 5, 2014 at 17:00
  • 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. Commented Jun 5, 2014 at 17:11
  • 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.
    – bosnjak
    Commented Jun 5, 2014 at 17:15
2

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.

0

Are you trying to use as a static address one which falls inside the router's address pool? If so, there is no telling what your router will do. Check the router address pools from the GUI, and pick an address outside the pool.

You may check whether you still experience such phenomena simply by stopping network manager (I presume you use one), giving yourself an address,

  ip link set dev eth0 down
  ip addr flush dev eth0
  ip addr add 192.168.1.whatever/24 dev eth0
  ip link set dev eth0 up
  ip route add default via 192.168.1.1

without using dhcpcd. This has the advantage of isolating the problem: if it happens again, then it's your router's fault, otherwise it was an incorrect choice of static IP address.

2
  • Even when I use the IP outside of the pool, the behaviour is strange - i get that IP for some time, but then I just dissapear from the LAN altogether.. I will try the manual way and report back.
    – bosnjak
    Commented Jun 5, 2014 at 17:38
  • @Lawrence I forgot one command in the manual sequence, please take a look at the revised version. Commented Jun 5, 2014 at 17:47
0

The question was:

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.

Yes, you can. You expressed a desire in your question: "I would like to use the same IP every time for my device. Either set it as static or as preferred."

Setting a preferred IP address in dhcpcd is very easy: In /etc/dhcpcd.conf, add this single line:

# instead of a static IP:
interface wlan0
request 192.168.1.135/24

The request is better than assigning a static IP because your DHCP server remains involved, and performing the job it was "hired" to do. Note that it does not guarantee you'll get the requested IP address, but you'll get it if it is available.

Since you do not have admin access to the DHCP server/router, you could use the address that DHCP assigns to your system initially; e.g. let's assume that 192.168.1.178 is initially assigned. That likely means that the server admin has configured the DHCP server so that 192.168.1.178 is in the "pool" of dynamic host addresses. But if you "adopt" that IP address, you can add the request 192.168.1.178/24 line to your dhcpcd.conf file, and probably have it for as long as you want it. DHCP servers always prefer to assign the same IP address to a host, but the request allows you to express a preference for that address to the server.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .