# Switching eth0 <-> eth2 under openrc -- 99% SOLVED

## Felig

I have a system which has two ethernet interfaces, eth0 (static IP) and eth2 (DHCP) (eth1 exists but is not connected).  It also runs apache on 127.0.0.1.  These two ethernet interfaces can't both be up at once, but that's ok,they don't need to.  I can't change this and the reasons are immaterial.

Once a week I travel 150 miles to the site to run something like this:

```
/etc/init.d/net.eth0 stop

/etc/init.d/eth2 start

# miscellaneous work

/etc/init.d/net.eth2 stop

/etc/init.d/net.eth0 start
```

The rest of the time, I periodically ssh in for other maintenance work.  Yes, it sucks, but other things suck worse, and sometimes things just are what they are.  Life gives you lemons sometimes, and you have to learn to make lemonade.

This all used to work fine.  However, this last weekend (31 May 2008), it added a new wrinkle.  When I stop eth0, it also stops apache.  Apache doesn't use the eth0 address, only 127.0.0.1, so there is no need to bring apache down.  If I try /etc/init.d/apache2 start, it brings eth0 back up too, but without dropping eth2, which confuses the poor box something fierce, so if any of the work done while eth2 is up requires the local apache, I now have to make sure the needed pages are loaded before switching.  Furthermore, when I drop eth2 and restart eth0, it does not restart apache.  I have to wait for eth0 to come up in the background (only a few seconds) and restart apache manually.

Now I could live with this, but this evening (1 June 2008), after having driven the 150 miles away like I usually do, I discovered that altho the site is up and running, receiving email, and responding to pings, I can't ssh in -- connection refused.  It sure looks like dropping eth0 also shut down sshd, and bringing eth0 back up left sshd down just as it did with apache.

Since I don't have access to the machine until next weekend, I can't report emerge --info etc.  It is a ~amd64 system, and openrc is probably 0.2.5 -- it was up to date as of Saturday (31 May 2008).

I would ask help for several things.  Bear in mind that I won't be able to access this machine until the weekend (7 June 2008).  I would like to be prepared ahead of time.

1.  Does anybody know why this changed?  Did someone decide it would be a good idea to ass-u-me that apache is part and parcel of eth0 (but only when eth0 goes down)?

2.  Does anybody know how to disable this?  I am guessing I might be able to edit init.d/apache2 and/or init.d/net.* to change the dependencies.

3.  Does anybody know why bringing eth0 back up does not restart apache (and presumably sshd), since it is quite happy to stop it (and presumably sshd) when eth0 goes down?

4.  Is my guess correct, that dropping eth0 also drops ssh in addition to apache?Last edited by Felig on Mon Jun 09, 2008 1:35 am; edited 1 time in total

----------

## krisse

Sounds it might be somewhat similar to what I'm experiencing: after having switched to baselayout2 + openrc, SSH can sometimes just stop working. 

I don't know why; can't find anything in the logs. No services -- including sshd -- has changed status. Everything seems to be in order. Only I can't ssh in. Sometimes it just hangs, trying to connect. Sometimes it tells me right away that host is down.

A simple /etc/init.d/sshd restart does the trick.

I've just set LogLevel to verbose, and waiting for it to happen again...

----------

## Felig

I've been kicking myself regularly for the last several hours for not trying this before I left, but it never occurred to me that sshd would go down for any reason, especially "intentionally" when eth0 went down.  I did see the message about bringing down apache, but I also noticed it because the browser complained.  I might have missed a similar message about sshd coming down.  If sshd went down for other reasons, like your problem, it might have nothing to do with apache going down; I just don't know.

----------

## UberLord

You probably just have net.eth0 in the default runlevel.

This means, that as far as dependencies go, ONLY net.eth0 provides net. So when you stop net.eth0, your network services stop. If net.eth0 is stop and you start a service that requires net, it starts net.eth0.

This is correct behaviour, and a good default for most people. But how can you change it?

Well, a variety of ways. The easiest way is probably just to remove the net provision from net.*, and you can do this like so in /etc/conf.d/net

rc_provide="!net"

That basically means that for purposes of dependency no scripts provide net. As you've stated that you cannot have net.eth0 and net.eth2 active at the same time, this is probably the route you need to go down.

----------

## Felig

Where is "rc_provide" and its ilk documented?  It might behoove me to read up on this.

If I want net.lo to provide net, will it be something like "rc_provide="net.lo" or is this automatic and/or unnecessary?

----------

## UberLord

 *Felig wrote:*   

> Where is "rc_provide" and its ilk documented?  It might behoove me to read up on this.

 

/etc/rc.conf

man runscript

 *Quote:*   

> If I want net.lo to provide net, will it be something like "rc_provide="net.lo" or is this automatic and/or unnecessary?

 

It depends on the script  :Smile: 

For net.lo and scripts linked to it, they automatically provide net by default.

----------

## Felig

Just tried the rc_provide="!net" and it mostly worked, at least for apache.  I will have to investigate more tomorrow.

----------

## Felig

The "rc_provide=!net" fix has done the trick, but sometimes (not always) there is a flurry of messages about no net provided.  It doesn't always happen, and hasn't since the last reboot.  Maybe it needed to rejigger its dependencies once from a reboot.  I don't understand why it used to be fine before and not now, but I'll chalk it up to just more gentoo amateurness and stop worrying about it.

----------

## UberLord

Probably as you removed the net provision from net.lo.

Add this AFTER the other line

rc_provide_lo="net"

----------

