LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-21-2008, 11:02 PM   #1
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Rep: Reputation: 38
Question Issue with which interface my computer connects at boot.


In my office there are three available interfaces. Plus, I go to a coffee shop when on the road.

1. wired
2. My wpa encrypted wireless.
3. The neighbors unencrypted network in the office next door.
4. The coffee shop.

The problem ....
When I boot my notebook at my office desk, sometimes it connects with the wired connection, or sometimes with my encrypted wireless, and sometimes my neighbor's network.

I commented out the part of wpa_supplicant that enables you to connect to insecure networks to prevent connecting to the neighbor's network. However, that also disables connections at the coffee shop.

My question.... I want to be able to connect according to order of priority.
First wired (fastest), second my encrypted wireless when I am away from the desk. And third is the coffee shop. And of course, I do not want to connect to the other office.

How do I configure for that order of priority?

Here is my current setup:
Madwifi, atheros chipset. netgear wg511t

rc.inet1.conf
Code:
# Config information for eth0:
FNAME[1]="eth0"
IPADDR[0]=""
NETMASK[0]=""
USE_DHCP[0]="yes"
DHCP_HOSTNAME[0]=""

# Config information for ath0:
IFNAME[1]="ath0"
IPADDR[1]=""
NETMASK[1]=""
USE_DHCP[1]="yes"
WLAN_WPA[1]="wpa_supplicant"
WLAN_WPADRIVER[1]="wext"
wpa_supplicant
# WPA protected network, supply your own ESSID and WPAPSK here:
network={
proto=WPA
key_mgmt=WPA-PSK
ssid="*****"
psk=*******************************************************
}

# Plaintext connection (no WPA, no IEEE 802.1X),
# nice for hotel/airport types of WiFi network.
#network={
# key_mgmt=NONE
# priority=0
#}
 
Old 11-21-2008, 11:39 PM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
I can't comment on how to manage the wired network (I use Debian's 'ifplugd' tool). Of course you can take the source code and hack it to suit you - check wired, then start up wireless.

For the wireless, all you have to do to set the priority is to put networks into the order you want to check in your wpa_supplicant.conf file (or whatever file is used by your installation of wpa_supplicant); to distinguish between open networks that you know and generic open networks, just add stanzas for each open network you know - the ESSID (and the order in the conf file) will be used to distinguish them. The stanza for a generic open network does not specify the ESSID to match.
 
Old 11-22-2008, 06:03 PM   #3
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Original Poster
Rep: Reputation: 38
When watching the words scroll at boot, I noticed that the eth0 interface is read first probably according to rc.inet1.conf. Then the ath0 interface. I hope there is a way that after the first interface is connected there would be no further searching for a connection.

In addition, as I previously stated, when I uncommented the stanza that gives the ability to connect to any open network, at times I would be connected to my encrypted network and sometimes to the neighbors. As you stated, you are probably correct that the wpa_supplicant.conf is also read in order from top to bottom. However, though there is a connection with my encrypted network which is first in line, at times I still get connected to the neighbors unencrypted.

Is there a way that once dhcp obtains an ip address the search for additional connections stops?
 
Old 11-22-2008, 06:37 PM   #4
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Quote:
Originally Posted by okos View Post
Is there a way that once dhcp obtains an ip address the search for additional connections stops?
You need to read through the network setup scripts and alter them as necessary to get what you want.

For example, let the network script start with a test to see if you're already connected - you can do this by checking /etc/resolv.conf and also checking the default routing - if you're connected, then exit.

For your wired bit, you have to set that up so that a failed dhcp negotiation shuts down that interface.

I don't know wpa_supplicant that well; I have never read through the source code. One possible method (which does not use a wpa_supplicant.conf at all) is to write a script which goes through and attempts to connect to your known networks or to generic open networks. To do this you can first call 'iwlist ath0 scan' , process the output to recover a list of nets, delete known open nets which you don't want to connect to (such as the office next door), check the list of nets in the order of ESSIDs you're interested in (if I have "home_net", connect to that, if not check for "work_net", etc) and finally, decide what you want to do with your list of generic open nets.
 
Old 11-23-2008, 01:15 PM   #5
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Original Poster
Rep: Reputation: 38
There is the /etc/rc.d/rc.inet1 script but I have not learned how to write bash scripts yet. Does anyone know how to edit the script so that once a dhcp address is obtained, do nothing more.

Code:
#######################
# INTERFACE FUNCTIONS #
#######################

