You are not logged in.

#1 2009-05-29 21:23:17

nfm
Member
Registered: 2008-06-13
Posts: 66

How to use eth and wlan ifaces at the same time?

Hi,
How can I use eth0 and wlan0 at the same time for 2 different purposes? wlan0 is connected to a separate router. I would like deluge to use wlan0, and the rest fallback to eth0. How can I route this?
Thanks.

Offline

#2 2009-06-01 02:45:18

nfm
Member
Registered: 2008-06-13
Posts: 66

Re: How to use eth and wlan ifaces at the same time?

Bump

Offline

#3 2009-06-01 04:56:59

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: How to use eth and wlan ifaces at the same time?

It's tricky, but should be possible...

#!/bin/bash

# Update these 3 variables to suit.
ETH0_GATEWAY='yyy.yyy.yyy.yyy'
WLAN0_GATEWAY='xxx.xxx.xxx.xxx'
TORRENT_PORTS=(49162 18925)

# Setup 2 Different Routing Tables; one for each gateway
ip route flush table 1
ip rule del fwmark 101 table 1
ip route add table 1 default via $ETH0_GATEWAY
ip rule add fwmark 101 table 1

ip route flush table 2
ip rule del fwmark 102 table 2
ip route add table 2 default via $WLAN0_GATEWAY
ip rule add fwmark 102 table 2

# ensure that traffic in one interface goes back out the same interface
iptables -t mangle -F PREROUTING
iptables -t mangle -A PREROUTING -j CONNMARK --restore-mark
iptables -t mangle -A PREROUTING -m mark ! --mark 0 -j ACCEPT
iptables -t mangle -A PREROUTING -i eth0 -m state --state NEW -j MARK --set-mark 101
iptables -t mangle -A PREROUTING -i wlan0 -m state --state NEW -j MARK --set-mark 102
iptables -t mangle -F OUTPUT
iptables -t mangle -A OUTPUT -j CONNMARK --restore-mark
iptables -t mangle -A OUTPUT -m mark ! --mark 0 -j ACCEPT

echo "Routing torrent traffic via $WLAN0_GATEWAY"
for PORT in "${TORRENT_PORTS[@]}" ; do
        iptables -t mangle -A OUTPUT -p tcp --dport $PORT -m state --state NEW -j MARK --set-mark 102
        iptables -t mangle -A OUTPUT -p udp --dport $PORT -m state --state NEW -j MARK --set-mark 102
        iptables -t mangle -A OUTPUT -p tcp --sport $PORT -m state --state NEW -j MARK --set-mark 102
        iptables -t mangle -A OUTPUT -p udp --sport $PORT -m state --state NEW -j MARK --set-mark 102
done

iptables -t mangle -A OUTPUT -j CONNMARK --save-mark
ip route flush cache

The only place I can think this might not quite work is if Deluge get's it's public IP address via your eth0 gateway, which means it will be telling all other torrent clients to connect to that address, whereas you actually want it to be telling them the gateway on wlan0.

Last edited by fukawi2 (2009-06-01 06:32:50)

Offline

#4 2009-06-01 06:11:07

nfm
Member
Registered: 2008-06-13
Posts: 66

Re: How to use eth and wlan ifaces at the same time?

Oh wow, I thought It would be simpler than that, I will check it out ASAP. Thanks cool.

Offline

Board footer

Powered by FluxBB