Thanks to Ken Ryan for this. ---SNIP--- Hello, Mohit! I've been using your QuickSwitch utility for some time now, and I thought I'd pass up to you a patch that scratched a couple of my itches. :-) First, I've found it useful to be able to switch to a state where no network is configured at all (specifically, so that my ethernet device driver could be unloaded; it also lets me use the PCMCIA infrastructure for my wireless ethernet card[1]). I've added the ability to leave the "address" line in the configuration block empty ("address="). This works when switching from either DHCP or static. One implication of doing this, of course, is the hostname needs to get attached to "127.0.0.1" since there isn't another interface. Second, at one site I sometimes configure my machine to take the place of an old, obsolete one. I added an "ether=AA:BB:CC:DD:EE:FF" configuration line so the hardware ethernet address could be loaded (on my system the 3c59x driver only lets the HW address be set after the module is loaded and before the first "ifconfig", but that is adequate for me). Anywy, the patch and a few of my .conf entries are attached. My apologies if I do something ugly in my changes; I'm not a perl programmer. If you like the changes and wish to include them in your mainline I'd be honored. :-) BTW, I've been running it lately on a heavily customized Slackware 9.1 installation (with a 2.4.26 kernel) Thanks for making such a useful little program! Ken Ryan linuxryan@NOSPAM.org [1] I know Quickswitch supports wireless ethernet also. One thing I like about the normal card services infrastructure is to be able to get two different network configurations merely by shoving the card into one slot or the other ... === patch against v1.05 ================================================ --- /root/src/quickswitch-1.05/switchto 2003-09-21 08:00:29.000000000 -0400 +++ ./switchto 2004-09-02 20:00:46.000000000 -0400 @@ -473,6 +473,7 @@ usehosts nfsexports nisdomain essid key + if_opts ether )){ $self->{$key} = $ref->{$key} if defined($ref->{$key}); } @@ -699,27 +700,42 @@ sub configure_device { my $self = shift; - if( $self->{ipaddr} =~ m/dhcp/i ){ - #This line prints to stderr because of Switcher - print STDERR $self->ANSI_color('normal')."Determining DHCP/BOOTP info...\n" - if ! $self->{quiet_mode} && $self->{verbose}; - - $self->do_command("Configuring device...\n", - "$self->{dhcpconfig} $self->{device}"); + if( $self->{ipaddr} ){ + + if( $self->{ipaddr} =~ m/dhcp/i ){ + + #This line prints to stderr because of Switcher + print STDERR $self->ANSI_color('normal')."Determining DHCP/BOOTP info...\n" + if ! $self->{quiet_mode} && $self->{verbose}; + + $self->do_command("Configuring device...\n", + "$self->{dhcpconfig} $self->{device}"); + + }else{ + + $self->do_command("Killing dhcp client...\n", + "$self->{dhcpkill}"); + $self->do_command("Configuring hardware address...\n", + "$self->{ifconfig} $self->{device} hw ether $self->{ether}") + if defined $self->{ether}; + + my $IFLINE = "$self->{ifconfig} $self->{device} $self->{ipaddr}"; + $IFLINE .= " netmask $self->{netmask}" if defined $self->{netmask}; + $IFLINE .= " $self->{if_opts}" if defined $self->{if_opts}; + + $self->do_command("Configuring device...\n", + $IFLINE); + + } + }else{ - + $self->do_command("Killing dhcp client...\n", - "$self->{dhcpkill}"); - - my $IFLINE = "$self->{ifconfig} $self->{device} $self->{ipaddr}"; - $IFLINE .= " netmask $self->{netmask}" if defined $self->{netmask}; - - $self->do_command("Configuring device...\n", - $IFLINE); - + "$self->{dhcpkill}"); } + } ###----------------------------------------------------------------### @@ -810,9 +826,16 @@ print "Writing to $HOSTSFILE...\n" if $self->{verbose}; open (F, ">$HOSTSFILE") || die "Couldn't open $HOSTSFILE [$!]"; print F "# Generated by Quickswitch. Do not modify.\n\n"; - print F "127.0.0.1 localhost localhost.localdomain\n"; - print F "$self->{ipaddr} $self->{hostname} $self->{fqhostname}\n" - if $self->{ipaddr} !~ /dhcp/i; + if( $self->{ipaddr} ){ + if ( $self->{ipaddr} !~ /dhcp/i ) { + print F "127.0.0.1 localhost localhost.localdomain\n"; + print F "$self->{ipaddr} $self->{hostname} $self->{fqhostname}\n"; + } else { + print F "127.0.0.1 localhost localhost.localdomain $self->{hostname} $self->{fqhostname}\n"; + } + }else{ + print F "127.0.0.1 localhost localhost.localdomain $self->{hostname} $self->{fqhostname}\n"; + } close(F); $self->print_ok; ====== some of my .conf entries ==================================== # # DHCP (wired) # [dynamic] description=Wired 100Mbit ethernet + DHCP execpre=/etc/rc.d/rc.netdevice address=dhcp hostname=chur FQhostname=chur.home # # DHCP (wired, alt mac) # [altdynamic] description=Wired 100Mbit ethernet + DHCP + alt execpre=/etc/rc.d/rc.netdevice address=dhcp hostname=chur FQhostname=chur.home ether=00:c0:4f:7f:ff:66 # # Wired, alt. MAC # [alt] description=Wired 100Mbit ethernet + alt. IP execpre=/etc/rc.d/rc.netdevice address=192.168.0.3 netmask=255.255.255.0 FQHostname=chur.home gateway=192.168.0.1 domain=home dns1=192.168.0.1 hostname=chur #if_opts=hw ether 00:c0:4f:7f:ff:66 ether=00:c0:4f:7f:ff:66 # # Null setting # [null] description=Null setting address= hostname=chur #execpost=sleep 3; /sbin/rmmod 3c59x execpost=/sbin/ifconfig eth0 down ---SNIP---