# localhost listed twice, once ureachable, why?

## agrypa1

The network connection seems to be working fine. There is however a strange thing about 127.0.0.0/8 network addres.

Both route -n and ip route reveal this problem:

```

localhost linux # route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     0.0.0.0         255.255.255.0   U     5      0        0 br0

127.0.0.0       -               255.0.0.0       !     0      -        0 -

127.0.0.0       127.0.0.1       255.0.0.0       UG    0      0        0 lo

0.0.0.0         192.168.1.1     0.0.0.0         UG    5      0        0 br0

```

```

localhost linux # ip route 

192.168.1.0/24 dev br0  scope link  metric 5 

unreachable 127.0.0.0/8  scope host 

127.0.0.0/8 via 127.0.0.1 dev lo  scope link 

default via 192.168.1.1 dev br0  metric 5 

```

here is some more:

```
 ip link

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    link/ether 00:11:d8:1c:08:9e brd ff:ff:ff:ff:ff:ff

3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000

    link/ether 00:11:d8:1a:1d:e9 brd ff:ff:ff:ff:ff:ff

4: tap0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500

    link/ether a6:22:c7:74:02:33 brd ff:ff:ff:ff:ff:ff

6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN 

    link/ether 00:11:d8:1c:08:9e brd ff:ff:ff:ff:ff:ff

```

```

localhost ~ # ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    link/ether 00:11:d8:1c:08:9e brd ff:ff:ff:ff:ff:ff

    inet6 fe80::211:d8ff:fe1c:89e/64 scope link 

       valid_lft forever preferred_lft forever

3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000

    link/ether 00:11:d8:1a:1d:e9 brd ff:ff:ff:ff:ff:ff

4: tap0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500

    link/ether a6:22:c7:74:02:33 brd ff:ff:ff:ff:ff:ff

    inet6 fe80::a422:c7ff:fe74:233/64 scope link 

       valid_lft forever preferred_lft forever

6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN 

    link/ether 00:11:d8:1c:08:9e brd ff:ff:ff:ff:ff:ff

    inet 192.168.1.10/24 brd 192.168.1.255 scope global br0

    inet6 fe80::211:d8ff:fe1c:89e/64 scope link 

       valid_lft forever preferred_lft forever

```

I don't know where to look in order to get to know why this is so...

Any clues?

Agryppa

----------

## linear

Greetings,

How about posting your /etc/hosts and /etc/conf.d/net, please.

HTH.

----------

## agrypa1

 *linear wrote:*   

> Greetings,
> 
> How about posting your /etc/hosts and /etc/conf.d/net, please.
> 
> HTH.

 

```
  # /etc/hosts: Local Host Database

#

# This file describes a number of aliases-to-address mappings for the for 

# local hosts that share this file.

#

# In the presence of the domain name service or NIS, this file may not be 

# consulted at all; see /etc/host.conf for the resolution order.

#

#127.0.0.1   localhost.localdomain   localhost

#127.0.0.1   localhost.localdomain   localhost

## livebox TPSA

192.168.1.1 livebox

## Plip connection to debian laptop

#192.168.1.2   debian

# IPv4 and IPv6 localhost aliases

127.0.0.1   localhost

::1      localhost

#10.0.0.1 sabayonx86

#10.0.0.2 netgear

#  IPV6 versions of localhost and co

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

ff02::3 ip6-allhosts

#

# Imaginary network.

#10.0.0.2               myname

#10.0.0.3               myfriend

#

# According to RFC 1918, you can use the following IP networks for private 

# nets which will never be connected to the Internet:

#

#       10.0.0.0        -   10.255.255.255

#       172.16.0.0      -   172.31.255.255

#       192.168.0.0     -   192.168.255.255

#

# In case you want to be able to connect directly to the Internet (i.e. not 

# behind a NAT, ADSL router, etc...), you need real official assigned 

# numbers.  Do not try to invent your own network numbers but instead get one 

# from your network provider (if any) or from your regional registry (ARIN, 

# APNIC, LACNIC, RIPE NCC, or AfriNIC.)

#

 
```

```
 #-----------------------------------------------------------------------------

# Bridging (802.1d)

# For bridging support emerge net-misc/bridge-utils

# To add ports to bridge br0

#bridge_br0="eth0 eth1"

bridge_br0="eth0 tap0"

# or dynamically add them when the interface comes up

#bridge_add_eth0="br0"

#bridge_add_tap0="br0"

#bridge_add_eth1="br0"

# You need to configure the ports to null values so dhcp does not get started 

config_eth0="null"

config_tap0="null"

# Finally give the bridge an address - dhcp or a static IP

config_br0="dhcp" # may not work when adding ports dynamically

#config_br0="192.168.0.1/24"

# If any of the ports require extra configuration - for example wireless or

# ppp devices - we need to depend on them like so.

rc_need_br0="net.eth0 net.tap0"

# Below is an example of configuring the bridge

# Consult "man brctl" for more details

#brctl_br0="setfd 0

#brctl_br0="sethello 0"

#brctl_br0="stp on"

  
```

----------

## sera

Are you using baselayout2, then have a look at the content of /etc/init.d/network. The reason is there, a good answer why this is as it is and if it has to be like this I'm still lacking.

----------

## agrypa1

 *sera wrote:*   

> Are you using baselayout2, then have a look at the content of /etc/init.d/network. The reason is there, a good answer why this is as it is and if it has to be like this I'm still lacking.

 

Hi,

All entried in /etc/init.d/network are commented out. So I guess there is nothing there affecting my system. Yes I am using baselayout-2

Agryppa

----------

## sera

 *agrypa1 wrote:*   

> All entried in /etc/init.d/network are commented out. 
> 
> 

 

Do you by any chance confuse /etc/init.d/network with /etc/conf.d/network?

However, there is a function start() with an if statement of  uname = linux, then add route to localhost twice. Essentially covering the first of those.

I'm again not at a baselayout2 machine, so again no quote of the relevant code snippet. Sorry.

----------

## agrypa1

Ok, here is the start() function from baselayout-2 that I have on my machine:

```
   

start()

{

   local cr=0 r= int= intv= cmd= args= upcmd=

   if [ -z "$domainname" -a -s /etc/defaultdomain ]; then

      domainname=$(cat /etc/defaultdomain)

   fi

   if [ -n "$domainname" ]; then

      ebegin "Setting NIS domainname: $domainname"

      domainname "$domainname"

      eend $?

   fi

   einfo "Starting network"

   routeflush

   if [ "$RC_UNAME" = "Linux" ]; then

      ifconfig lo 127.0.0.1 netmask 255.0.0.0 || cr=1 

      route add -net 127.0.0.0 netmask 255.0.0.0 \

         gw 127.0.0.1 2>/dev/null

      route add -net 127.0.0.0 netmask 255.0.0.0 \

         gw 127.0.0.1 reject 2>/dev/null

   else

      ifconfig lo0 127.0.0.1 netmask 255.0.0.0 || cr=1

      route -q add -inet 127.0.0.0 -netmask 255.0.0.0 \

         127.0.0.1 -reject || cr=1

   fi

   eindent

   for int in $(interfaces); do

      local func= cf=

      intv=$(shell_var "$int")

      eval upcmd=\$ifup_$intv

      for func in ip ifconfig; do

         eval cmd=\$${func}_$intv

         if [ -n "$cmd" -o -f /etc/"$func.$int" ]; then

            cf=/etc/"$func.$int"

            break

         fi

      done

      [ -n "$cf" -o -n "$upcmd" -o \

         -f /etc/ifup."$int" -o -f "$cf" ] || continue

      veinfo "$int"

      case "$func" in

      ip)   func=runip; intup=false;;

      esac

      eindent

      runargs /etc/ifup."$int" "$upcmd"

      r=0

      dumpargs "$cf" "$cmd" | while read -r args; do

         case "$args" in

         ''|"#"*)   ;;

         "!"*)

               (

                   eval vebegin "${args#*!}"

                  eval "${args#*!}"

                  veend $?

               );;

         *)

               (

                   set -o noglob

                  eval set -- "$args"

                  vebegin "$@"

                  $func "$int" "$@"

                  veend $?

               );;

         esac

      done

      eoutdent

   done

   eoutdent

   eend $cr

   # Wait for any inet6 tentative addresses

   r=5

   while [ $r -gt 0 ]; do

      tentative || break

      sleep 1

      r=$(($r - 1))

   done

   

   if [ -n "$defaultroute" ]; then

      ebegin "Setting default route $defaultroute"

      route add default $defaultroute

      eend $?

   elif [ -n "$defaultiproute" ]; then

      ebegin "Setting default route $defaultiproute"

      ip route add default $defaultiproute

      eend $?

   fi

   if [ -n "$defaultroute6" ]; then

      ebegin "Setting default route $defaultroute6"

      if [ "$RC_UNAME" = Linux ]; then

         routecmd="route -A inet6 add"

      else

         routecmd="route -inet6 add"

      fi

      $routecmd default $defaultroute6

      eend $?

   elif [ -n "$defaultiproute6" ]; then

      ebegin "Setting default route $defaultiproute6"

      ip -f inet6 route add default $defaultiproute6

      eend $?

   fi

   return 0

}

```

In your last post did you mean I should add or substract an addition of a route to localhost?

thanks

Agryppa

----------

## Ant P.

The reject rule is there so loopback traffic never accidentally goes out via the default 0.0.0.0 route. That would be bad.

----------

## sera

```
if [ "$RC_UNAME" = "Linux" ]; then

      ifconfig lo 127.0.0.1 netmask 255.0.0.0 || cr=1

      route add -net 127.0.0.0 netmask 255.0.0.0 \

         gw 127.0.0.1 2>/dev/null

      route add -net 127.0.0.0 netmask 255.0.0.0 \

         gw 127.0.0.1 reject 2>/dev/null 
```

This snippet is the reason for the unreachable route. The second call to route makes the first unavailable. All I can say about it is it looks like  a workaround for a problem unknown to me and the developer did it intentionally.

----------

## sera

 *Ant_P wrote:*   

> The reject rule is there so loopback traffic never accidentally goes out via the default 0.0.0.0 route. That would be bad.

 

Questionable is the first call to route.

----------

## agrypa1

 *sera wrote:*   

>  *Ant_P wrote:*   The reject rule is there so loopback traffic never accidentally goes out via the default 0.0.0.0 route. That would be bad. 
> 
> Questionable is the first call to route.

 

I continue to have problems and struggle with the unreachable route mentioned at the start of the thread. Perhaps I will post what's going on here again:

```
ip route show scope host 

unreachable 127.0.0.0/8 

```

the above is the error i would like to wipe out.

And here is what happens in the local table:

```
ip route show table local

broadcast 192.168.1.0 dev br0  proto kernel  scope link  src 192.168.1.12 

broadcast 127.255.255.255 dev lo  proto kernel  scope link  src 127.0.0.1 

broadcast 192.168.1.255 dev br0  proto kernel  scope link  src 192.168.1.12 

local 192.168.1.12 dev br0  proto kernel  scope host  src 192.168.1.12 

broadcast 127.0.0.0 dev lo  proto kernel  scope link  src 127.0.0.1 

local 127.0.0.1 dev lo  proto kernel  scope host  src 127.0.0.1 

local 127.0.0.0/8 dev lo  proto kernel  scope host  src 127.0.0.1 

```

and yet another:

```
ip route show scope global

127.0.0.0/8 via 127.0.0.1 dev lo 

default via 192.168.1.1 dev br0  metric 6 

```

The file etc/init.d/network is posted earlier in this thread so please review it there.

any clues for me, maybe?

Agryppa

----------

## NightMonkey

Yep, old thread, but never answered it seems.  :Smile:  I'm wondering the same thing. What is the purpose of this reject route, in the context of the other hardcoded localhost routes in /etc/init.d/net.lo? Why not rather explicitly setup a localhost net (127.0.0.0/ :Cool:  route to go over localhost?

Is the dev who implemented this available to nicely educate us?  :Smile:  Thanks in advance.

----------

