How to set up a ethernet connection through your laptop

Any and all things Laptop related.


Re: How to set up a ethernet connection through your laptop

Postby jh13 » Wed Nov 05, 2008 12:59 pm

ok. i am using my laptop to connect wireless via a router. and i wanna give my desktop internet , by using an ethernet cable from my laptop to the desktop, so that the connection is shared so that both pc's have internet access. I'm not sure how to set it so that the laptop lets the desktop have internet access. I've done it with windows and i am convinced there is a way with ubuntu, but not sure how.
jh13
U.E. Knowledgable
U.E. Knowledgable
 
Posts: 41
Joined: Tue Oct 14, 2008 2:35 pm
Location: maryland, usa
Age: 28
Operating System: Ultimate Edition 3.1 64 BIT



Re: How to set up a ethernet connection through your laptop

Postby deate » Wed Nov 05, 2008 1:11 pm

Why wouldn't you just add a nic to your desktop??? and let it connect to your wireless router??? Oh well, I'll think on what you're trying to do, and see what I can come up with... :D
User avatar
deate
Site Admin
 
Posts: 1336
Joined: Tue Dec 18, 2007 9:54 am
Location: South Texas
Age: 69
Operating System: Ultimate Edition 3.0 Lite



Re: How to set up a ethernet connection through your laptop

Postby jh13 » Wed Nov 05, 2008 1:18 pm

i would but i don't have one and i don't plan to buy one just for this pc. its an old optiplex gx 270. got the parts from at work, so it was free i'm just using it to test stuff for now, but i am planning on making my own pc. I've already got some info on where to go and such.
jh13
U.E. Knowledgable
U.E. Knowledgable
 
Posts: 41
Joined: Tue Oct 14, 2008 2:35 pm
Location: maryland, usa
Age: 28
Operating System: Ultimate Edition 3.1 64 BIT



Re: How to set up a ethernet connection through your laptop

Postby tuxsax » Wed Nov 05, 2008 5:47 pm

I think I undestand the problem...

I assume you have a wired NIC in your desktop, right? and you have both wired NIC and wireless NIC in your laptop.
I have a similar situation at home, just that the wireless router I'm using is at MY home and I can just plug a network cable for my desktop and be connected to the internet without needing my laptop.
The problem is if you're using someone else's nearby wireless and you can't just connect a cable to your desktop NIC. Is this your situation?

Anyway, in order to make it happen you'll have to turn your laptop linux into a router which performs NAT between your desktop and your wireless network. I guess the router also performs NAT so your desktop will be behind NAT twice, it works, but sometimes it can lead you to some weird problems...

So, here's how you can make it happen, please pay attention and adapt everything to your PC where needed, OK? We'll use iptables and linux ip forwarding capabilities.
1. Make sure you have iptables installed
Code: Select all
which iptables
/sbin/iptables

If not, install it
Code: Select all
sudo apt-get install iptables


2. Edit the file /etc/sysctl.conf
Code: Select all
sudo gedit /etc/sysctl.conf

and uncomment (remove the "#" from the beginning of the line) this line (in my case is line number 38)
before
Code: Select all
#net.ipv4.ip_forward=1

after
Code: Select all
net.ipv4.ip_forward=1

Save and close the file.

3. Now we need to make sure we start on a clean iptables configuration, so let's clean it up
Code: Select all
sudo iptables -F
sudo iptables -t nat -F
sudo iptables -t mangle -F

4. Now let's configure the network. I assume your network interfaces are wlan0 for your wireless internet and eth0 for your wired network (keep in mind you may need a cross connection cable) So please change if needed, to suit your setup. The IP address I chose is also an example, though it will work if you set it exactly like this.

Edit /etc/network/interfaces and add the needed settings for eth0
Code: Select all
sudo gedit /etc/network/interfaces

auto eth0
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0

Save exit and restart the networking
Code: Select all
sudo /etc/init.d/networking restart


5. Now we need to set up the iptables NAT and forwarding and save its configuration, for this "sudo" isn't enough, so we need to be root, be careful here!
Code: Select all
sudo -s
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i eth0 -j ACCEPT
iptables-save > -c /etc/iptables.rules
exit


6. In order to make it persistent after reboot, we need to edit again the file /etc/network/interfaces but this time you'll need to add the following line to the end of your "wlan0" section
Code: Select all
sudo gedit /etc/network/interfaces
auto wlan0 inet dhcp
...
...
post-up iptables-restore < /etc/iptables.rules



Save, exit, and now you can reboot your Laptop and see if all comes up nicely.
If you get by mistake locked down by iptables, the command "sudo iptables -F" will clean it all up for you.

From now on, any computer you connect to the wired NIC of your Laptop will be able to surf through it as long as you set them the networking properly, any IP you set on the Desktop from 192.168.0.2 and up to 192.168.0.255 with a default gateway 192.160.0.1 will be able to surf the internet.
Oh, almost forgotten, you should set DNS servers to your desktop too, you can get them from your Laptop settings.

I hope this helps and is not too complicated.
And remember what the 11th commandment says:
"Thou shalt not covet thy neighbours WiFi..." :lol: :lol: :lol:

Ziv
______________________________
Two things I love: Linux and my sax
tuxsax
U.E. Master
U.E. Master
 
Posts: 790
Joined: Sat Apr 26, 2008 4:15 am
Age: 47
Operating System: Ultimate Edition Beta Tester



Re: How to set up a ethernet connection through your laptop

Postby jh13 » Wed Nov 05, 2008 8:04 pm

you understand what i meant but i'm using our wifi. the router is way too far from the pc and its too much trouble to move the stuff around. lol.
i have a problem tho.
when i type :sudo iptables-save > -c /etc/iptables.rules
this prints out : Unknown arguments found on commandline
i did everything else u said to do.
jh13
U.E. Knowledgable
U.E. Knowledgable
 
Posts: 41
Joined: Tue Oct 14, 2008 2:35 pm
Location: maryland, usa
Age: 28
Operating System: Ultimate Edition 3.1 64 BIT



Re: How to set up a ethernet connection through your laptop

Postby tuxsax » Thu Nov 06, 2008 5:33 am

jh13 wrote:you understand what i meant but i'm using our wifi. the router is way too far from the pc and its too much trouble to move the stuff around. lol.
i have a problem tho.
when i type :sudo iptables-save > -c /etc/iptables.rules
this prints out : Unknown arguments found on commandline
i did everything else u said to do.


I was kidding about the "neighbours WiFi" actually I don't care if anyone does it or not, if there are people that don't care others connecting to their wireless, and I know a few, I asked a friend once if his wifi is secured, so he asked why, an I explained him that the whole building may be using his internet, to what he said "So what? I don't mind, I pay for the connection anyway so let them enjoy..." so be it...
I had the same situation at home with a computer that was far away the problem was wireless wasn't an option because there was no reception there and also the routers were expensive then, so I had to pull a large cable between rooms, made holes in the external walls, etc. I won't ever do it again, now I have a very good wireless router (Cisco 857W)

Please try taking the "-c" switch off and try again
Code: Select all
sudo iptables-save > /etc/iptables.rules


Let me know if this helps
Ziv
______________________________
Two things I love: Linux and my sax
tuxsax
U.E. Master
U.E. Master
 
Posts: 790
Joined: Sat Apr 26, 2008 4:15 am
Age: 47
Operating System: Ultimate Edition Beta Tester



Re: How to set up a ethernet connection through your laptop

Postby jh13 » Thu Nov 06, 2008 9:25 am

now i'm getting this.
:~$ sudo iptables-save > /etc/iptables.rules
bash: /etc/iptables.rules: Permission denied

is there someway i could just refresh everything and start fresh?
jh13
U.E. Knowledgable
U.E. Knowledgable
 
Posts: 41
Joined: Tue Oct 14, 2008 2:35 pm
Location: maryland, usa
Age: 28
Operating System: Ultimate Edition 3.1 64 BIT



Re: How to set up a ethernet connection through your laptop

Postby tuxsax » Thu Nov 06, 2008 12:06 pm

I've found what is the problem with the iptables-save, you must be root to do it, sudo is not enough, I've edited my original post, please pay attention to the differences
You don't have to start over from the beginning, if all the rest went ok with no problems you can only do item number five and it will be enough

I tried this at my laptop and it worked, so this time it will be ok.
Sorry for the inconvenience
Ziv
______________________________
Two things I love: Linux and my sax
tuxsax
U.E. Master
U.E. Master
 
Posts: 790
Joined: Sat Apr 26, 2008 4:15 am
Age: 47
Operating System: Ultimate Edition Beta Tester



Re: How to set up a ethernet connection through your laptop

Postby jh13 » Thu Nov 06, 2008 1:33 pm

hey, now this pops up,

sudo /etc/init.d/networking restart
* Reconfiguring network interfaces... /etc/network/interfaces:8: misplaced option
ifdown: couldn't read interfaces file "/etc/network/interfaces"
/etc/network/interfaces:8: misplaced option
ifup: couldn't read interfaces file "/etc/network/interfaces"

could u show me what ur interfaces looks like? i tihnk i may have deleted something that was needed or deleted something which made some sort of spelling error.

thanks alot for your help. lol. your prob going nuts by now.
jh13
U.E. Knowledgable
U.E. Knowledgable
 
Posts: 41
Joined: Tue Oct 14, 2008 2:35 pm
Location: maryland, usa
Age: 28
Operating System: Ultimate Edition 3.1 64 BIT



Re: How to set up a ethernet connection through your laptop

Postby tuxsax » Thu Nov 06, 2008 6:39 pm

Yes, you may have deleted something there, you should have something like this in your configuration file
Code: Select all
auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet dhcp
post-up iptables-restore < /etc/iptables.rules

auto eth0
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0


That's all, of course changing if needed your wireless and wired NIC interfaces names

Don't worry, I'm not going nuts, I hope neither you are, be patient, we'll make it work
Ziv
______________________________
Two things I love: Linux and my sax
tuxsax
U.E. Master
U.E. Master
 
Posts: 790
Joined: Sat Apr 26, 2008 4:15 am
Age: 47
Operating System: Ultimate Edition Beta Tester

PreviousNext

Return to Laptops-All topics

Who is online

Users browsing this forum: No registered users and 1 guest