# adhoc -> wlan0 bridge to eth0

## andi_s

hi,

i try to get internet access from a mobile device.

as i do not have a wlan access point i try to establish an adhoc connection to my gentoo box (wlan0) that is connected via eth0 to the internet.

well, i think this can be done by bridging.

my setup:

802.1d Ethernet Bridging is enabled in kernel

bridge-utils are emerged

my dsl-router/gateway is on 192.168.1.1

my mobile device has a static ip: 192.168.1.7, gateway 192.168.1.1, dns 192.168.1.1

edit: real static dns server in mobile-device setup does not fix the problem

```

ifconfig eth0 0.0.0.0 netmask 255.255.255.0 up

ifconfig wlan0 down

iwconfig wlan0 mode ad-hoc

iwconfig wlan0 channel 7

iwconfig wlan0 essid test

ifconfig wlan0 0.0.0.0 netmask 255.255.255.0 up

brctl addbr br0

brctl addif br0 eth0

brctl addif br0 wlan0

ifconfig br0 192.168.1.2 netmask 255.255.255.0 up

route add default gw 192.168.1.1

route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     *               255.255.255.0   U     0      0        0 br0

loopback        *               255.0.0.0       U     0      0        0 lo

default         192.168.1.1     0.0.0.0         UG    0      0        0 br0

```

then i connect from my mobile device to adhoc connection 'test' and the mobile device tells me that it is connected.

the result:

ping 192.168.1.2 from my mobile device: OK

ping 192.168.1.7 from my gentoo box: OK

internet access from my gentoo box: OK

internet access from my mobile device: NOT POSSIBLE ):

i hope anybody here is able to help me and can explain what's wrong in my setup and how i can fix this to be able to connect to the internet with my mobile device via my gentoo box.

thanksLast edited by andi_s on Sun Oct 24, 2010 7:51 am; edited 3 times in total

----------

## chithanh

Bridging wireless and wired ethernet is hit-and-miss, and does not work with all drivers. Probably using different networks and using the laptop to route between them has a greater chance of success.

----------

## andi_s

hmm, so my setup is ok and it may be just the driver?

could ip-forwarding/masquerading be a possible way to solve this problem?

----------

## chithanh

You will have to assign wlan0 an address from 192.168.2.0/24 or similar, install a DHCP server such as dnsmasq, and enable ipv4 forwarding in /etc/sysctl.conf.

Then you have two options:

In your DSL/Broadband router, set your notebook's LAN address as gateway for 192.168.2.0/24

Enable NAT (masquerading) through iptablesVerify that your setup works by pinging the DSL router's LAN address from the mobile device.

----------

## reanimator

 *chithanh wrote:*   

> You will have to assign wlan0 an address from 192.168.2.0/24 or similar, install a DHCP server such as dnsmasq, and enable ipv4 forwarding in /etc/sysctl.conf.
> 
> Then you have two options:
> 
> In your DSL/Broadband router, set your notebook's LAN address as gateway for 192.168.2.0/24
> ...

 

I am trying to make the similar setup. What I can't get is how routing will target the problem with ARP:

Let's consider two nodes: remote node A and local node B.

remote node A connected to node B via wireless connection.

Node B has two interfaces: lan0 and wlan0.

Node A has one interface: wlan1.

```

[Node B]                 [Node A]

   br0                     /

  /    \        >>>>>     /

lan0  wlan0             wlan1

                <<<<<

```

Now Node A wants to ping Node B (br0)

1. Node A send ARP request with src address of MAC(wlan1) and broadcast dst address.

2. Node B receives the ARP request and replies with src address of MAC(br0) and dst address of MAC(wlan1)

3. Node A send ICMP packet to MAC(br0) via wireless, but this packet discarded by Node B wlan0 because dst MAC doesn't coincides.

So how iptables may helps here?

----------

## chithanh

No amount of iptables rules will help you if you attempt to bridge LAN and WLAN.

----------

