# [Solved]How to access localhost when internet access is down

## ElleStone

When I start Gentoo with my network cable plugged in and with access to the internet, then do "startx" to start the icewm "desktop", this is what happens:

*the icewm taskbar shows the network monitoring applet. 

*"htop" shows "/bin/busybox udhcpc . . . " in the list of running processes. 

*apache2 can be started and stopped with /etc/init.d/apache2 start (stop, etc).

If I then unplug the network cable, obviously I can't access any websites on the world wide web, but I can still start and stop apache and I can still access my "localhost" test website. Also the network monitor applet is still on the icewm taskbar and htop still shows the "busybox" process.

However, when the network cable is unplugged *before* I start the computer, or if our household access to the internet is down (as alas happened fairly frequently), then after "startx" to get to icewm, this is what happens:

*the network monitoring applet appears for a brief moment, then disappears.

*the busybox process doesn't appears in the htop list of running processes.

*If I try to start apache2, the terminal output says: 

```
dhcp ... * Running udhcpc ... * start-stop-daemon: failed to start '/bin/busybox'

[some other lines]

*ERROR: net.eth0 failed to start

[a couple more lines]
```

How do I configure Gentoo so the eth0/localhost stuff works even if the internet is down when I start the computer? I double-checked with Kubuntu and when Kubuntu is started without internet access, it's still possible to access localhost, so it has to be possible to also do so with Gentoo, yes?

ElleLast edited by ElleStone on Wed May 15, 2013 11:51 am; edited 1 time in total

----------

## NeddySeagoon

ElleStone,

Correct.  

Xorg needs the network service to be started because its 'network transparent'.  That means that it talks to itself over the network, even on an isolated system.

On Gentoo, by default, the network service is only considered to be up when all interfaces are started.  That condition is not satified when you start with an interface unplugged. 

Knowing the above, read the comments in /etc/rc.conf and make the required change.

----------

## ElleStone

Hi NeddySeadragon,

Thank you very much for the hint. The line in rc.conf that jumped out was #rc_depend_strict="YES", which I changed to rc_depend_strict="NO". But the problem still persisted. I read through the rest of rc.conf several times, but nothing else seemed relevant. I also installed dhcpcd with the "autoconf" flag, thinking that might help. But it didn't.

However, your hint encouraged me to search farther. I found this older post (2004):

"Problem with /etc/init.d/net.eth0 at home"

https://forums.gentoo.org/viewtopic-t-145556-start-0-postdays-0-postorder-asc-highlight-.html

 *Quote:*   

> When I'm at home and work offline net.eth0 doesn't start and I can't start apache . . . if I change the parameter iface_eth0 from "dhcp" to a fixed ip address there is no problem. Of course when I work in office I must set "dhcp". 

 

Altering the contents of /etc/conf.d/net depending on whether the internet is available when the computer starts (especially when one doesn't know in advance whether the internet is available or not) isn't exactly the nicest way to be able to use apache to access localhost when the internet isn't available, because the file needs to be altered again when internet access is restored. 

I also found this page:

http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=4

which shows how to create different runlevels, perhaps one for when the internet is available and one for when it isn't. But again, for situations where the internet might be down when the computer is started, and come back up a minute or an hour later, restarting the computer to go to a different runlevel is a bit cumbersome.

I did solve my own immediate problem. I'm lucky enough to have two ethernet connections, eth0 and eth1. So I modified /etc/conf.d/net as follows:

```
config_eth0="dhcp"

config_eth1="0"
```

and I added eth1 to the default runlevel ("rc-update add net.eth1 default"). 

Thanks very much! for providing a hint that led to a solution. But for the majority of users who probably don't have two ethernet cards (I've never used the second card until this very day), is there an easier way?

ElleStone

----------

## NeddySeagoon

ElleStone,

Did you notice that rc_depend_strict= was commented out?

You need to uncomment it to change the setting.

----------

## ElleStone

 *Quote:*   

> Did you notice that rc_depend_strict= was commented out?
> 
> You need to uncomment it to change the setting.

 

Hi NeddySeadragon. Yes, I did notice and did uncomment it, but it didn't make any difference. When I get a chance I try the same thing on my laptop and see if it makes a difference there (the laptop uses udev rather than eudev, is 32-bit rather than 64-bit, only has one ethernet card instead of two, etc).

----------

## khayyam

ElleStone ...

very briefly, as I'm *supposed* to be busy :)

This is what I think you want (explanations to follow if needed):

```
# emerge ifplugd

# rc-update del eth1 default
```

/etc/conf.d/net

```
config_eth0="plug"
```

/etc/rc.conf

```
rc_depend_strict="NO"

rc_apache2_need="!net"
```

Of course, there are other ways, runlevels being my favourite for this kind of things, but for simplicities sake the above should be workable.

best ... khay

----------

## cwr

I use a host file and set up static fallback addresses in /etc/conf.d/net.  It seems to work

on and off line, but I've never bother to automate the change-over and I have to run

dhclient explicitly when I plug in a cable.  Probably (certainly) udev could be used

to do this.

Will

----------

## ElleStone

Will, khay, NeddySeadragon, thanks! 

The next thing on my "Gentoo to-do" list was "figure out how to keep the network from starting until I actually want it to start, without unplugging the network cable" (this particular computer almost never needs to be connected to the internet, except for when installing software), and you all already answered that question, too! Putting it all together:

In rc.conf:

```
rc_depend_strict="NO"

rc_apache2_need="!net"
```

Then

```
rc-update del eth0 default

rc-update del eth1 default

rc-update del netmount default
```

Now apache can be started without networking, I can start the computer with the network cable plugged in, but the computer won't actually connect to the network until I do "/etc/init.d/net.eth0 start", and I can kill network access with "/etc/init.d/net.eth0 stop", without also stopping apache from running. As "/bin/busybox/udhcpc" can start and stop the network, I don't need to install dhcp, dhcpcd, or ifplugd. 

Thank you, thank you, and thank you!

Elle

----------

## khayyam

 *ElleStone wrote:*   

> NeddySeadragon

 

Elle ... I never really saw Neddy as a dragon, more of a goon ... anyhow, for some reason that had me rotfl :)

best ... khay

----------

## ElleStone

Oops! My apologies NeddySeagoon! Obviously I've read waaay too many stories featuring dragons of one sort or another (the sea-going type obviously being the best type of dragon there is)!

ElleStone

----------

## cwr

 *ElleStone wrote:*   

> Oops! My apologies NeddySeagoon! Obviously I've read waaay too many stories featuring dragons of one sort or another (the sea-going type obviously being the best type of dragon there is)!
> 
> ElleStone

 

He's fallen in the water!

(Sorry, sorry, I'll just go out and come back in again quietly, shall I?)

Will

----------

