DHCP only with selected interfaces

Post there if you plan to contribute to this SystemCd
emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

DHCP only with selected interfaces

Postby emiliano » 22 Nov 2010, 20:12

Hello to all,
I'd like to have the ability to request an address with DHCP only for selected interfaces, and not for all. So I propose a change in the dodhcp kernel option like this:

Code: Select all

dodhcp=eth0,eth2

so you can request an address only for eth0 and eth2, and set the address of eth1, for example with:

Code: Select all

dodhcp=eth0,eth2 eth1=192.168.128.1/24

I changed the /init script in the initram.igz of Sysresccd 1.6.3 in the following way:

Code: Select all

465c465,470
<       ethlist="$(/sbin/ifconfig -a | grep 'eth' | awk '{print $1}' | busybox xargs)" # (eg: eth0 eth1 eth2)
---
>       if [ -n "${SETDODHCP}" ]
>       then
>          ethlist="$(echo ${SETDODHCP} | sed -e 's!,! !g')" # (eg: eth0 eth2)
>       else
>          ethlist="$(/sbin/ifconfig -a | grep 'eth' | awk '{print $1}' | busybox xargs)" # (eg: eth0 eth1 eth2)
>       fi
1269c1274
<       dodhcp)
---
>       dodhcp\=*)
1270a1276
>          SETDODHCP=`parse_opt "${x}"`
1493a1500
> SETDODHCP=''

I also changed the initscript /etc/init.d/netconfig2 in the same way, to prevent DHCP request on all interfaces if the nonm option is used (that is, when disabling NetworkManager):

Code: Select all

43a44,49
>          
>          if echo "${opt}" | grep -q -F 'dodhcp'
>          then
>             SETDODHCP=$(echo "${opt}" | cut -d= -f2)
>             print_and_log_netconfig2 "DODHCP=${SETDODHCP}"
>          fi
45,46c51,58
<       
<       NETDEVICES="$(awk -F: '/eth.:|tr.:|ath.:|wlan.:/{print $1}' /proc/net/dev 2>/dev/null)"
---
>
>       if [ -n "${SETDODHCP}" ]
>       then
>          NETDEVICES="$(echo ${SETDODHCP} | sed -e 's/,/ /g')"
>       else
>          NETDEVICES="$(awk -F: '/eth.:|tr.:|ath.:|wlan.:/{print $1}' /proc/net/dev 2>/dev/null)"
>       fi
>


It seems to work; could someone please comment and give me advices?
Many thanks and kind regards,

Emiliano

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: DHCP only with selected interfaces

Postby admin » 13 Dec 2010, 08:04

Thanks for your contribution, sorry for the long delay.
I have made these modifications (with minor modifications) in sysresccd-1.7.0-beta009
Could you check that it works for you and post the feed back here?

emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Re: DHCP only with selected interfaces

Postby emiliano » 13 Dec 2010, 20:53

Hello admin, you're right !!
Many thanks for the interest; I'll edit my post to include the patches in unified format. But please let me first check the code because I wrote it for the 1.6.3 version.

Emiliano

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: DHCP only with selected interfaces

Postby admin » 13 Dec 2010, 20:55

Don't worry about the patch, it should not be necessary any more as I have merged it already.
And the current version is not very different from the latest beta so no conflicts in the patch
But yes please use the unified format the next time if you can.
I have not uploaded version beta009 yet, I will do as soon as I can, if you could test it it would be great

emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Re: DHCP only with selected interfaces

Postby emiliano » 13 Dec 2010, 21:25

ok, thank you so much!
just downloaded the beta008, I'll check all my patches against it, and then with beta009 when available.

(by the way, I have several patches and a little installer script I use to create custom virtual appliances based on SystemRescueCD; I'd like to post here in the Contributions)

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: DHCP only with selected interfaces

Postby admin » 13 Dec 2010, 23:10

I have updated the documentation

emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Re: DHCP only with selected interfaces

Postby emiliano » 13 Dec 2010, 23:52

oh great! thank you so much :-)

emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Re: DHCP only with selected interfaces

Postby emiliano » 16 Dec 2010, 15:28

Hello admin,
maybe there is a small typo in file /etc/init.d/netconfig2 of SystemRescueCD 1.7.0-beta010; here is the patch:

Code: Select all

--- /livemnt/squashfs/etc/init.d/netconfig2   2010-12-13 20:49:05.000000000 +0000
+++ /etc/init.d/netconfig2   2010-12-16 15:20:13.000000000 +0000
@@ -44,7 +44,7 @@
          fi
          if echo "${opt}" | grep -q -F 'dodhcp='
          then
-            DHCPDEVICES="$(echo '${opt}' | cut -d= -f2 | sed -e 's/,/ /g')"
+            DHCPDEVICES="$(echo "${opt}" | cut -d= -f2 | sed -e 's/,/ /g')"
             print_and_log_netconfig2 "DHCPDEVICES=${DHCPDEVICES}"
          fi
       done

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: DHCP only with selected interfaces

Postby admin » 16 Dec 2010, 19:24

Many thanks, it will be fixed in beta011

emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Re: DHCP only with selected interfaces

Postby emiliano » 01 Mar 2011, 11:24

Hello,
it seems is not working anymore in 2.1.0-beta003 (and maybe previous versions).
The problem is at the begin of sysresccd_netconfig() in the lines:

Code: Select all

    # ---- force dhcp if booting via pxe and no static configuration specified
    if [ "${NETCONFIG}" = '1' ] && [ -z "${SETETHX}${NODHCP}" ]
    then
        DODHCP='all'
    fi


in this way, booting with options "nonm dodhcp=eth0,eth2 eth1=192.168.1281/24" the DODHCP variable will be set to 'all'.
Solved with this patch:

Code: Select all

diff --git a/initramfs/init b/initramfs/init
index 7edf67f..4ed0b15 100755
--- a/initramfs/init
+++ b/initramfs/init
@@ -323,7 +323,7 @@ sysresccd_netconfig()
        /sbin/ifconfig lo 127.0.0.1
 
        # ---- force dhcp if booting via pxe and no static configuration specified
-       if [ "${NETCONFIG}" = '1' ] && [ -z "${SETETHX}${NODHCP}" ]
+       if [ "${NETCONFIG}" = '1' ] && [ -z "${SETETHX}${NODHCP}${DODHCP}" ]
        then
                DODHCP='all'
        fi

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: DHCP only with selected interfaces

Postby admin » 05 Mar 2011, 13:46

Thanks for your contribution, it will be in sysresccd-2.1.0-beta004


Return to “Contributions”

Who is online

Users browsing this forum: No registered users and 3 guests