Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Dec 2005 18:12:22 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Yuan Jue <yuanjue02@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Wireless NIC in FreeBSD 6.0 ?
Message-ID:  <20051226161222.GA1038@flame.pc>
In-Reply-To: <200512261107.45871.yuanjue02@gmail.com>
References:  <200512251530.21898.yuanjue02@gmail.com> <200512252205.33644.yuanjue02@gmail.com> <43AEB79D.9030200@locolomo.org> <200512261107.45871.yuanjue02@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-12-26 11:07, Yuan Jue <yuanjue02@gmail.com> wrote:
> instead, I figure out another way to work around.
>
> 1.ifconfig bge0 delete
> % this would shut my local NIC down totally
>
> 2.kldload if_ath
>    dhclient ath0
>
> then I can enjoy the wireless internet surfing :)
>
> antway, thank you again!

FWIW,

On my laptop, which has to switch between a couple of wireless networks and
my local LAN at home, I use custom shell scripts called ``/root/net/*.sh''
to encapsulate the changes I'd have to manually make.

I have prepared working sets of files, like:

    /etc/resolv.conf_home
    /etc/resolv.conf_work

and then run /root/net/home.sh which contains:

    #!/bin/sh

    if test -n "$1" && test -f "/root/netstart-home-$1.sh" ; then
        mode="$1"
    else
        mode=wlan
    fi

    echo "## Stopping local services"
    /etc/rc.d/named stop
    /etc/rc.d/sendmail stop

    echo "## Setting up /etc and /usr/local/etc files"
    (
      cd /etc;
      cp resolv.conf_home resolv.conf;
      cp dhclient.conf_home dhclient.conf;
      cp namedb/named.conf_home namedb/named.conf;

      cd /usr/local/etc/postfix;
      cp main.cf_home main.cf;
    )

    echo "## Bringing up the network connection"
    "/root/net/netstart-home-${mode}.sh"

    echo "## Refreshing the firewall rules"
    /etc/rc.d/pf reload

    echo "## Starting local services again"
    /etc/rc.d/named start
    /etc/rc.d/sendmail start

The real work is done by netstart-home-wlan.sh or netstart-home-wlan.sh.
The wlan script is the one that sets up a wireless connection, and
contains:

    #!/bin/sh

    # Default setup for my bge0 interface.
    export ifconfig_ath0="DHCP ssid 'gker' \
               wepmode on weptxkey 1 wepkey '1:0xXXXXXXXXXXXXXXXXXXXXXXXXXX'"
    export defaultrouter="192.168.1.2"

    /etc/rc.d/netif stop bge0
    /etc/rc.d/netif stop ath0

    echo -n "Waiting for ath0 to associate "
    _timeout=0
    _associated=NO
    while [ "$_timeout" -lt 30 ]; do
            status=$( ifconfig ath0 2>&1 | grep status: |\
                      awk '{print $2}' )
            if [ X"${status}" = X"associated" ]; then
                    _associated=YES
                    break
            fi
            echo -n '.'
            sleep 1
            _timeout=$(( $_timeout + 1 ))
    done
    if [ X"${_associated}" = X"YES" ]; then
            echo " ok"
    else
            echo ''
            echo "Failed to bring up ath0.  Aborting."
            /etc/rc.d/netif stop ath0
            exit 1
    fi

    #
    # The default route may be pointing to another interface.  Find out
    # the IP address of the default gateway, delete it and point to the
    # default gateway of my home network.
    #
    if [ -n "${defaultrouter}" ]; then
            _oldrouter=`netstat -rn | grep default | awk '{print $2}'`
            if [ -n "${_oldrouter}" ]; then
                    route delete default "${_oldrouter}"
                    unset _oldrouter
            fi
            route add default "$defaultrouter"
    fi

This seems to work remarkably well so far.  All I need to do once the
laptop boots is to log in as root and run the proper /root/net/*.sh script :)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051226161222.GA1038>