# Function to bring up a network interface.  If the interface is
# already up or does not yet exist (perhaps because the kernel driver
# is not loaded yet), do nothing.
if_up() {
  # Determine position 'i' of this interface in the IFNAME array:
  i=0
  while [ $i -lt $MAXNICS ]; do
    [ "${IFNAME[$i]}" = "${1}" ] && break
    i=$(($i+1))
  done
  # If the interface isn't in the kernel yet (but there's an alias for it in
  # modules.conf), then it should be loaded first:
  if ! grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then # no interface yet
    if /sbin/modprobe -c | grep -w "alias ${1}" | grep -vw "alias ${1} off" > /dev/null ; then
      echo "/etc/rc.d/rc.inet1:  /sbin/modprobe ${1}" | $LOGGER
      /sbin/modprobe ${1}
    fi
  fi
  if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then # interface exists
    if ! /sbin/ifconfig | grep -w "${1}" 1>/dev/null || \
      ! /sbin/ifconfig ${1} | grep "inet addr" 1> /dev/null ; then # interface not up or not configured
      if [ ! "${HWADDR[$i]}" = "" ]; then # Set hardware address _before_ the interface goes up:
        echo "/etc/rc.d/rc.inet1:  /sbin/ifconfig ${1} hw ether ${HWADDR[$i]}" | $LOGGER
 /sbin/ifconfig ${1} mtu ${MTU[$i]}
      fi
      if [ -x /etc/rc.d/rc.wireless ]; then
        . /etc/rc.d/rc.wireless ${1} start # Initialize any wireless parameters
      fi
      if [ "${USE_DHCP[$i]}" = "yes" ]; then # use DHCP to bring interface up
        [ ${DHCP_HOSTNAME[$i]} ] && DHCP_OPTIONS="-h ${DHCP_HOSTNAME[$i]}"
        [ "${DHCP_KEEPRESOLV[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -R"
        [ "${DHCP_KEEPNTP[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -N"
        [ "${DHCP_KEEPGW[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -G"
        [ ${DHCP_IPADDR[$i]} ] && DHCP_OPTIONS="$DHCP_OPTIONS -s ${DHCP_IPADDR[$i]}"
        echo "Polling for DHCP server on interface ${1}:"
        # If you set a timeout, you get one, even if the kernel doesn't think that
        # your device is connected, in case /sys isn't right (which it usually isn't
        # except right after the device is loaded, when it usually is):
        if [ "${DHCP_TIMEOUT[$i]}" = "" ]; then
          ifconfig ${1} up && sleep 1
          CONNSTATUS="$(cat /sys/class/net/${1}/carrier 2> /dev/null)"
          ifconfig ${1} down
          if [ "$CONNSTATUS" = "0" ]; then
            # The kernel has just told us the cable isn't even plugged in, but we will
            # give any DHCP server a short chance to reply anyway:
            echo "No carrier detected on ${1}.  Reducing DHCP timeout to 10 seconds."
            DHCP_TIMEOUT[$i]=10
          fi
        fi
        # 30 seconds should be a reasonable default DHCP timeout.  60 was too much.  :-)
        echo "/etc/rc.d/rc.inet1:  /sbin/dhcpcd -d -t ${DHCP_TIMEOUT[$i]:-30} ${DHCP_OPTIONS} ${1}" | $LOGGER
fi
        fi
      fi
    else
      if [ "$DEBUG_ETH_UP" = "yes" ]; then
        echo "/etc/rc.d/rc.inet1:  ${1} is already up, skipping" | $LOGGER
      fi
    fi
  else
    if [ "$DEBUG_ETH_UP" = "yes" ]; then
      echo "/etc/rc.d/rc.inet1:  ${1} interface does not exist (yet)" | $LOGGER
    fi
  fi
}

# Function to take down a network interface:
if_down() {
  # Determine position 'i' of this interface in the IFNAME array:
  i=0
  while [ $i -lt $MAXNICS ]; do
    [ "${IFNAME[$i]}" = "${1}" ] && break
 i=$(($i+1))
  done
  if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then
    if [ "${USE_DHCP[$i]}" = "yes" ]; then
      echo "/etc/rc.d/rc.inet1:  /sbin/dhcpcd -k -d ${1}" | $LOGGER
      /sbin/dhcpcd -k -d ${1} 2> /dev/null || /sbin/ifconfig ${1} down
      sleep 1
    else
      echo "/etc/rc.d/rc.inet1:  /sbin/ifconfig ${1} down" | $LOGGER
      /sbin/ifconfig ${1} down
    fi
    if [ -x /etc/rc.d/rc.wireless ]; then
      . /etc/rc.d/rc.wireless ${1} stop # Kill wireless daemons if any.
    fi
  fi
}
I would greatly appreciate some input. :-)
 
Old 11-23-2008, 03:56 PM   #6
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
rc.inet1 is apparently meant to be included in another file (via . /etc/rc.d/rc.inet1)
The functions in there would actually be called from another script. However, if you look at the if_up() function, you can ensure that the interface is brought down if the dhcp negotiation fails (often a timeout because there's no wire; sometimes there just isn't a dhcp server).

If you can find the script which includes rc.inet1 you may be able to make some modifications (just keep another copy of your mods somewhere because an upgrade can replace the script).

I don't know how to tell if a wire is plugged into an ethernet port though; maybe I should get the Debian 'ifplugd' source and have a peek. One extremely annoying thing is the long wait for the DHCP request timeout when there isn't even a cable plugged in.
 
Old 11-24-2008, 06:48 PM   #7
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Original Poster
Rep: Reputation: 38
The above code is from part of the /etc/rc.d/rc.inet1 script.
I posted what I thought was important and left the rest out for brevity.

At this point I have no clue how to edit the file to meet my needs. I am sure that I am not the only one with this issue. I thought maybe someone else has already solved the issue.

Therefore, I was hoping some already has the know how on correctly editing the script.

okos
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
usb drive connects as different devices when connecting to my computer okos Slackware 16 09-15-2008 12:26 AM
Help, Two network interface on same computer. ERBRMN Linux - Networking 2 04-17-2006 01:48 AM
vnc viewer only connects to its own computer DJOtaku Linux - General 5 11-10-2005 02:21 PM
My computer connects sometimes to the internet bucovaina78 Linux - Networking 1 11-09-2004 03:13 PM
Why I couldn't reach webmin interface from another computer? myeniad Linux - Software 0 07-09-2004 07:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration