# setting up wlan0 as gateway for eth0

## soigres

i have a wifi connection to my router and then to the internet; then i have connected my eth0 interface with a cross cable to another pc; now i want to go to the internet on the other pc passing through eth0 that passes trough wlan0... i set wlan 10.0.0.6 and its gatewsy and dns and it works... then i think to set eth0 192.168.0.1 and 10.0.0.6 as gateway and dns but it doesn't work... what's wrong?

ps - this is my first topic written by lynx... i hope it's all ok... firefox doesn't let me login...  :Sad: 

----------

## NeddySeagoon

soigres,

Since you have a private address range behind your router you can allocate IPs in the same subnet to all your interfaces and use forwarding in the PC with the WiFi and wired networks to allow the second PC to reach the internet.

You can use this script as the basis of of to set up your forwarding - its mostly comments.

```
#!/bin/bash

#

# ipaqnet       Control script for iPAQ USBNet connection

#

# Author: Michel Stempin

# Creation: 11/08/2002

# additional comments and minor tweaks

# Roy Bamford 6 Dec 2003

PC_ADDR=192.168.100.201

IPAQ_ADDR=192.168.100.202

IPAQ_NET=192.168.100.0/24

# WARNING:usb0 is hard coded in some places

UPLINK_IF=usb0

start() {

    # load the usb networking module

    /sbin/modprobe usbnet

    # bring up the PC end of the link with IP addr PC_ADDR

    # exit if it fails for some reason

    /sbin/ifconfig usb0 inet $PC_ADDR up

    if [ $? -ne 0 ]; then

        echo "Could not set up usb0"

        echo "Is the iPaq connected and switched on?"

        exit 1

    fi

    # set up proxy_arp for our usb interface

    echo "1" >/proc/sys/net/ipv4/conf/usb0/proxy_arp

    UPLINK=`/sbin/ifconfig $UPLINK_IF >/dev/null 2>&1`

    # exit if it fails for some reason

    if [ $? -ne 0 ]; then

        echo "Could not set up proxy_arp for usb0"

        exit 1

    fi

    # set up proxy_arp for eth0, so this better be our

    # internet connection

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

    # turn on IP forwarding

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

    # delete the unwanted route via usb0

    # its wrong anyway

    /sbin/route del -net $IPAQ_NET dev usb0

    # add the route we really want

    /sbin/route add $IPAQ_ADDR dev usb0

}

stop() {

    /sbin/ifconfig usb0 down

    # rmmod -r usbnet

}

case "$1" in

    start|add)

        start

        ;;

    stop|remove)

        stop

        ;;

    *)

        echo $"Usage: $0 {start|stop|add|remove}"

        exit 1

esac

```

You need forwarding support in your kernel. I don't think your second PC can use DHCP because DHCP broadcasts will not be forwarded. You can probably skip the module loading stuff at the start. This script predates hotplugging.

----------

## soigres

i don't understand what you say... let's make a resume:

first pc:

. wlan 0: ip 10.0.0.6; gateway & dns 10.0.0.2 (router)

. eth0:    ip 10.0.0.101; gateway & dns 10.0.0.6 (wlan0!)

second pc (with cross cable to eth0):

. ip 10.0.0.102; gateway & dns 10.0.0.101

ip and gateway are set in net and net.wlan0 net.eth0 set as default; dns are set in /etc/resolv.conf

but doesn't work... why? what's wrong?

----------

## NeddySeagoon

soigres,

I understand your network layout now. This PC

```
first pc:

. wlan 0: ip 10.0.0.6; gateway & dns 10.0.0.2 (router)

. eth0: ip 10.0.0.101; gateway & dns 10.0.0.6 (wlan0!) 

```

needs to have forwarding turned on with 

```
# turn on IP forwarding

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

Your kernel needs to support forwarding for this to work.

Also, forwarding makes the first PC 'transparent' so this PC

```
 second pc (with cross cable to eth0):

. ip 10.0.0.102; gateway & dns 10.0.0.101
```

shoukd have the gateway & dns set to 10.0.0.2. The same as the first PC.

If this does not help, please post the output of 

```
route -n
```

 from both PCs

----------

## soigres

many thanks!

i'm answering only now because i was looking for the ip_forward in the make menuconfig menu... but still no found!

----------

## NeddySeagoon

soigres,

I can't find it now either. Maybe its been permanently set to on.

Try the 

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

command and see if you get an error.

----------

## soigres

/proc/sys/net/ipv4/ip_forward doesn't exist... i create it but doesn't work.. i'll try later... thanks a lot!

----------

## NeddySeagoon

soigres,

You should not try to create things in /proc. Its not a real filesystem. Its a way of exposing kernel data structures so they can be changed without recompiling the kernel.

If you dont have /proc/sys/net/ipv4/ip_forward, then something is missing from your kernel. What do you have in /proc/sys/net/ipv4 ?

If thats missing, then you dont have any network support in your kernel.

----------

