Jump to content

ifplugd (and ifmetric)


coverup
 Share

Recommended Posts

Edited: Okay, I contacted the developer, and he pointed that there is another tool, ifmetric, which allows one to assign priorities to interface devices. Apparently, it ships with mandrake 10.x (I've seen an RPM on www.pbone.net). Is there anybody out there who uses it, or have seen it being used in network interface configuration scripts?

 

=======================

 

I need help with configuring ifplugd for monitoring two network interfaces.

 

I would like to monitor and configure the wired eth0 and the wireless eth1 as follows: If the network cable connected, activate eth0 and use it as default gateway. If the cable is disconnected, switch to eth1 and use it as default gateway.

 

So far, I did this

 # ifup eth0
# ifup eth1
# ifplugd --iface=eth0

The last command tells ifplugd to monitor eth0. Both interfaces are on the same network and connect to the same router. The default gateway is on eth0, and I can access the internet via eth0 just fine when the network cable is connected.

 

When I pull out the cable, ifplugd shuts eth0 down. Ifplugd also removes the default gateway eth0 from the routing table, but it does not add a gateway entry for eth1 to the routing table. This prevents packets from going out through eth1. I thought running ifplugd --iface=eth1 would fix the problem, but to no avail. Nothing works, except manually configuring eth1 as the default gateway.

 

Is there a way to make ifplugd not only tutn on/off interfaces but also configure default gateways?

 

Help is appreciated.

Edited by coverup
Link to comment
Share on other sites

Ok, it appears that Mandrake 10.1 does use ifmetric. Which means you can have a "Windows type" connection, i.e., both the wired and wireless interfaces are up, and the system sends packets to the fastest interface connected?

 

If somebody has this type of connection working, could you you then please post here the content of your ifcfg-eth0 and ifcfg-<wireless> as well as the output of ifconfig and route -n (run those as root).

 

Much appreciate

Link to comment
Share on other sites

there should be a script called /etc/ifplugd/ifplugd.action that is executed whenever the state of the interface changes.

 

if you run ifplugd with the options -r or --run=(script) then it will execute that script when the link status changes, and the default script is /etc/ifplugd/ifplugd.action.

 

i'm not sure how the script should go, but it should be something simple like:

 

/etc/init.d/net.eth0 stop

/etc/init.d/net.eth1 start

exit 0

 

but i'm running gentoo, so I'm not so sure how it would go on mandrake. also, won't linux applications automatically use the first available non-loopback interface, so you won't have to manually configure gateways?

Edited by arthur
Link to comment
Share on other sites

modifying ifplugd.action is not enough, you have to run ifplugd with the -r or --run=path option. like so

 

$ifplugd --iface=eth0 --run=/etc/ifplugd/ifplugd.action

 

about choosing to send packets to the fastest interface, that might be another matter, as you have to have a system of measuring the faster connection first (maybe pinging at regular intervals) but I'm not sure if ifplugd measures these.

 

most command-line linux network programs can choose the network interface manually, like the nmap -e option:

 

$ nmap -e eth1

 

hope this helps

Link to comment
Share on other sites

modifying ifplugd.action is not enough, you have to run ifplugd with the -r or --run=path option. like so

 

$ifplugd --iface=eth0 --run=/etc/ifplugd/ifplugd.action

 

Yep, got that working... I wrote two scripts, one brings down eth0 and brings up eth1 (wifi), another one does just an opposite thing. Then added those two scripts to ifplugd.action, ran the command as above, and it worked...

 

Now, it remains to figure out how to start ifplugd on boot. Of course, it can be permanently added to /etc/rc.local, that however would be too easy.... I like to start ifplugd as service. That way, I can control whether to start this service for a particular netprofile.

about choosing to send packets to the fastest interface, that might be another matter, as you have to have a system of measuring the faster connection first (maybe pinging at regular intervals) but I'm not sure if ifplugd measures these.

This is done by modifying the interface metric in the routing table. If you have both eth0 and eth1 present in the routing table, run

# ifmetric eth0 1
ifmetric eth1 0

and packets will go to eth1. To send packets to eth0, run

# ifmetric eth0 0
ifmetric eth1 1

Unfortunately, I can't use this trick. The problem is that even when I start two interfaces, the scrips leave me with only one default gateway configured, the 2nd gateway has to be added manually (this could have been fixed in 10.1, as 10.1 scripts are a lot different).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...