Page 1 of 1

two computers, one wifi connection

Posted: Mon May 31, 2010 6:34 pm
by VolTeK
my friend has two computers side by side connected using a ethernet cord. the wifi connection on one computer is using the internet from the router, in the next room. he doesnt have a 50 ft ethernet cable to connect it to the router, only a 3 ft, and that wont do ofcourse. is there anyway that this person can connect to the internet of one wifi adapter? they are connected into a small 2 computer network both on windows 7 ultimate, but one has a wifi connection, and he doesnt have another wifi adapter. is there anyway both computers can use one wifi adapter for one wifi connection?

Re: two computers, one wifi connection

Posted: Mon May 31, 2010 9:23 pm
by JackScott
On the computer that has both ethernet and WiFi, go into the network connections window (where the adapters are listed) and select both of the connections. Then right-click on either of the connections (doesn't matter which one) and click Bridge Connections (or Create Bridge, or whatever it's called). Now just pretend it's all one big network.

Re: two computers, one wifi connection

Posted: Mon May 31, 2010 10:13 pm
by xvedejas
How to do this on ubuntu? (relevant to my interests)

Re: two computers, one wifi connection

Posted: Tue Jun 01, 2010 8:11 am
by thepowersgang
There's a trick I hacked together from a collection of tutorials that seems to work:

Code: Select all

#!/bin/sh
if [ $# -ne 2 ]
then
	echo "Usage: $0 <external interface> <internal interface>" >&2
	exit 1
fi

# Flush all the rules in filter and nat tables
iptables --flush
iptables --table nat --flush
# Delete all chains that are not in default filter and nat table
iptables --delete-chain
iptables --table nat --delete-chain

# Set up IP FORWARDing and Masquerading
iptables --table nat --append POSTROUTING --out-interface $1 -j MASQUERADE
iptables --append FORWARD --in-interface $2 -j ACCEPT

#Enables packet forwarding by kernel
echo 1 > /proc/sys/net/ipv4/ip_forward
This scripts sets up a pair of interfaces to act as a NAT.

You could also use brctl to bridge both connections, but I could never get that to work properly personally.

Re: two computers, one wifi connection

Posted: Tue Jun 01, 2010 12:57 pm
by xenos
I have a small server running Ubuntu which also works as a router, so it is connected to my DSL modem and provides internet access to any computer in my local network. I also use iptables, as shown in the code above. There is a nice tutorial on the web, which I used to set up my server and which explains the whole thing in more detail. You can find it here:

http://www.ecst.csuchico.edu/~dranch/LI ... tml#ipmasq

It's call "IP masquerading HOWTO", because this way of providing internet access to computers on a local network "hides" them behind a "mask", namely the router.

Re: two computers, one wifi connection

Posted: Wed Jun 02, 2010 1:43 pm
by xvedejas
thepowersgang wrote:There's a trick I hacked together from a collection of tutorials that seems to work:

Code: Select all

#!/bin/sh
if [ $# -ne 2 ]
then
	echo "Usage: $0 <external interface> <internal interface>" >&2
	exit 1
fi

# Flush all the rules in filter and nat tables
iptables --flush
iptables --table nat --flush
# Delete all chains that are not in default filter and nat table
iptables --delete-chain
iptables --table nat --delete-chain

# Set up IP FORWARDing and Masquerading
iptables --table nat --append POSTROUTING --out-interface $1 -j MASQUERADE
iptables --append FORWARD --in-interface $2 -j ACCEPT

#Enables packet forwarding by kernel
echo 1 > /proc/sys/net/ipv4/ip_forward
This scripts sets up a pair of interfaces to act as a NAT.

You could also use brctl to bridge both connections, but I could never get that to work properly personally.
I don't really know anything about networking or iptables, so I tried to run this script like "./script.sh wlan0 eth0" and it doesn't work. Anything I'm missing?

Re: two computers, one wifi connection

Posted: Wed Jun 02, 2010 6:37 pm
by thepowersgang
I forgot to say that you need to have two networks for that script. One subnet (say 10.0.0.0/24) for the eth0 side, and another (192.168.1.0/24 or your current subnet) on the wlan0 side.

Re: two computers, one wifi connection

Posted: Thu Jun 03, 2010 9:42 pm
by xvedejas
Um, and how would I go about setting that up?

Re: two computers, one wifi connection

Posted: Fri Jun 04, 2010 7:29 am
by thepowersgang
Just set the IP setting manually for the "local"/nat side to something like 10.0.0.1.
But for what you seem to want to do, it might be easier to look into making a true network bridge, so both computers get IPs from DHCP