LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2005, 07:13 PM   #16
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380

troubleshooting is the proper term, debugging is for software developers... ;-)

yeah, they can be useful troubleshooting tools, but mianly they are configuration tools... remember that ifconfig and route are run automatically in your startup scripts and they set the values you put in your network configuration files...

they aren't only tools for you, they are necessary tools for your system also...

i'll post the slackware 10.1 /etc/rc.d/rc.inet1 file so you can see how it uses ifconfig and route to pick-up whatever configuration we've set in the /etc/rc.d/rc.inet1.conf:
Code:
#! /bin/sh
# /etc/rc.d/rc.inet1
# This script is used to bring up the various network interfaces.
#
# @(#)/etc/rc.d/rc.inet1 10.0  Sun Jun  6 23:42:32 PDT 2004  (pjv)

############################
# READ NETWORK CONFIG FILE #
############################

# Get the configuration information from /etc/rc.d/rc.inet1.conf:
. /etc/rc.d/rc.inet1.conf

###########
# LOGGING #
###########

# If possible, log events in /var/log/messages:
if [ /var/run/syslogd.pid -a -x /usr/bin/logger ]; then
  LOGGER=/usr/bin/logger
else # output to stdout/stderr:
  LOGGER=/bin/cat
fi

######################
# LOOPBACK FUNCTIONS #
######################

# Function to bring up the loopback interface.  If loopback is
# already up, do nothing.
lo_up() {
  if grep lo: /proc/net/dev 1> /dev/null ; then
    if ! /sbin/ifconfig | grep "^lo" 1> /dev/null ; then
      echo "/etc/rc.d/rc.inet1:  /sbin/ifconfig lo 127.0.0.1" | $LOGGER
      /sbin/ifconfig lo 127.0.0.1
      echo "/etc/rc.d/rc.inet1:  /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo" | $LOGGER
      /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo
    fi
  fi
}

# Function to take down the loopback interface:
lo_down() {
  if grep lo: /proc/net/dev 1> /dev/null ; then
    echo "/etc/rc.d/rc.inet1:  /sbin/ifconfig lo down" | $LOGGER
    /sbin/ifconfig lo down
  fi
}

######################
# ETHERNET FUNCTIONS #
######################

# Function to bring up an Ethernet interface.  If the interface is
# already up or does not yet exist (perhaps because the kernel driver
# is not loaded yet), do nothing.
eth_up() {
  # 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 eth${1}: /proc/net/dev 1> /dev/null ; then # no interface yet
    if /sbin/modprobe -c | grep -w "alias eth${1}" | grep -vw "alias eth${1} off" > /dev/null ; then
      echo "/etc/rc.d/rc.inet1:  /sbin/modprobe eth${1}" | $LOGGER
      /sbin/modprobe eth${1}
    fi
  fi
  if grep eth${1}: /proc/net/dev 1> /dev/null ; then # interface exists
    if ! /sbin/ifconfig | grep -w "eth${1}" 1>/dev/null || \
      ! /sbin/ifconfig eth${1} | grep "inet addr" 1> /dev/null ; then # interface not up or not configured
      if [ -x /etc/rc.d/rc.wireless ]; then
        . /etc/rc.d/rc.wireless eth${1} # Initialize any wireless parameters
      fi
      if [ "${USE_DHCP[$1]}" = "yes" ]; then # use DHCP to bring interface up
        if [ ! "${DHCP_HOSTNAME[$1]}" = "" ]; then
          echo "/etc/rc.d/rc.inet1:  /sbin/dhcpcd -d -t 10 -h ${DHCP_HOSTNAME[$1]} eth${1}" | $LOGGER
          /sbin/dhcpcd -d -t 10 -h ${DHCP_HOSTNAME[$1]} eth${1}
        else
          echo "/etc/rc.d/rc.inet1:  /sbin/dhcpcd -d -t 10 eth${1}" | $LOGGER
          /sbin/dhcpcd -d -t 10 eth${1}
        fi
      else # bring up interface using a static IP address
        if [ ! "${IPADDR[$1]}" = "" ]; then # skip unconfigured interfaces
          # Determine broadcast address from the IP address and netmask:
          BROADCAST=`/bin/ipmask ${NETMASK[$1]} ${IPADDR[$1]} | cut -f 1 -d ' '`
          # Set up the ethernet card:
          echo "/etc/rc.d/rc.inet1:  /sbin/ifconfig eth${1} ${IPADDR[$1]} broadcast ${BROADCAST} netmask ${NETMASK[$1]}" | $LOGGER
          /sbin/ifconfig eth${1} ${IPADDR[$1]} broadcast ${BROADCAST} netmask ${NETMASK[$1]}
        else
          if [ "$DEBUG_ETH_UP" = "yes" ]; then
            echo "/etc/rc.d/rc.inet1:  eth${1} interface is not configured in /etc/rc.d/rc.inet1.conf" | $LOGGER
          fi
        fi
      fi
    else
      if [ "$DEBUG_ETH_UP" = "yes" ]; then
        echo "/etc/rc.d/rc.inet1:  eth${1} is already up, skipping" | $LOGGER
      fi
    fi 
  else
    if [ "$DEBUG_ETH_UP" = "yes" ]; then
      echo "/etc/rc.d/rc.inet1:  eth${1} interface does not exist (yet)" | $LOGGER
    fi
  fi
}

# Function to take down an Ethernet interface:
eth_down() {
  if grep eth${1}: /proc/net/dev 1> /dev/null ; then
    if [ "${USE_DHCP[$1]}" = "yes" ]; then
      echo "/etc/rc.d/rc.inet1:  /sbin/dhcpcd -k -d eth${1}" | $LOGGER
      /sbin/dhcpcd -k -d eth${1} || /sbin/ifconfig eth${1} down
      sleep 1
    else
      echo "/etc/rc.d/rc.inet1:  /sbin/ifconfig eth${1} down" | $LOGGER
      /sbin/ifconfig eth${1} down
    fi
  fi
}

#####################
# GATEWAY FUNCTIONS #
#####################

# Function to bring up the gateway if there is not yet a default route:
gateway_up() {
  if ! /sbin/route -n | grep "^0.0.0.0" 1> /dev/null ; then
    if [ ! "$GATEWAY" = "" ]; then
      echo "/etc/rc.d/rc.inet1:  /sbin/route add default gw ${GATEWAY} metric 1" | $LOGGER
      /sbin/route add default gw ${GATEWAY} metric 1 2>&1 | $LOGGER
    fi
  fi
}

# Function to take down an existing default gateway:
gateway_down() {
  if /sbin/route -n | grep "^0.0.0.0" 1> /dev/null ; then
    echo "/etc/rc.d/rc.inet1:  /sbin/route del default" | $LOGGER
    /sbin/route del default
  fi
}

############
### MAIN ###
############

case "$1" in
'start') # "start" brings up all available interfaces:
  lo_up
  eth_up 0
  eth_up 1
  eth_up 2
  eth_up 3
  gateway_up
  ;;
'stop') # "stop" takes down all existing interfaces:
  gateway_down
  eth_down 3
  eth_down 2
  eth_down 1
  eth_down 0
  lo_down
  ;;
eth?_start) # "eth?_start" will start the specified interface
  INUM=`echo $1 | /bin/cut -c 4`
  eth_up $INUM
  ;;
eth?_stop) # "eth?_stop" will stop the specified interface
  INUM=`echo $1 | /bin/cut -c 4`
  eth_down $INUM
  ;;
eth?_restart) # "eth?_restart" will take the specified interface down and up again
  INUM=`echo $1 | /bin/cut -c 4`
  eth_down $INUM
  eth_up $INUM
  ;;
*) # The default is to bring up all interfaces:
  lo_up
  eth_up 0
  eth_up 1
  eth_up 2
  eth_up 3
  gateway_up
esac

# End of /etc/rc.d/rc.inet1

Last edited by win32sux; 05-20-2005 at 05:27 PM.
 
Old 04-28-2005, 10:15 PM   #17
Obie
Member
 
Registered: Apr 2004
Distribution: Red Hat
Posts: 290

Original Poster
Rep: Reputation: 30
That's true. I come from a programming background so I'll excuse myself ;-). Thanks for your help.
 
  


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
routes himyuza *BSD 6 08-03-2004 10:41 AM
where are routes stored? Ph0enix2003 Linux - Networking 1 06-23-2004 10:46 PM
I need some routes |Drakehash| Linux - Newbie 1 06-08-2003 12:22 AM
I need some routes |Drakehash| Linux - Networking 1 06-07-2003 02:36 PM
Multiple routes DavidPhillips Linux - Networking 2 12-03-2001 12:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:02 PM.

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