# [solved] ad-hoc wifi network for wifi-only mobile device

## theRealMorpheu5

Hi there, I'm trying to set-up an ad-hoc network using my laptop (ipw2200, firmware version 3.1). I successfully created the network, and the mobile device can hook up to it, I was even able to configure it via dhcp, but at this point I'm stuck. Let's recap what I've done so far.

Knowing my eth0 is the wired interface connected to my router/gateway, and eth1 is the ipw2200 interface, I ran

```
# ifconfig eth1 down && iwconfig eth1 mode ad-hoc essid test channel 8 && ifconfig eth1 192.168.1.32 up
```

then I fired up wpa_gui and created the corresponding network, then I connected to it, and everything was good. Then I grabbed my mobile device, scanned for the networks list, and connected to the test network. Having configured dhcpd as follows

```
ddns-update-style none;

option domain-name-servers 8.8.4.4;

subnet 192.168.1.0 netmask 255.255.255.0 {

        host mobile_device {

                fixed-address 192.168.1.11;

                hardware ethernet F0:B4:79:D7:0C:5F;

                option domain-name-servers 8.8.8.8;

                option routers 192.168.1.1;

                option subnet-mask 255.255.255.0;

        }

}
```

my mobile device was correctly given the IP, the dns, the subnet mask, and the router (192.168.1.1 is the IP of my router/gateway) though it takes ages, I think that's because the router/gw also has dhcp enabled. Anyways.

Then I went back to my laptop and tried to

```
# ping 192.168.1.11

PING 192.168.1.11 (192.168.1.11) 56(84) bytes of data.

From 192.168.1.64 icmp_seq=2 Destination Host Unreachable

From 192.168.1.64 icmp_seq=3 Destination Host Unreachable

From 192.168.1.64 icmp_seq=4 Destination Host Unreachable
```

so I looked the routing table

```
# 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 eth0

192.168.1.0     *               255.255.255.0   U     0      0        0 eth1

loopback        *               255.0.0.0       U     0      0        0 lo

default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
```

which looks fine to me (but I'm no expert). Now I'm stuck. I can ping 192.168.1.32 from my laptop, but I can't ping 192.168.1.11. Using the mobile device, I can't connect to anything, not even 192.168.1.32 (I can only test using a web browser, but I have apache on my laptop and I already checked that from my laptop I can access 192.168.1.32 and apache correctly responds).

I tried setting up a bridge between eth1 and eth0, so I configured the kernel, installed net-misc/bridge-utils and issued the following commands:

```
# brctl addbr br0

# brctl addif br0 eth0

# brctl addif br0 eth1

can't add eth1 to bridge br0: Operation not supported
```

and then I have no more ideas.

I know this can be done, since I've done it with WinXP, by just creating the ad-hoc network and bridging the two interfaces together (not sure this last thing was actually necessary, but I saw it did no harm so I left it set up). So now: how do I do this in Linux (and is it possible to do it without bridging?).Last edited by theRealMorpheu5 on Fri Jan 28, 2011 11:19 am; edited 1 time in total

----------

## theRealMorpheu5

Up?

----------

## cwr

Summary of interfaces:

Laptop:

eth0 => router (192.168.1.1)

eth1 => 192.168.1.32

Mobile:

wlan0 192.168.1.11

Laptop => router succeeds.

Mobile => anywhere fails.

The default mobile path is to the laptop. The default laptop default is to the router.

So the laptop can never find the mobile.  I use subnetting for this problem, but that's

on an isolated network with it's own Bind.

Another approach I've used (a hack) was:

#!/bin/bash

# For permanence, add or uncomment the following line in /etc/sysctl.conf:

# net.ipv4.ip_forward = 1

# Drop current routes.

route del -net 193.237.32.224 netmask 255.255.255.224

route del -net 193.237.32.192 netmask 255.255.255.224

# Add new routes.

route add -net 193.237.32.192 netmask 255.255.255.224 gw 193.237.32.196 dev eth0

route add -net 193.237.32.224 netmask 255.255.255.224 gw 193.237.32.225 dev wlan0

# Show results.

route -n

# Set up proxy arp.

echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp

echo 1 > /proc/sys/net/ipv4/conf/wlan0/proxy_arp

echo 1 > /proc/sys/net/ipv4/ip_forward

# eof

Good luck - Will

----------

## theRealMorpheu5

Ok, thanks. As soon as the device can hook up again to the network (-.-) I'll try that.

----------

## theRealMorpheu5

Hi, sorry, I can't figure out what those IPs are supposed to refer to, except for the networks, of course, I don't know how to transpose those 196 and 225 to my situation.

----------

## theRealMorpheu5

Serendipity moment: why not adding a static route to host 192.168.1.11 (mobile device) with gateway 192.168.1.32 (ip for eth1) via dev eth1 (wifi card)?

```
# route add -host 192.168.1.11 gw 192.168.1.32 dev eth1
```

It worked. Out of nothing.

Opinions?

----------

## cwr

Sorry, I've got only intermittent contact with the Gentoo forums; for some

reason my local access provider has started to produce a blank page in lieu,

or to give the error message "too many connections".

The setup I described above is a desktop machine with a wired (eth0)

interface, address xxx.196, and a wireless (wlan0) AP, address xxx.225.

The idea is to use a 224, /27 mask to run two subnets, one starting at

192 and the other at 224. (This is all IPv4 notation.)  Then route between

the two subnets, adding filtering etc. to taste.  The Wikipedia subnetting

article is a useful starting point.  So is the Gentoo Home Router Guide.

OTOH, the setup I've described, while interesting, is unnecessary for your

purpose - on second thoughts, I'd just bridge the two interfaces.

Simply adding a single host to the AP with "route add -host address port"

would also work, but I don't think that the attached machine would then be

able to route beyond the AP; I'm not sure of this, so you'll have to try

it and see.  Getting packets from A to B is usually straightforward; getting

them back from B to A, usually less so.

Good luck - Will

----------

## theRealMorpheu5

Hi Will, thanks for your explanation, it really helped.

However I seem to have solved the issue with the following script

```
#!/bin/bash                                                                                                                                  

ifconfig eth1 down && iwconfig eth1 mode ad-hoc essid "porto-ap" channel 8 key s:pass___phrase && ifconfig eth1 192.168.1.32 up && route add -host 192.168.1.11 gw 192.168.1.32 dev eth1                                                                                                     

echo 1 > /proc/sys/net/ipv4/conf/all/proxy_arp                                                                                               

echo 1 > /proc/sys/net/ipv4/ip_forward
```

and configuring wpa_supplicant as follows:

```
network={                                                                                                                                    

        ssid="porto-ap"                                                                                                                      

        key_mgmt=NONE                                                                                                                        

        wep_key0="pass___phrase"                                                                                                             

        wep_tx_keyidx=0                                                                                                                      

}
```

Now I have a possibly unrelated issue which is a) how to configure Bind in order to map local.* to 192.168.1.32 (like local.www.example.com to 192.168.1.32 while forwarding the request for anything that's not local., like plain www.example.com... I'm told I need to set up an authoritative something and turn it on only when I need it) and b) how to actually make the device query this local Bind server.

I'll do some more research and then I'll probably open another thread, though.

----------

