0

I have this in etc/network/interfaces :

auto eth0
iface eth0 inet static
address 192.168.1.119
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4

I don't use network manager.

ifdown eth0 && ifup eth0 does not update my ip.

But the update is done if I reboot.

What am I missing ?

trogne
  • 141
  • 1
  • 8
  • You haven't said much about your environment. It could be that in your down/up is fast enough to request the same IP, while a restart takes long enough that another client gets the IP. – Jason Martin May 02 '17 at 18:40
  • It's kali linux. I'm alone in my environment. No one gets the ip I'm requesting. But if I'm doing `ifconfig -a`, I still see the interface with the ip. Normal ? – trogne May 02 '17 at 18:43
  • Oh, is the issue that ifconfig is not matching your file? – Jason Martin May 02 '17 at 18:51
  • yes, ifconfig doesn't not show the IP address I'm requesting – trogne May 02 '17 at 18:55
  • Perhaps `ifup` is failing to parse your config for some reason. Can you simplify the config slightly by removing the `network` and `broadcast` stanzas and split the DNS config into two statements `dns-nameservers 8.8.8.8` and `dns-nameservers 8.8.4.4`. It may also be useful using the `--verbose` flag when using `ifdown` and `ifup` to see if you get any additional information. – Mark Riddell May 02 '17 at 19:24
  • see my comment below about `dhclient -v -r` – trogne May 02 '17 at 19:26

2 Answers2

2

I had first to turn down the interface, ifdown eth0.

Then edit the file /etc/network/interfaces, changing the ip.

And only then, turn up the interface, ifup eth0.

This way, it always works.

I guess that when using ifdown eth0 && ifup eth0 after editing the /etc/network/interfaces file, it seems that the ifdown eth0 doesn't have the right data to turn the interface down correctly.

trogne
  • 141
  • 1
  • 8
  • 2
    If it was DHCP before you made your edits, then the ifdown tool doesn't know it needs to stop the dhcp daemon. It is kinda stupid like that. You could have also manually killed the dhcp client process. Stopping the interface, then making changes is a good option though. – Zoredache May 02 '17 at 23:30
1

Maybe you can try

service networking restart

That will restart network interfaces reloading parameters in /etc/network/interfaces.

You can also use sysctl, but service still works.

patan90
  • 141
  • 1
  • 5
  • It does not work, like ifdown/ifup. – trogne May 02 '17 at 19:09
  • Just a silly question.. but are you have the proper administrative rights? Perform the command as **root** or using **sudo**. – patan90 May 02 '17 at 19:16
  • `sudo service networking restart` or `service networking restart` as root. – patan90 May 02 '17 at 19:16
  • I'm already root. – trogne May 02 '17 at 19:16
  • Can you post the entire file? Does you get any error when restarting the service? Just to try. remove **network 192.168.1.0** and **broadcast 192.168.1.255** parameters, the are not generally needed. – patan90 May 02 '17 at 19:21
  • As you are providing IP and Netmask, the other parameters are not needed. – patan90 May 02 '17 at 19:22
  • `ifup` works if I run it after `dhclient -v -r` ... seems that we can't get static ip renew successfully if a dhcp service is running (?) – trogne May 02 '17 at 19:24