# [SOLVED] same IP address with wlan and eth (only one up)

## disperato

I have an HP-CQ50 with wireless-ath9k (AR9280) and ethernet-forcedeth. I switch from cable to wireless and back several times a day. I would like to use the same IP address with eth0 and wlan0 interface where only one is up at a time.

Currently I'm using the following script:

```

if test "$1" = "eth"

then

echo "starting network on" ${1}0

#/etc/init.d/net.wlan0 stop

#ifconfig wlan0 down

#modprobe -r ath9k

#modprobe forcedeth

ln -sf /etc/init.d/net.lo /etc/init.d/net.eth0

/etc/init.d/net.eth0 start

#ifconfig eth0 192.168.1.10

#route add default gw 192.168.1.1 netmask 0.0.0.0 metric 1 eth0

fi

if test "$1" = "wlan"

then

echo "starting network on" ${1}0

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

#ifconfig eth0 down

#modprobe -r forcedeth

#modprobe ath9k

ln -sf /etc/init.d/net.lo /etc/init.d/net.wlan0

/etc/init.d/net.wlan0 start

#ifconfig wlan0 192.168.1.10

#route add default gw 192.168.1.1 netmask 0.0.0.0 metric 1 wlan0

fi

if test "$1" = "stop"

then

echo "/usr/sbi/connect.sh stop: stopping all network cards"

/etc/init.d/net.eth0 stop 2>&-

rm /etc/init.d/net.eth0 2>&-

/etc/init.d/net.wlan0 stop 2>&-

rm /etc/init.d/net.wlan0 2>&-

fi
```

with the following settings in /etc/conf.d/net:

```
config_eth0=( "192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255" )

#config_eth0=( "null" )

config_wlan0=( "192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255" )

#config_wlan0=( "null" )

routes_eth0=( "default gw 192.168.1.1" )

routes_wlan0=( "default gw 192.168.1.1" )

modules=( "iwconfig" "!wpa_supplicant" )

essid_wlan0="myessid"

channel_wlan0="8"

key_myessid="[1] mypassword key [1] enc open"
```

As you can see by the commented lines, I've already been playing with this issue, but to no avail. I even unloaded the relevant modules, as suggested here: http://osdir.com/ml/linux.hardware.thinkpad/2003-01/msg00077.html. No luck! Even rebooting doesn't erase the memory of previous routing stored somewhere(?).

The only way to juggling with the two cards is that of declaring:

```
config_eth0=( "192.168.1.11 netmask 255.255.255.0 broadcast 192.168.1.255" )
```

so that eth0->192.168.1.11 while it's up (connect.sh eth), whereas wlan0->192.168.1.10 while up (connect.sh wlan).  

I need to have the same ip address for issues with several internet applications that can't be worked out through iptables and the virtual server built-in into the router. Could anyone help?Last edited by disperato on Mon Oct 12, 2009 11:17 am; edited 1 time in total

----------

## krinn

what a complex script for that issue, can't you create a tun interface with the needed IP and connect your network cards to that tun ?

----------

## disperato

 *krinn wrote:*   

> what a complex script for that issue, can't you create a tun interface with the needed IP and connect your network cards to that tun ?

 

thank you for the prompt answer  :Smile: 

anyway the script is not that complex (four lines). I just left the commented lines to lt people willing to help to figure out what I had already experimented (particularly helpful if compared with the linked external post by another user).

Really, I don't have the foggiest idea what solution you're yalking about, because I'm not so expert on networking. Would you drop some line of code?

Thanx

----------

## disperato

ok, I emerged vtun but the docs are totally useless, and the vtund.conf can maybe be only read by a network engineer with 10+ years of experience.

Before this attempt, I tried ifplugd + ifslave, just to discover that any apparently logical settings in /etc/conf.d/net and /etc/conf.d/bonding (which I had to write from scratch by reading examples on the internet) will never work. Why? wlan0 is not an easy ethernet interface like every eth* due to the fact it's up only when connected etc.

By the way, to anyone who might be in the same troubles and is wondering why the hell "something" remembers the last route and ip addresses even if the pc is rebooted 30 times or just shutdown and switched on again... well it depends on the fucking router, it's not local. If the router is switched off and on again, the new ip address and route will work fine. That's oboiuvsly not a feasible solution, as well as logging into the router every time to handle the routing table.

I insist what I'm trying to achieve should be made simpler:

eth0 is on with, say, 192.168.1.10 and the gw is 192.168.1.1, while wlan0 is off, fine.

wlan0 is on with, say, 192.168.1.10 and the gw is 192.168.1.1, while eth0 is off, fine.

The dream of having a machine-related ip address seems to be very hard to accomplish.

----------

## krinn

http://wiki.openzaurus.org/HowTos/Bridging_with_Gentoo

all is explain here, it's simple as you will see.

you'll endup with

(sample)

eth0 192.168.1.12 -> br0

wlan0 192.168.1.14 -> br0

br0 192.168.1.99 -> routerIP

so finally it will do what you want, as your router will only see someone querying him from 192.168.1.99

----------

## disperato

I've tried what's written in the guide you suggest, but, though it seems pretty logical, it does not work (obviously I recompiled the kernel with bridging module). The reason, I suppose, is that the router retain the card's hw address associated with the ip address. So the only way to change from wlan to eth or the other way round is by switching off/on or restarting the router. To give another shot to what you suggest I've even tried to spoof the mac address by means of ifconfig (ifconfig hw ether hwaddress) using the most recent linked mac address. No way.

Same thing seen with bonding or "manual" scripts, which reinforces my guess...

I give up. I'll try to use wlan preferably, surrendering to the idea that changing interface means restarting the router. It's at home, no problem.

I'll give it some new attempts, should I handle a more sophisticated router in the future.

Thanx again, your suggestion has been helpful to learn new stuff.

----------

## disperato

I've got a solution by using bonding and ifenslave. For anyone who is concerned, here is it:

configure and recompile kernel with:

```
 Device Drivers --->

      [*] Network device support --->

                <M> Bonding driver support
```

install ifenslave

```
emerge ifenslave -av
```

put the following script in /usr/sbin/connect.sh

```
#!/bin/bash

#ver: 1.0 - date: 12/10/2009

if test "$1" = "eth"

then

connect.sh stop

echo "starting network on" ${1}0

modprobe bonding

ifconfig bond0 up

#Assign non-conflicting MAC address of your choice:

ifconfig bond0 hw ether 001122334455

ifconfig bond0 192.168.1.10

route add default gw 192.168.1.1 netmask 0.0.0.0 bond0

ifconfig eth0 up

ifenslave bond0 eth0 

fi

if test "$1" = "wlan"

then

connect.sh stop

echo "starting network on" ${1}0

modprobe bonding

ifconfig bond0 up

#Assign non-conflicting MAC address of your choice:

ifconfig bond0 hw ether 001122334455

ifconfig bond0 192.168.1.10

route add default gw 192.168.1.1 netmask 0.0.0.0 bond0

ifconfig wlan0 up

ifenslave bond0 wlan0

# The ESSID must be set the same into the router:

iwconfig wlan0 essid "myessid-without-quotes"

iwconfig wlan0 mode managed

# The channel must be either set to the same number (1-11) or to auto into the router:

iwconfig wlan0 channel 8

iwconfig wlan0 key open

# If you are using WEP set the same into the router:

iwconfig wlan0 key s:"my-13-characters-long-wep-ascii-password-with-no-quotes"

ifconfig wlan0 up

fi

if test "$1" = "stop"

then

echo "/usr/sbi/connect.sh stop: stopping all network cards"

ifenslave -d bond0 eth0 wlan0 2>&-

ifconfig wlan0 down 2>&-

ifconfig eth0 down 2>&-

ifconfig bond0 down 2>&-

modprobe -r bonding

```

```
usage: connect.sh  [eth|wlan|stop]
```

It's working fine under heavy stress tests, detaching wlan0 and attaching eth0 or viceversa repeatedly and randomly. What did the trick was the assignment of the same hw address to the bond0 device, otherwise inherited from the first (or the last? not sure) bonded device. Not doing so, may confuse some routers, like mine, needing to restart the router itself. Initially, though, try with MAC address filtering deactivated on the router.

Notice: using this with a direct ethernet cable connection works fine, but I still have issues (and I feel there is no solution either) with powerline adapters. That's because they have a their very own MAC address each, so what adapter's address should we use? I tried the possible combinations with no luck. This doesn't mean the powerline technology is bad, on the contrary I must thank it for the flawless internet connection used so far in the building I'm writing from (20mt+ distance from the ap).

PS: I'm not an English native writer, so I'm sorry for any mistake I have done.

----------

## loopx

I'm looking for "bonding" module, .. you miss to read this : 

http://www.mjmwired.net/kernel/Documentation/networking/bonding.txt

this module can be configured to do anything .. it's very good, you should have a look in it.

----------

