2

I have a raspberry PI in a network where all clients get a DHCP IP address assigned automatically. DHCP-IPs are "192.168.0.X" with subnet mask "255.255.255.0"

But for my raspberry (and other devices) I want to use a fixed IP address in another network. Desired IP "192.168.X.Y" with subnet mask "255.255.0.0"

The raspberry should get the IP "192.168.20.104" with subnet mask "255.255.0.0".

My "/etc/network/interfaces" looks like

auto lo
iface lo inet loopback

iface eth0 inet static
  address 192.168.20.104
  netmask 255.255.0.0
  gateway 192.168.0.252

This works ok so far, my raspberry gets the address "192.168.20.104", but it also gets a DHCP address assigned (in my case "192.168.0.173").

Output of "sudo ip addr show":

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:37:1d:30 brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.104/16 brd 192.168.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.0.173/24 brd 192.168.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::ba27:ebff:fe37:1d30/64 scope link
       valid_lft forever preferred_lft forever

But I want the raspberry to use my static address only. There should be no DHCP address.

Is there an error in my "interfaces" file? Can someone explain why I get a DHCP address although I configured a static address?

What do I have to change in my config file so that I don't get a DHCP address?

  • The netmask for that IP should be 255.255.255.0. – schaiba Nov 20 '15 at 13:09
  • @schaiba Youre right, /24 would be the correct subnet, but in my case I have to use /16. But /24 would not make a difference to my "problem" – Boardwish Nov 20 '15 at 13:15
1

You are running a dhcpcd service that is giving you IP addresses no matter what the configuration you have.

imo you should not even have it installed, as dhclient normally does the job. (I am assuming Debian here, maybe I am a bit off) You probably installed it in substitution, so we won't be deinstalling it just in case in the future you define a dhcp enabled interface.

So we will be taking it out of boot configuration, and stopping it.

apt-get install chkconfig
chkconfig dhcpcd off
service dhcpcd stop

Would you please change /etc/network/interfaces it to:

auto eth0
iface eth0 inet static
    address 192.168.20.104
    netmask 255.255.0.0
    network 192.168.0.0
    broadcast 192.168.255.255
    gateway 192.168.0.252

And afterwards do a:

sudo service networking restart
  • I copied your config into my interfaces file and rebooted the raspberry. after booting the static ip works fine, but I again to have a DHCP ip... so there is no difference – Boardwish Nov 20 '15 at 13:44
  • It should not be happening. You must be calling dhclient somewhere else. Can you show me the output of "dpkg -l | grep dhcp" – Rui F Ribeiro Nov 20 '15 at 13:46
  • and also the output of "ps ax | grep dhclient" – Rui F Ribeiro Nov 20 '15 at 13:47
  • dpkg -l | grep dhcp: ii dhcpcd5 6.7.1-1+rpi3 armhf DHCPv4, IPv6RA and DHCPv6 client with IPv4LL support ii isc-dhcp-client 4.3.1-6 armhf DHCP client for automatically obtaining an IP address ii isc-dhcp-common 4.3.1-6 armhf common files used by all of the isc-dhcp packages ps ax | grep dhclient: 1023 pts/3 S+ 0:00 grep --color=auto dhclient – Boardwish Nov 20 '15 at 13:48
  • do a "ps ax | grep dhcp" please – Rui F Ribeiro Nov 20 '15 at 14:17
0

I found another solution where only a modification of the interfaces file is necessary:

Just added the following line at the end of the file:

iface default inet dhcp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.