two computers, one wifi connection

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

two computers, one wifi connection

Post 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?
User avatar
JackScott
Member
Member
Posts: 1031
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Contact:

Re: two computers, one wifi connection

Post 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.
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: two computers, one wifi connection

Post by xvedejas »

How to do this on ubuntu? (relevant to my interests)
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: two computers, one wifi connection

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: two computers, one wifi connection

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: two computers, one wifi connection

Post 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?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: two computers, one wifi connection

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: two computers, one wifi connection

Post by xvedejas »

Um, and how would I go about setting that up?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: two computers, one wifi connection

Post 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
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply