# Somewhat strange net.eth0 problem (Solved, Sort of.)

## Logician

Hello all,

I appriciate any help I can get on the following problem:

I recently did an emerge sync (within the last two days), and this morning went ahead and updated all the etc files that required it.  Now, for some reason, my network no longer works in the usual way.  It does, however, work to a certain degree.  

Upon boot-up, net.eth0 does NOT start dhcp correctly, and as a result all net based services told to boot on startup fail.  By logging in as root, and then manually typing the command 

```
dhcpcd
```

 I can get dhcp running.  At this point, I know that the internet is working - I can emerge things from root, and I can use links to connect to the internet.  However, when I go inside my window manager, no net based progams work: not firefox, limewire, or any other.  

The only error I get on typing the command 

```
dhcpcd
```

 is a few red exclamations marks after a line that reads 

```
default gateway 192.168.0.1   [!!!]
```

My machine recognizes my network card, and has limited access to the internet, as mentioned above.  What in the world is wrong with my setup?  I realize it is probably something ridiculous and simple, but for some reason I have no idea!  Help is appriciated.

Also, I would attempt to use net-setup, as recommended in the gentoo-guide, but for some reason my machine does not have that command.  What needs to be emerged in order to have it?Last edited by Logician on Tue Jul 12, 2005 2:36 pm; edited 2 times in total

----------

## adaptr

What is the contents of /etc/conf.d/net ?

You can't emerge net-setup - it is part of the LiveCD, not regular gentoo.

----------

## Logician

Okay - part of LiveCD.  Gotcha.  As for the second part of your question - 

These are the contents of conf.d net

```
# /etc/conf.d/net:

# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/conf.d/net,v 1.7 2002/11/18 19:39:22 azarah Exp $

# Global config file for net.* rc-scripts

# This is basically the ifconfig argument without the ifconfig $iface

#

#iface_eth0="192.168.1.102 broadcast 192.168.0.255 netmask 255.255.255.0"

#iface_eth1="207.170.82.202 broadcast 207.0.255.255 netmask 255.255.0.0"

# For DHCP set iface_eth? to "dhcp"

# For passing options to dhcpcd use dhcpcd_eth?

#

iface_eth0="dhcp"

#dhcpcd_eth0="-DH"

# For adding aliases to a interface

#

#alias_eth0="192.168.0.3 192.168.0.4"

# NB:  The next is only used for aliases.

#

# To add a custom netmask/broadcast address to created aliases,

# uncomment and change accordingly.  Leave commented to assign

# defaults for that interface.

#

#broadcast_eth0="192.168.0.255 192.168.0.255"

#netmask_eth0="255.255.255.0 255.255.255.0"

# For setting the default gateway

#

gateway="eth0/192.168.0.1"

```

Also - just did the same process - rebooted, got the not working dhcp thing, typed 

```
dhcpcd
```

 inside of my window manger, then started firefox, and it worked - but I still got the error in the beginning.  don't know if that makes a difference, but just thought I'd bring it up.

----------

## Logician

Bump

----------

## Logician

Bump

----------

## Logician

Anybody?  Any assistance would be greatly appriciated.

----------

## bvcarter

I think your problem is caused by the new net.eth0 script from the update.  I updated mine a couple of days ago and the new script is completely different from the old one.  I have not merged mine yet, and I am glad I didn't.  I am sorry that I do not have the answer to fix it, but maybe this will help you identify the problem.

If it helps, here is my pre-update net.eth0:

```

#!/sbin/runscript

# Copyright 1999-2004 Gentoo Technologies, Inc.

# Distributed under the terms of the GNU General Public License v2

# $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/net.eth0,v 1.41 2004/05/10 14:16:35 agriffis Exp $

#NB: Config is in /etc/conf.d/net

if [[ -n $NET_DEBUG ]]; then

   set -x

   devnull=/dev/stderr

else

   devnull=/dev/null

fi

# For pcmcia users. note that pcmcia must be added to the same

# runlevel as the net.* script that needs it.

depend() {

   use hotplug pcmcia

}

checkconfig() {

   if [[ -z "${ifconfig_IFACE}" ]]; then

      eerror "Please make sure that /etc/conf.d/net has \$ifconfig_$IFACE set"

      eerror "(or \$iface_$IFACE for old-style configuration)"

      return 1

   fi

   if [[ -n "${vlans_IFACE}" && ! -x /sbin/vconfig ]]; then

      eerror "For VLAN (802.1q) support, emerge net-misc/vconfig"

      return 1

   fi

}

# Fix bug 50039 (init.d/net.eth0 localization)

# Some other commands in this script might need to be wrapped, but

# we'll get them one-by-one.  Note that LC_ALL trumps LC_anything_else

# according to locale(7)

ifconfig() {

   LC_ALL=C /sbin/ifconfig "$@"

}

# setup_vars: setup variables based on $1 and content of /etc/conf.d/net

# The following variables are set, which should be declared local by

# the calling routine.

#   status_IFACE         (up or '')

#   vlans_IFACE            (space-separated list)

#   ifconfig_IFACE         (array of ifconfig lines, replaces iface_IFACE)

#   dhcpcd_IFACE         (command-line args for dhcpcd)

#   routes_IFACE         (array of route lines)

#   inet6_IFACE            (array of inet6 lines)

#   ifconfig_fallback_IFACE   (fallback ifconfig if dhcp fails)

setup_vars() {

   local i iface="${1//\./_}"

   status_IFACE="$(ifconfig ${1} 2>${devnull} | gawk '$1 == "UP" {print "up"}')"

   eval vlans_IFACE=\"\$\{iface_${iface}_vlans\}\"

   eval ifconfig_IFACE=( \"\$\{ifconfig_$iface\[@\]\}\" )

   eval dhcpcd_IFACE=\"\$\{dhcpcd_$iface\}\"

   eval routes_IFACE=( \"\$\{routes_$iface\[@\]\}\" )

   eval inet6_IFACE=( \"\$\{inet6_$iface\[@\]\}\" )

   eval ifconfig_fallback_IFACE=( \"\$\{ifconfig_fallback_$iface\[@\]\}\" )

   # BACKWARD COMPATIBILITY: populate the ifconfig_IFACE array

   # if iface_IFACE is set (fex. iface_eth0 instead of ifconfig_eth0)

   eval local iface_IFACE=\"\$\{iface_$iface\}\"

   if [[ -n ${iface_IFACE} && -z ${ifconfig_IFACE} ]]; then

      # Make sure these get evaluated as arrays

      local -a aliases broadcasts netmasks

      # Start with the primary interface

      ifconfig_IFACE=( "${iface_IFACE}" )

      # ..then add aliases

      eval aliases=( \$\{alias_$iface\} )

      eval broadcasts=( \$\{broadcast_$iface\} )

      eval netmasks=( \$\{netmask_$iface\} )

      for ((i = 0; i < ${#aliases[@]}; i = i + 1)); do

         ifconfig_IFACE[i+1]="${aliases[i]} ${broadcasts[i]:+broadcast ${broadcasts[i]}} ${netmasks[i]:+netmask ${netmasks[i]}}"

      done

   fi

   # BACKWARD COMPATIBILITY: check for space-separated inet6 addresses

   if [[ ${#inet6_IFACE[@]} == 1 && ${inet6_IFACE} == *' '* ]]; then

      inet6_IFACE=( ${inet6_IFACE} )

   fi

}

iface_start() {

   local IFACE=${1} i x retval

   checkconfig || return 1

   if [[ ${ifconfig_IFACE} != dhcp ]]; then

      # Show the address, but catch if this interface will be inet6 only

      i=${ifconfig_IFACE%% *}

      if [[ ${i} == *.*.*.* ]]; then

         ebegin "Bringing ${IFACE} up (${i})"

      else

         ebegin "Bringing ${IFACE} up"

      fi

      # ifconfig does not always return failure ..

      ifconfig ${IFACE} ${ifconfig_IFACE} >${devnull} && \

      ifconfig ${IFACE} up &>${devnull}

      eend $? || return $?

   else

      # Check that eth0 was not brought up by the kernel ...

      if [[ ${status_IFACE} == up ]]; then

         einfo "Keeping kernel configuration for ${IFACE}"

      else

         ebegin "Bringing ${IFACE} up via DHCP"

         /sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE}

         retval=$?

         eend $retval

         if [[ $retval == 0 ]]; then

            # DHCP succeeded, show address retrieved

            i=$(ifconfig ${IFACE} | grep -m1 -o 'inet addr:[^ ]*' | 

               cut -d: -f2)

            [[ -n ${i} ]] && einfo "  ${IFACE} received address ${i}"

         elif [[ -n "${ifconfig_fallback_IFACE}" ]]; then

            # DHCP failed, try fallback.

            # Show the address, but catch if this interface will be inet6 only

            i=${ifconfig_fallback_IFACE%% *}

            if [[ ${i} == *.*.*.* ]]; then

               ebegin "Using fallback configuration (${i}) for ${IFACE}"

            else

               ebegin "Using fallback configuration for ${IFACE}"

            fi

            ifconfig ${IFACE} ${ifconfig_fallback_IFACE} >${devnull} && \

            ifconfig ${IFACE} up &>${devnull}

            eend $? || return $?

         else

            return $retval

         fi

      fi

   fi

   if [[ ${#ifconfig_IFACE[@]} -gt 1 ]]; then

      einfo "  Adding aliases"

      for ((i = 1; i < ${#ifconfig_IFACE[@]}; i = i + 1)); do

         ebegin "    ${IFACE}:${i} (${ifconfig_IFACE[i]%% *})"

         ifconfig ${IFACE}:${i} ${ifconfig_IFACE[i]}

         eend $?

      done

   fi

   if [[ -n ${inet6_IFACE} ]]; then

      einfo "  Adding inet6 addresses"

      for ((i = 0; i < ${#inet6_IFACE[@]}; i = i + 1)); do

         ebegin "    ${IFACE} inet6 add ${inet6_IFACE[i]}"

         ifconfig ${IFACE} inet6 add ${inet6_IFACE[i]} >${devnull}

         eend $?

      done

   fi

   # Set static routes

   if [[ -n ${routes_IFACE} ]]; then

      einfo "  Adding routes"

      for ((i = 0; i < ${#routes_IFACE[@]}; i = i + 1)); do

         ebegin "    ${routes_IFACE[i]}"

         /sbin/route add ${routes_IFACE[i]}

         eend $?

      done

   fi

   # Set default route if applicable to this interface

   if [[ ${gateway} == ${IFACE}/* ]]; then

      local ogw=$(/bin/netstat -rn | awk '$1 == "0.0.0.0" {print $2}')

      local gw=${gateway#*/}

      if [[ ${ogw} != ${gw} ]]; then

         ebegin "  Setting default gateway ($gw)"

         # First delete any existing route if it was setup by kernel...

         /sbin/route del default dev ${IFACE} &>${devnull}

         # Second delete old gateway if it was set...

         /sbin/route del default gw ${ogw} &>${devnull}

         # Third add our new default gateway

         /sbin/route add default gw ${gw} >${devnull}

         eend $? || {

            true # need to have some command in here

            # Note: This originally called stop, which is obviously

            # wrong since it's calling with a local version of IFACE.

            # The below code works correctly to abort configuration of

            # the interface, but is commented because we're assuming

            # that default route failure should not cause the interface

            # to be unconfigured.

            #local error=$?

            #ewarn "Aborting configuration of ${IFACE}"

            #iface_stop ${IFACE}

            #return ${error}

         }

      fi

   fi

   # Enabling rp_filter causes wacky packets to be auto-dropped by

   # the kernel.  Note that we only do this if it is not set via

   # /etc/sysctl.conf ...

   if [[ -e /proc/sys/net/ipv4/conf/${IFACE}/rp_filter && \

         -z "$(grep -s '^[^#]*rp_filter' /etc/sysctl.conf)" ]]; then

      echo -n 1 > /proc/sys/net/ipv4/conf/${IFACE}/rp_filter

   fi

}

# iface_stop: bring down an interface.  Don't trust information in

# /etc/conf.d/net since the configuration might have changed since

# iface_start ran.  Instead query for current configuration and bring

# down the interface.

iface_stop() {

   local IFACE=${1} i x aliases inet6 count

   # Try to do a simple down (no aliases, no inet6, no dhcp)

   aliases="$(ifconfig | grep -o "^$IFACE:[0-9]*" | tac)"

   inet6="$(ifconfig ${IFACE} | awk '$1 == "inet6" {print $2}')"

   if [[ -z ${aliases} && -z ${inet6} && ! -e /var/run/dhcpcd-${IFACE}.pid ]]; then

      ebegin "Bringing ${IFACE} down"

      ifconfig ${IFACE} down &>/dev/null

      eend 0

      return 0

   fi

   einfo "Bringing ${IFACE} down"

   # Stop aliases before primary interface.

   # Note this must be done in reverse order, since ifconfig eth0:1 

   # will remove eth0:2, etc.  It might be sufficient to simply remove 

   # the base interface but we're being safe here.

   for i in ${aliases} ${IFACE}; do

      # Delete all the inet6 addresses for this interface

      inet6="$(ifconfig ${i} | awk '$1 == "inet6" {print $3}')"

      if [[ -n ${inet6} ]]; then

         einfo "  Removing inet6 addresses"

         for x in ${inet6}; do 

            ebegin "    ${IFACE} inet6 del ${x}"

            ifconfig ${i} inet6 del ${x}

            eend $?

         done

      fi

      # Stop DHCP (should be N/A for aliases)

      # Don't trust current configuration... investigate ourselves

      if /sbin/dhcpcd -z ${i} &>${devnull}; then

         ebegin "  Releasing DHCP lease for ${IFACE}"

         for ((count = 0; count < 9; count = count + 1)); do

            /sbin/dhcpcd -z ${i} &>${devnull} || break

            sleep 1

         done

         [[ ${count} -lt 9 ]]

         eend $? "Timed out"

      fi

      ebegin "  Stopping ${i}"

      ifconfig ${i} down &>${devnull}

      eend 0

   done

   return 0

}

start() {

   # These variables are set by setup_vars

   local status_IFACE vlans_IFACE dhcpcd_IFACE 

   local -a ifconfig_IFACE routes_IFACE inet6_IFACE

   # Call user-defined preup function if it exists

   if [[ $(type -t preup) == function ]]; then

      einfo "Running preup function"

      preup ${IFACE} || {

         eerror "preup ${IFACE} failed"

         return 1

      }

   fi

   # Start the primary interface and aliases

   setup_vars ${IFACE}

   iface_start ${IFACE} || return 1

   # Start vlans

   local vlan

   for vlan in ${vlans_IFACE}; do

      /sbin/vconfig add ${IFACE} ${vlan} >${devnull}

      setup_vars ${IFACE}.${vlan}

      iface_start ${IFACE}.${vlan}

   done

   # Call user-defined postup function if it exists

   if [[ $(type -t postup) == function ]]; then

      einfo "Running postup function"

      postup ${IFACE}

   fi

}

stop() {

   # Call user-defined predown function if it exists

   if [[ $(type -t predown) == function ]]; then

      einfo "Running predown function"

      predown ${IFACE}

   fi

   # Don't depend on setup_vars since configuration might have changed.

   # Investigate current configuration instead.

   local vlan

   for vlan in $(ifconfig | grep -o "^${IFACE}\.[^ ]*"); do

      iface_stop ${vlan}

      /sbin/vconfig rem ${vlan} >${devnull}

   done

   iface_stop ${IFACE} || return 1  # always succeeds, btw

   # Call user-defined postdown function if it exists

   if [[ $(type -t postdown) == function ]]; then

      einfo "Running postdown function"

      postdown ${IFACE}

   fi

}

# vim:ts=4

```

----------

## UberLord

The problem is that you're using dhcp and setting a default gateway - you can't do both.

Well, actually you can, but you would have to delete the defaut route DHCP provides or ask dhcp not to install a default root.

----------

## Logician

 *Quote:*   

> The problem is that you're using dhcp and setting a default gateway - you can't do both.
> 
> Well, actually you can, but you would have to delete the defaut route DHCP provides or ask dhcp not to install a default root.

 

Yep - thanks for that - I recognized that yesterday, actually, and fixed it - no change.  I am going to try to replace the new script with the old one, and see what happens.  I'll let you all know what happens.

----------

## Logician

Awesome - we're getting close to a fix here.  I replaced the new net.eth0 script with the old one, and now my network boots on start on its own.  (Thanks for the old config, bvcarter, it helped tremendously.)  Now, however, I am getting the following error on boot:

```
Please make sure the /etc/conf.d/net has $ifconfig.lo set (or $iface.lo for old style configuration.)
```

I understand what it wants, more or less, I simply don't know what bit of code I need to add.  Any more ideas guys?  All the help is greatly appriciated, and I'm looking forward to putting SOLVED in the post title.

----------

## bvcarter

You can try to change the net.lo script too.  It was also changed during the update and could also be a problem.  Here is mine.

```

#!/sbin/runscript

# Copyright 1999-2004 Gentoo Technologies, Inc.

# Distributed under the terms of the GNU General Public License v2

# $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/net.lo,v 1.10 2004/04/21 17:09:18 vapier Exp $

start() {

   ebegin "Bringing ${IFACE} up"

   /sbin/ifconfig lo 127.0.0.1 up 2>/dev/null

   /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 \

      gw 127.0.0.1 dev lo 2> /dev/null

   eend 0

}

stop() {

   ebegin "Bringing ${IFACE} down"

   /sbin/ifconfig ${IFACE} down &>/dev/null

   eend 0

}

```

Hope this helps.  I noticed while copying this that the update files may have just been swapped.  I wonder if this is a bug?

----------

## Logician

 *Quote:*   

> 
> 
> PostPosted: Mon Jun 27, 2005 2:57 pm    Post subject:
> 
> You can try to change the net.lo script too. It was also changed during the update and could also be a problem. Here is mine. 

 

No go - I thought that would work too - and thanks for posting the file - but, while it does fix the error, the network, even though it reads as if it was coming up properly, doesn't.  I get okays across the board, but I can't get my computer to recognize that it actually IS connected to the net.  Not quite sure what else to do....I replaced the net.lo file, and now have internet again, just with that bloody error.  Any other ideas anyone?

----------

## UberLord

 *Logician wrote:*   

> Awesome - we're getting close to a fix here.  I replaced the new net.eth0 script with the old one, and now my network boots on start on its own.  (Thanks for the old config, bvcarter, it helped tremendously.)  Now, however, I am getting the following error on boot:[code]Please make sure the /etc/conf.d/net has $ifconfig.lo set (or $iface.lo for old style configuration.)

 

The downside is that when baselayout next upgrades you have to do that all over again - you you're actually futher away from a fix

I told you have to "fix" your config a few posts up.

----------

## Logician

Yeah, thanks Uberlord - but I already mentioned that I fixed that WITHOUT your aid.  We've moved on from there.  Also, I don't intend to update the net for a while - if I get it to work properly again, I'll leave that alone, and mask it manually for a while, until a newer, perhaps more stable version comes out.

----------

## UberLord

Your loss

----------

## amzuk

just read /etc/conf.d/net.example

its very helpful, i recently made an update, n had sm problems, but after reading a while  everything works perfect (its pretty stable alerady, just takes some time to read)

----------

## Logician

Alright - I have this problem solved - kinda.  The problem is in passing commands from the net.eth0 to DHCP.  Somewhere in there a problem occurs, causing DHCP not to work properly.  Solution for the moment - set a static IP.  Then net boots properly.  I've read over net.example, and see a few ways of fixing the problem for real, but nothing has worked yet.  I'll post the solution once I have it completely working.  Thanks for all your help, everyone.  It was and is greatly appriciated.

----------

