changing /etc/network/interfaces has no effect

2

1

I have read many posts that to change your PC between static and dhcp ip addressing you change your /etc/network/interfaces file and then restart the networking with:

/etc/init.d/networking restart

However when I do this, the restart seems to go ok, but (for example using a static address) I see that the ip address is unchanged (using ifconfig eth0).

However when I do this manually:

sudo ifconfig eth0 192.168.3.20 netmask 255.255.255.0 up

Then it works fine, but only if I remove the "auto eth0" line from the networking file, otherwise DHCP is used.

So it looks like the networking file is used, but I can't get it to do static ip addresses :(

Here is my networking file contents:

#auto eth0 COMMENTED OUT iface eth0 inet static address 192.168.3.21 (USING .21 HERE TO DISTINGUISH BETWEEN MANUAL AND NETWORKING) netmask 255.255.255.0 network 192.168.3.0 broadcast 192.168.3.255 gateway 192.168.3.1

Am I doing somthing wrong?

code_fodder

Posted 2015-10-12T11:49:00.967

Reputation: 1 057

Are you trying to use an IP address that is within the scope of your DHCP server? – duenni – 2015-10-12T11:56:27.010

You need to use the command ifup eth0 – qasdfdsaq – 2015-10-12T11:57:44.057

@duenni no, the IP address can be anything at all - it is for talking to some custom hardware that may have any ip address. – code_fodder – 2015-10-12T11:59:54.800

@qasdfdsaq ah, is that in the networking file after the gateway 192.168.3.1 line? – code_fodder – 2015-10-12T12:00:33.053

No. On the command line, instead of /etc/init.d/networking restart. – qasdfdsaq – 2015-10-12T12:05:21.237

Answers

1

Your error is in having edited out the line

       auto eth0

which instead must remain in place. You may also wish to add DNSes to make your network work: add to the eth0 stanza the line

       dns-nameservers 8.8.8.8 8.8.4.4

Notice the plural, nameservers, and the lack of punctuation between the two nameservers. If you don't like Google's, you can pick any you like.

As to the difference between service networking restart and ifdown eth0 && ifup eth0, there isn't any: the file /etc/init.d/networking, which is executed when the service networking is restarted, contains the lines:

       # Provides:          networking ifupdown
         ...........
        ifup $ifaces "$@"

and so on: in other words, service networking restart uses ifup/ifdown. Both usages are ok.

MariusMatutiae

Posted 2015-10-12T11:49:00.967

Reputation: 41 321

ah, so I thought the auto eth0 was the part that told it to do DHCP, so that is why I removed that when trying to use static IP address. So you are saying I still need that along with all the rest of the lines I entered? (don't need DNS's : ) Thanks – code_fodder – 2015-10-12T12:34:35.277

Also when I leave auto eth0 in, I can manually set the static IP address, but then about 10 seconds later, it gets changed back (I lose my address) – code_fodder – 2015-10-12T12:37:16.237

@code_fodder The fact that you lose your static IP address is very odd. Can you post the output of ip addr show dev eth0 before losing the static IP, after it, and then post the output of dmesg in between? Also: the part that told it to do dhcp was the word dhcp placed instead of static. – MariusMatutiae – 2015-10-12T13:01:21.287