Page 1 of 1

DHCPCD - re-allocate IP

Posted: 10 Jul 2012, 08:55
by OldAndWeary
Recently transferred from SLAX environment to Porteus and struggling with something that used to work
- perhaps I was abusing the system and getting away with it before!

I want to be able to switch operation (live) from having an allocated DHCP address to setting my own ... then when required, swap back again

e.g.
Start with DHCP allocated IP and use on one network; then connect to alternative network & select IP of say 100.0.0.10; then connect back to original and re-enable DHCP again

Used to do this using commands ....

To disable DHCP and define my own IP
dhcpcd -k eth0
sleep 2
ifconfig eth0 up
ifconfig eth0 100.0.0.1

Then to re-enable DHCP:
ifconfig eth0 up
dhcpcd eth0
ifconfig eth0 up

Note: I had to include the 'up' commands to ensure the interface always came up correctly.

However, this does not work under Porteus. Although the manually set IP is allocated, it does not stick. It goes back to the automatically assigned IP again.

Any clues or suggestions please

Many Thanks
John

Re: DHCPCD - re-allocate IP

Posted: 10 Jul 2012, 13:31
by fanthom
hi OldAndWeary,

please create two profiles in Network Manager: one for static IP and one for dynamic IP.
now move them in/out of /etc/NetworkManager/system-connections folder with a script or command.

tested and works here.

Re: DHCPCD - re-allocate IP

Posted: 10 Jul 2012, 13:34
by brokenman
How are you actually connecting to the network? Do you use networkmanager or are you using wpa_supplicant directly through a script?

Re: DHCPCD - re-allocate IP

Posted: 10 Jul 2012, 15:27
by OldAndWeary
Many Thanks to both fanthom and brokenman for replying.

I had got to the same conclusion as fanthom that I could probably 'play' with the /etc/NetworkManager/system-connections folder contents
... at least that's what I have been trying to script.
I'm very pleased to hear that this should work.
In fact I'm using awk to change everything after the [ipv4] settings to either
method=manual
addresses1=100.0.0.1;24;100.0.0.1;
Or
method=auto
Not sure if having done this whether I still need to use ifconfig to set the values for manual ... or whether it will just happen? Guess I'll find out in a few minutes. (Unless either of you lets me know).

With regard to comment about wpa_supplicant - as I don't know what this means (too thick!) I believe I must be using NetworkManager. Should I use wpa_suplicant? Or does it not matter?

Many Thanks again
John

Posted after 1 hour 30 minutes 32 seconds:
Still fighting a losing battle ...

If one edits the file Wired connection 1 directly with vim, the changes are almost immediately reflected (using command ifconfig eth0).
However, if the file is updated using an editor such as Kate or updated using 'cp' command ... although the file is updated, the address does not change.

Any suggestions please?

Re: DHCPCD - re-allocate IP

Posted: 10 Jul 2012, 20:09
by brokenman
Probably the easiest thing (so as not to over complicate things with coding) is to use the built in profile manager in networkmanager.

Here is a video of how to do it. Remember to save your current session (Porteus settings centre) if you are booting in always fresh mode (or make a module of your networkmanager profile folder).

http://youtu.be/BJly2j-KDVc
Creating one profile for DHCP and another for static ip address in networkmanager.

Re: DHCPCD - re-allocate IP

Posted: 11 Jul 2012, 10:49
by OldAndWeary
Many Thanks Brokenman for producing the video.

I can see that this is a tidy way of doing it.

Regards
John