Page 1 of 6 123 ... LastLast
Results 1 to 10 of 52

Thread: HOWTO: Automatic network configuration

  1. #1
    Join Date
    Jan 2005
    Beans
    90

    HOWTO: Automatic network configuration

    HOWTO Whereami
    Originally by Reid Gilman
    goodstuff AT blueplazma DOT org
    8/4/2005


    1) What is Whereami?
    Whereami is a very useful little program that "automatically configures your system during boot and whenever a PCMCIA network card is inserted or removed." It can be used to switch settings and is very useful on laptops that move from trusted networks to untrusted networks.
    This HOWTO will cover setting up a laptop to differentiate a wired, wireless, and un-trusted wireless network. We will assume that this laptop is normally on a public, unsecured wireless network, but is also used on a home wireless network (which is also unsecured), as well as a home wired network. eth0 will be an ethernet card, and eth1 will be a wireless card. This HOWTO was tested on Ubuntu Hoary running on a Dell Inspiron 8600 with an Intel IPW2200(b/g).

    2) Where do I get Whereami?
    There are a few ways to get Whereami. I did this install on Ubuntu, so I used apt-get. On Ubuntu, simply
    Code:
    sudo apt-get install whereami
    For other distros, visit the download page.

    3) How do I configure Whereami?
    Whereami configuration involves two main files: /etc/whereami/detect.conf and /etc/whereami/whereami.conf. From now on, if I refer to one of these files, I mean for it to be prefaced by /etc/whereami. Thus, if I say, "Edit whereami.conf..." I mean "Edit /etc/whereami/whereami.conf". To begin setting up Whereami, cd into the whereami directory from a terminal.
    Code:
    cd /etc/whereami
    1) detect.conf
    detect.conf is the first of the two extremely important files to make whereami function. This file does what it sounds like: it detects on which network you are using a variety of tests. Ubuntu gives you an example detect.conf; I recommend moving it to detect.conf.default and opening a new version like so
    Code:
    sudo mv detect.conf detect.conf.default && sudo gedit detect.conf
    You should now have a nice shiny gedit window with nothing in it. You should set a "default" location. For our purposes, it will be "wireless". Enter the line
    Code:
     default wireless
    into your new detect.conf file.
    The next test is to determine if there is an ethernet cable plugged in or not, since that can rule out one possible configuration. We will use the testmii command to do so. testmii needs two arguements. The first is an interface to test, the second a network to enable should it find an ethernet cable. Since it is looking for an ethernet cable, it will enable the wired network if it finds one. eth0 is our ethernet card, so enter this line to check for an ethernet cable plugged into eth0
    Code:
    testmii eth0 lan
    Now let's tell Whereami what to do if an ethernet cable is plugged in.
    Code:
    if lan
    	set INTERFACE eth0
    	testdhcp 192.168.1.0/24 home-wired
    	testdhcp '*.*.*.*' wired
    	notat down
    else
    	notat wired,home-wired
    	always set INTERFACE eth1
    	always testap scan wlan
    fi
    So, what does all that mean? Some of it is plain old shell-scripting, but some is not. "set INTERFACE eth0" tells whereami to perform the following tests on the interface eth0. testdhcp tells whereami to test for a DHCP assigned IP address on the interface and activate the selected network if it finds one. "notat down" simply tells Whereami that we have some type of network, since down is going to be our selection when there is absolutely no connectivity. The last command of interest is "testap scan wlan". If you haven't guessed yet, this command simply scans for a wireless AP within range and activate the wlan network when it finds one.
    Now, we must determine if we are on our trusted wireless network or not.
    Code:
    if wlan
    	testssid MyHomeNetwork home-wireless
    	testap scan wlan wireless
    	always notat wlan
    fi
    "testssid MyHomeNetwork home-wireless" is our final test. If it finds an SSID for our trusted network, then it turns on the home-wireless network. Otherwise, it assumes we have an unknown network. It shuts off wlan because wlan is just a name to avoid conflict in if statements.

    2) whereami.conf
    Now that we know which network we are at, we need to tell Whereami to do something about it. whereami.conf does this, and is much more straightforward and self-explanatory than is detect.conf.
    Here is the first section of our whereami.conf.
    Code:
    	=rm /etc/network/interfaces.old
    
    +home-wired /etc/init.d/networking restart
    +home-wired /etc/init.d/firestarter restart
    +home-wired setresolver search <put in your settings here>
    There are really three things that need explanation here. First is the equals sign (=), which means to always perform the command, regardless of which network we were on before. The plus (+) means to perform this command only if we were not on this network before, and the minus (-) means to perform this command only if we were on this network before, but are NOT anymore. See the documentation for specifics. Also, please consider writing small firewall scripts to replace firestarter if you can. It will give you much better control over your firewall at different locations. I have done this, and have an /etc/init.d/trusted-network-firewall and /etc/init.d/untrusted-network-firewall script set up. That is beyond this HOWTO, but worth considering. Otherwise, the default firestarter setup should be fine for you.

    4) How do I make this all work now?
    Whereami should work on reboot, or by running the initscript (/etc/init.d/whereami). I found that this works well for me. I hope it works well for you too. These settings can be kind of difficult, but I found the included documentation to be very sparse, so I hope that this example will help you a bit to get off the ground. Obviously, whereami can be used for very complex networks including WEP and WPA, but most people do not need an extremely complex setup.

  2. #2
    Join Date
    Apr 2005
    Beans
    645
    Distro
    Dapper Drake Testing/

    Re: HOWTO: Automatic network configuration

    Quote Originally Posted by blueplazma
    HOWTO Whereami
    Originally by Reid Gilman
    goodstuff AT blueplazma DOT org
    8/4/2005


    1) What is Whereami?
    Whereami is a very useful little program that "automatically configures your system during boot and whenever a PCMCIA network card is inserted or removed." It can be used to switch settings and is very useful on laptops that move from trusted networks to untrusted networks.
    This HOWTO will cover setting up a laptop to differentiate a wired, wireless, and un-trusted wireless network. We will assume that this laptop is normally on a public, unsecured wireless network, but is also used on a home wireless network (which is also unsecured), as well as a home wired network. eth0 will be an ethernet card, and eth1 will be a wireless card. This HOWTO was tested on Ubuntu Hoary running on a Dell Inspiron 8600 with an Intel IPW2200(b/g).

    2) Where do I get Whereami?
    There are a few ways to get Whereami. I did this install on Ubuntu, so I used apt-get. On Ubuntu, simply
    Code:
    sudo apt-get install whereami
    For other distros, visit the download page.

    3) How do I configure Whereami?
    Whereami configuration involves two main files: /etc/whereami/detect.conf and /etc/whereami/whereami.conf. From now on, if I refer to one of these files, I mean for it to be prefaced by /etc/whereami. Thus, if I say, "Edit whereami.conf..." I mean "Edit /etc/whereami/whereami.conf". To begin setting up Whereami, cd into the whereami directory from a terminal.
    Code:
    cd /etc/whereami
    1) detect.conf
    detect.conf is the first of the two extremely important files to make whereami function. This file does what it sounds like: it detects on which network you are using a variety of tests. Ubuntu gives you an example detect.conf; I recommend moving it to detect.conf.default and opening a new version like so
    Code:
    sudo mv detect.conf detect.conf.default && sudo gedit detect.conf
    You should now have a nice shiny gedit window with nothing in it. You should set a "default" location. For our purposes, it will be "wireless". Enter the line
    Code:
     default wireless
    into your new detect.conf file.
    The next test is to determine if there is an ethernet cable plugged in or not, since that can rule out one possible configuration. We will use the testmii command to do so. testmii needs two arguements. The first is an interface to test, the second a network to enable should it find an ethernet cable. Since it is looking for an ethernet cable, it will enable the wired network if it finds one. eth0 is our ethernet card, so enter this line to check for an ethernet cable plugged into eth0
    Code:
    testmii eth0 lan
    Now let's tell Whereami what to do if an ethernet cable is plugged in.
    Code:
    if lan
    	set INTERFACE eth0
    	testdhcp 192.168.1.0/24 home-wired
    	testdhcp '*.*.*.*' wired
    	notat down
    else
    	notat wired,home-wired
    	always set INTERFACE eth1
    	always testap scan wlan
    fi
    So, what does all that mean? Some of it is plain old shell-scripting, but some is not. "set INTERFACE eth0" tells whereami to perform the following tests on the interface eth0. testdhcp tells whereami to test for a DHCP assigned IP address on the interface and activate the selected network if it finds one. "notat down" simply tells Whereami that we have some type of network, since down is going to be our selection when there is absolutely no connectivity. The last command of interest is "testap scan wlan". If you haven't guessed yet, this command simply scans for a wireless AP within range and activate the wlan network when it finds one.
    Now, we must determine if we are on our trusted wireless network or not.
    Code:
    if wlan
    	testssid MyHomeNetwork home-wireless
    	testap scan wlan wireless
    	always notat wlan
    fi
    "testssid MyHomeNetwork home-wireless" is our final test. If it finds an SSID for our trusted network, then it turns on the home-wireless network. Otherwise, it assumes we have an unknown network. It shuts off wlan because wlan is just a name to avoid conflict in if statements.

    2) whereami.conf
    Now that we know which network we are at, we need to tell Whereami to do something about it. whereami.conf does this, and is much more straightforward and self-explanatory than is detect.conf.
    Here is the first section of our whereami.conf.
    Code:
    	=rm /etc/network/interfaces.old
    
    +home-wired /etc/init.d/networking restart
    +home-wired /etc/init.d/firestarter restart
    +home-wired setresolver search <put in your settings here>
    There are really three things that need explanation here. First is the equals sign (=), which means to always perform the command, regardless of which network we were on before. The plus (+) means to perform this command only if we were not on this network before, and the minus (-) means to perform this command only if we were on this network before, but are NOT anymore. See the documentation for specifics. Also, please consider writing small firewall scripts to replace firestarter if you can. It will give you much better control over your firewall at different locations. I have done this, and have an /etc/init.d/trusted-network-firewall and /etc/init.d/untrusted-network-firewall script set up. That is beyond this HOWTO, but worth considering. Otherwise, the default firestarter setup should be fine for you.

    4) How do I make this all work now?
    Whereami should work on reboot, or by running the initscript (/etc/init.d/whereami). I found that this works well for me. I hope it works well for you too. These settings can be kind of difficult, but I found the included documentation to be very sparse, so I hope that this example will help you a bit to get off the ground. Obviously, whereami can be used for very complex networks including WEP and WPA, but most people do not need an extremely complex setup.
    nice HOWTO, kinda so usefull to me, but can you explain better detect.conf please? because i have a static wired connection and a secures wireless connection, so for the wired, no DHCP and for the wireless, i need to pass a key, how to do that? where to have insfo on that??
    thanks
    [My Blog] | [My Sites] | [My Ubuntu Guides]

    doc.gwos.org, the real successor of Ubuntu Guide

  3. #3
    Join Date
    Jan 2005
    Beans
    90

    Re: HOWTO: Automatic network configuration

    Quote Originally Posted by Gandalf
    nice HOWTO, kinda so usefull to me, but can you explain better detect.conf please? because i have a static wired connection and a secures wireless connection, so for the wired, no DHCP and for the wireless, i need to pass a key, how to do that? where to have insfo on that??
    thanks
    Hi Gandalf. I'll assume that eth0 is wired and eth1 wireless. You'll need to adjust that to your own settings. If you only want to use one or the other at a time, then try setting up a detect.conf like this:
    Code:
    #detect.conf
    
    #use wired by default
    default down
    
    #check for an ethernet cable in the wired interface
    testmii eth0 wired
    
    if wired #if it finds a cable
         set INTERFACE eth0
         notat down #then there must be some kind of connectivity, let's use it
    else
        notat wired #no cable found, must not be wired
        always set INTERFACE eth1
        always testssid <yoursssid> secure-wireless #make sure your ssid is present
    fi
    That code should do fine for detecting if you are at your wired or wireless connection. To use a WEP key, you need to set up your /etc/network/interfaces to include the proper key information in it. You could do this by copying /etc/network/interfaces to /etc/network/interfaces.wired and /etc/network/interfaces.wireless . Then, put your wired interface information in interfaces.wired, and the same for wireless. Make sure to include information for the loopback in both. Using whereami.conf, put in a like this:
    Code:
    #whereami.conf
    
    =rm /etc/network/interfaces.last
    
    +secure-wireless cp /etc/network/interfaces /etc/network/interfaces.last
    +secure-wireless cp /etc/network/interfaces.wireless /etc/network/interfaces
    +secure-wireless /etc/init.d/networking restart
    
    +wired cp /etc/network/interfaces /etc/network/interfaces.last
    +wired cp /etc/network/interfaces.wired /etc/network/interfaces
    +wired /etc/init.d/networking restart
    This config will basically change your /etc/network/interfaces file to be the appropriate one for the network you are on. You will need to edit those files yourself to include the proper information, but if you use information that currently allows you to connect, you should be fine. It worked out pretty well for me. Good luck.

  4. #4
    Join Date
    Apr 2005
    Beans
    645
    Distro
    Dapper Drake Testing/

    Re: HOWTO: Automatic network configuration

    something weird has happened with me.
    i installed whereami on my test installation (it was befor today, just to test everything, all drivers etc.... and install a real distro later to be clean and fresh) whereami worked well on my PC, i have IPCOP router so i was identifying each zone by the MAC address and if not available i was using wireless and beleive was like magic, it was so good but unfortunately on the fresh install, ubuntu just hang on "Configuring Network Interfaces" service, and Ctrl + C to continue but then it's not possible to use network interfaces and ifup -a hang also...
    do you know where can i have a log of errors or something like that?
    [My Blog] | [My Sites] | [My Ubuntu Guides]

    doc.gwos.org, the real successor of Ubuntu Guide

  5. #5
    Join Date
    Jan 2005
    Beans
    90

    Re: HOWTO: Automatic network configuration

    If you think whereami is the problem, add this line to your detect.conf:
    set DEBUGWHEREAMI 1


    If you don't know exactly what the problem is, then you'll need to check out /var/log/syslog and /var/log/messages. It could be a number of things, but those two are always a good place to start.

  6. #6
    Join Date
    Apr 2005
    Beans
    645
    Distro
    Dapper Drake Testing/

    Re: HOWTO: Automatic network configuration

    Quote Originally Posted by blueplazma
    If you think whereami is the problem, add this line to your detect.conf:
    set DEBUGWHEREAMI 1


    If you don't know exactly what the problem is, then you'll need to check out /var/log/syslog and /var/log/messages. It could be a number of things, but those two are always a good place to start.
    i already solved it, and i sent a mail to the author also, i don't know why but for some reason, ifup hangs, i commented this line
    Code:
    # Can't use --syslog because syslog starts after the network (bug #160187)
    /usr/sbin/whereami --run_from ${SITUATION} --hint ${SITUATION}
    in /etc/network/if-pre-up.d/whereami file, and it hangs no more working perfect for all my network zones
    [My Blog] | [My Sites] | [My Ubuntu Guides]

    doc.gwos.org, the real successor of Ubuntu Guide

  7. #7
    Join Date
    Oct 2004
    Beans
    235

    Re: HOWTO: Automatic network configuration

    how can I simply configure this to check for two different networks when my wireless is using wpa_supplicant?


    I'm thinking something very simple like:

    testmmi eth0 lan
    testmmi eth1 wireless

    if wireless
    set INTERFACE eth1
    testdhcp '*.*.*.*' dhcp
    else
    if lan
    set INTERFACE eth0
    testdhcp '*.*.*.*' dhcp
    fi
    fi


    and this in whereami:

    +lan /sbin/ifup eth0
    +wireless /sbin/ifup eth1


    can anyone make me some confs that work? I've been toying with this for a while now and it's somewhat lacking in documentation.

  8. #8
    Join Date
    Jan 2005
    Beans
    90

    Re: HOWTO: Automatic network configuration

    Quote Originally Posted by AndersAA
    how can I simply configure this to check for two different networks when my wireless is using wpa_supplicant?


    I'm thinking something very simple like:

    testmmi eth0 lan
    testmmi eth1 wireless

    if wireless
    set INTERFACE eth1
    testdhcp '*.*.*.*' dhcp
    else
    if lan
    set INTERFACE eth0
    testdhcp '*.*.*.*' dhcp
    fi
    fi


    and this in whereami:

    +lan /sbin/ifup eth0
    +wireless /sbin/ifup eth1


    can anyone make me some confs that work? I've been toying with this for a while now and it's somewhat lacking in documentation.
    Well, be careful with the testmii call, because it will only work with a wired interface. Something like this may work better.
    Code:
    testmii eth0 wired
     
    if wired
    set INTERFACE eth0
    testdhcp '*.*.*.*' dhcp
    else
    set INTERFACE eth1
    testdhcp '*.*.*.*' dhcp
    fi
    fi
    And for whereami.conf try what you already have. It should be fine.

  9. #9
    Join Date
    Oct 2004
    Beans
    235

    Re: HOWTO: Automatic network configuration

    Quote Originally Posted by blueplazma
    Well, be careful with the testmii call, because it will only work with a wired interface. Something like this may work better.
    thanks for the help, and I actually believe wpa_supplicant triggers the wired/not wired when it connects, allowing clients to run dhcp calls properly. Although it's a while since I've been playing with it

  10. #10
    Join Date
    Oct 2004
    Beans
    183

    Re: HOWTO: Automatic network configuration

    Could someone explain a bit more how whereami.conf works? Maybe post an example?

Page 1 of 6 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •