-1

I was working with Raspbian Jessie version to set a static IP address for eth0 port. As of my knowledge we can configure it with interfaces file but for jessie, there is new file for it and that is dhcpcd.conf .

When I search through google, all tutorials say that " if you wanna use /etc/network/interfaces file, you have to disable dhcpcd service".

But I do not done anything to dhcpcd service and dhcpcd.conf file. I just have modified the /etc/network/interfaces file to include the static IP as per below.

auto lo
iface lo inet loopback

#iface eth0 inet manual
auto eth0
iface eth0 inet static
    address 192.168.42.1
    netmask 255.255.255.0
    network 192.168.42.0
    broadcast 192.168.42.255

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Now eth0 get static IP after reboot and I haven't disabled the dhcpcd.conf. Is that any problem?

Whether there is any effect on dhcpcd and network interfaces working?

mcv
  • 73
  • 1
  • 9

3 Answers3

1

dhcpcd is used to obtain or set an IP address. You don't need to disable dhcpcd to effectively get a fixed IP address. dhcpcd is a good and reliable program, used now by most Linux distributions. There are reasons why it has displaced the earlier programs.

dhcpcd is controlled/configured by the file /etc/dhcpcd.conf. You should have a look at man dhcpcd and man dhcpcd.conf when you have a few. But this is what you should do to get a static IP address for eth0: Use the software as it's intended, instead of forcing the system, and violating the instructions. In this way you will avoid problems downstream, and be much less likely to have to return here, posting questions, because you've ignored best practices.

Edit the file /etc/dhcpcd.conf to add the following line:

inform 192.168.42.1

And that's it - that is all you need to do to effectively get a static IP. This approach also has another advantage: you will see your RPi host (192.168.42.1) in your router's DHCP table of leases.

This assumes that your network is otherwise operational and rationally configured.

Note that you can also add the CIDR and broadcast address if you like, but they are optional.

If you're interested in "why", please read this answer

Don't be tempted to use the static_ipaddress option in /etc/dhcpcd.conf; man dhcpcd.conf is specific about this:

For IPv4, you should use the inform ipaddress option instead of setting a static address.

Seamus
  • 21,900
  • 3
  • 33
  • 70
0

I don't see why there would be any problem with what you have done. You have set a manual address for the interface. It will not put out a DHCP request for that interface.

It's not clear whether the DHCP daemon you are talking about was supplying eth0 with an address previously. Was it? If it was then it may have been automatically associating that IP address with the name of eth0's host. That may cause a problem if something is asking that DHCP daemon for the IP address of that host.

joan
  • 71,024
  • 5
  • 73
  • 106
  • If we are not using interfaces file, dhcpcd service will allocate IP to eth0 ( provided iface eth0 inet manual should be in the interfaces file). This what I think – mcv Mar 12 '19 at 12:40
0

Is that the COMPLETE contents of /etc/network/interfaces? If it calls dhcp that would disable dhcpcd.

There is nothing to stop you using /etc/network/interfaces BUT dhcpcd may still allocate an address, resulting in duplicate addresses, and potential routing problems.

Frankly, I don't understand why so many Pi users want static IP addresses!

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • I give my main backup device a static address. My preferred router does not act as a nameserver. There is no program way of asking what IP address has currently been assigned to machine mars (the backup device). – joan Mar 12 '19 at 11:35
  • @joan this Comment puzzled me as it is unrelated to the Question, till I realised the author. This was not intended as a general discussion on static IP addresses - those who understanding networks know when they are appropriate (I use them on Access Point, network printers and secondary routers) but this does not explain why Pi users have this mass hysteria for static IP addresses. Even in your case Zero-Conf may be an option. – Milliways Mar 12 '19 at 11:56
  • 2
    Perhaps you should edit your answer and delete "Frankly, I don't understand why so many Pi users want static IP addresses!" as it adds nothing but does invite discussion. – joan Mar 12 '19 at 12:06
  • I need static IP beacuse my application need it. I don't wanna go through the reason now. /etc/network/interfaces file contains one more line source-directory /etc/network/interfaces.d – mcv Mar 12 '19 at 12:31
  • So you mean that, If we do not stop dhcpcd service It will try to allocate address to eth0. I think there will be no duplicate address but there is a chance to change the address from static IP if eth0 gets IP from dhcpcd service. Isn't it? – mcv Mar 12 '19 at 12:35
  • @Milliways I do not understand the line " If it calls dhcp that would disable dhcpcd ". – mcv Mar 12 '19 at 13:02
  • @Milliways Making method as dhcp will not disable dhcpcd. It's a wrong statement – mcv Mar 13 '19 at 10:21
  • @mcv obviously you haven't tried. If you use dhcp in interfaces, dhcpcd closes and posts a message in the startup log. You can only run a single DHCP client. – Milliways Mar 13 '19 at 11:19
  • @Milliways I have tried. I configured wlan0 with dhcp and eth0 as manual. static IP is defined in the dhcpcd.conf. Also I got static IP to eht0 port and wlan0 get IP from dhcp of router. If dhcpcd is disabled, How eth0 get static IP? – mcv Mar 14 '19 at 10:28