# [SOLVED] Internet Connection Sharing (WLAN -> Ethernet)

## pertplus

Hello all,

I am trying to set up internet connection sharing but having been having difficulty. Here's whats up: 

-home wireless network (unencrypted)

-gentoo laptop with wireless card

-windows pc WITHOUT wireless card

-ethernet connection between the two

I saw a script online thru google, but I tried it and it didn't work, I think because I need to set up some kind of pseudo-interface for the internet to be shared over (??)

Right now, I have static ip setup on both machines. On this machine (gentoo laptop) eth0 is set to IP 192.168.0.1, and on windows it is set to 192.168.0.2, with gateway on 192.168.0.1 . I can ping each machine from the other with success. (strangely I can also ping 192.168.2.2 from the windows machine, this is my static wlan0 address on the laptop).

So what I understand is I need a script to set up ip forwarding (?) and also first need to create an interface to forward the traffic over (??) 

with prospective thanks for you help,

ppLast edited by pertplus on Wed Jun 22, 2011 8:15 pm; edited 1 time in total

----------

## cach0rr0

as far as the IP forwarding, you can enable this in /etc/sysctl.conf (doesn't take effect til next reboot)

to enable it without rebooting (a change that gets lost when you reboot, which is why you enable it in sysctl.conf)

```

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

```

as root 

start with that, no idea about setting up a special interface, as this isnt something i do myself (unless you mean a bridge?)

----------

## Hu

Is the wireless network unencrypted because you intend for it to be open or because you have not yet had time to secure it?  Do I understand correctly that you want the Windows machine wired to the laptop, which will then use a wireless card to communicate with a base station, and the base station has the Internet uplink?  This will limit all machines to the speed of the wireless, which is often much worse than even an old wired connection.

----------

## pertplus

thank you both for the replies.

cach0rr0, thanks for the info

hu, you are correct in your view of the newtwork setup. It's staying open. I know the speed will be limited, but there isn't another (acceptable) option as the router is two floors down.

What is the process to share in this network set up? I enable ipforwarding as described by cach0rr0, and then what?

----------

## pertplus

anoyone?  :Surprised: 

----------

## pertplus

Too easy! All I had to do was the following :

 *Quote:*   

> 
> 
> iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
> 
> 

 

 *Quote:*   

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

 

I now have internet on my windows machine which is connected to laptop by ethernet.

So easy its almost inexplicable how nobody gave the answer  :Very Happy: 

For any other noobs out there, the reason the comand wasn't working originally was I had the wrong gateway set for my LAN interface (eth0). For success, like this:

NOTE: I'm fairly sure this is a very insecure/lazy method of doing this. Any experts out there who would care to explain why are more than welcome to do so.

 *Quote:*   

> 
> 
> nano -w /etc/conf.d/net 
> 
> 

 

Your LAN interface (sharing TO):

**MAKE SURE your LAN gateway is your wireless router's ip

 *Quote:*   

> 
> 
> config_eth0=( "192.168.0.1 netmask 255.255.255.0 brd 192.168.0.255" )
> 
> routes_eth0=( "default via 192.168.2.1" ) 
> ...

 

And your WAN interface (sharing FROM):

 *Quote:*   

> 
> 
> config_wlan0=( "192.168.2.2 netmask 255.255.255.0 brd 192.168.2.255" )
> 
> routes_wlan0=( "default via 192.168.2.1" )
> ...

 

After setting this up, simply run the iptables and echo commands as above and you will be sharing internet! (after properly setting things up on the windows side of course - just set the same netmask and an ip within it ie 255.255.255.0 and 192.168.0.2 . for dns you can probly use sharing computer's ip, if not use google dns 8.8.8.8 )

----------

## pappy_mcfae

 *pertplus wrote:*   

> Too easy! All I had to do was the following :
> 
>  *Quote:*   
> 
> iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
> ...

 

Thanks for this. I always knew there had to be an easy way to share an IP with a Linux box. I've had some long incantations to iptables that proved worthless. This little lovely is just too easy to make happen. And since I use the old/new/maybe Funtoo network scripts, making all the interfaces go on and off is a snap. I'll post the net script once I get it working right, if anyone is interested.

Thanks again.

Cheers,

Pappy

----------

