ifenelon
Posts: 17
Joined: Wed Jul 11, 2012 11:24 am

Internet Connection Sharing?

Wed Jul 11, 2012 2:45 pm

I know there are other solutions out there for internet connectivity where access to router is physically too far away for a striaghforward ethernet connection (eg wireless broadband USB dongles), but has anybody got any advice/solutions about the possibility of connecting the Pi to the internet using ICS (Internet Connection Sharing) by plugging an ethernet cable between a laptop connected wirelessly to the internet and the Pi?

Is this possible? Is this easy to set up by a novice (like me!)?

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: Internet Connection Sharing?

Wed Jul 11, 2012 9:15 pm

I'm doing that right now with my Pi. I'm running Linux on my desktop computer, plugged in to the Pi via Ethernet. Here's what I did:
On the host computer:
If NetworkManager is running: Right-click the network manager applet in the toolbar and select "Edit connections..." In the Wired tab, click Add. Click the IPv4 setting tab. Change Method from Automatic to Manual. Click Add and set Address to 192.168.0.1, Netmask to 255.255.255.0, and leave Gateway blank. Press save.
Open a text editor (i.e Gedit or Kate) then copy and paste the below:

Code: Select all

# Defines the location of iptables executables.
iptables=/sbin/iptables

#Clears if any old iptable rules/ policies are there.
iptables --flush -t nat

 # Now we will do Masquerading ie. we are doing NAT.
iptables --table nat --append POSTROUTING --out-interface wlan0 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT

 # Enabling packet forwarding.
echo 1 > /proc/sys/net/ipv4/ip_forward
Save the file to your home folder with the name "ipmasq.sh"
Now open a terminal and run the command:

Code: Select all

chmod 755 ipmasq.sh
This command allows the file to run as a program and only needs to be run once.
Then, run this command:

Code: Select all

sudo ./ipmasq.sh
Your computer should now be sharing it's internet connection.

Now, to set up the Pi:
Run the following commands:

Code: Select all

sudo ifconfig eth0 192.168.0.2
sudo route add default gw 192.168.0.1
You should now be able to connect to the Internet from your Pi.

ifenelon
Posts: 17
Joined: Wed Jul 11, 2012 11:24 am

Re: Internet Connection Sharing?

Wed Jul 11, 2012 9:41 pm

Sorry - this looks like a great solution but my host laptop, wirelessly connected to the internet, is running Windows 7, not Linux.

I have got as far as sharing the wireless connection with other networks, having connected my Pi to the ethernet port on the laptop with an ethernet cable. However, I am not able to get any web pages on the Pi, so I guess I am not connected.

I read somewhere that I need a crossover cable, so I guess this is something I need to try before I delve any further...
Is crossover cable essential? I am using a standard ethernet cable at the moment.

BTW - the Local Network Connection is showing as "unidentified network" on the "Network Connections" screen.

The laptop is ruinning zonealarm firewall too. Will I need to open up any firewall ports?
Thanks for your help so far. This is a great forum! :)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Internet Connection Sharing?

Wed Jul 11, 2012 9:47 pm

It should "just work". I can think of no reason why it wouldn't. Yes, I am familiar with ICS and have used it often under Windows XP.

P.S. You should not even need a "crossover" cable. In the old days, you did, but nowadays, they have auto-sensing ports that eliminate the need. And yes, it has been verified here that the Pi has the new kind of ethernet port. So, any old cable should work.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: Internet Connection Sharing?

Wed Jul 11, 2012 11:31 pm

A crossover shouldn't be needed, modern network cards can detect the connection type automatically.
ICS from Windows provides a DHCP server. Try the following commands on the Pi:

Code: Select all

sudo ifconfig eth0 up
sudo dhclient -v eth0
The first command turns on the Pi's network card, the second command tells it to try and get an IP address from the computer sharing the internet connection. If the second command never finishes but keeps trying different things, press Ctrl+C to abort the command. If it says something like "Bound to 192.168.2.4" (the number at the end will be different) then you've successfully connected.

ifenelon
Posts: 17
Joined: Wed Jul 11, 2012 11:24 am

Re: Internet Connection Sharing?

Thu Jul 12, 2012 4:57 pm

Thanks for the replies.
I will try this next time I get time to pursue my latest hobby....hopefully tomorrow evening....

When I signed off trying to fix this (late) last night, I noticed that all of the lights were flashing on the Pi (some green, one yellow) and the LAN port on my laptop was flashing yellow too, which seemed to indicate a connection (?).

So I pinged a couple of website urls from the Pi command line and got IP addresses for the urls's back, which again, seems to indicate some sort of a connection...

The ping seemed to hang though, and I needed to ctrl-z to interrupt it. Not sure if this is normal in Linux (?).
I still can't see websites through the browser though...

From this, I am deducing that the issue may lie more in the interface between the network connections on the laptop (ICS). I may need to make some further setting changes in there (?) to get the link working between the Ethernet connection to the Pi and the wireless internet connection the laptop has.

However, I will try the commands you suggest before I do anything else...


Regards,

Ian

ifenelon
Posts: 17
Joined: Wed Jul 11, 2012 11:24 am

Re: Internet Connection Sharing?

Fri Jul 13, 2012 9:36 pm

I have just set everything up again and tried the sudo commands.
I get a few messages like DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 0
then
no DHCP offers received
no working leases in persistent database - sleeping

?

ifenelon
Posts: 17
Joined: Wed Jul 11, 2012 11:24 am

Re: Internet Connection Sharing?

Fri Jul 13, 2012 10:26 pm

Having looked around other posts, I think I have my solution....
A Network Bridge.
A piece of cake to set up in windows 7.
This YouTube video shows you how.

http://www.youtube.com/watch?v=OFLtw0uxDYY

My Pi is now connected to the internet through an ethernet cable to my laptop and out through wireless on the laptop to the internet.

Many thanks everyone for helping me out with this.
Means we can work out of my "den" and access the web without taking up one of the valuable USB ports on the Pi or investing in a powered USB hub.

Hurray!

monkeymatt501
Posts: 3
Joined: Sun Jul 15, 2012 4:45 pm

Re: Internet Connection Sharing?

Sun Jul 15, 2012 4:51 pm

ifenelon wrote:Having looked around other posts, I think I have my solution....
A Network Bridge.
A piece of cake to set up in windows 7.
This YouTube video shows you how.

http://www.youtube.com/watch?v=OFLtw0uxDYY

My Pi is now connected to the internet through an ethernet cable to my laptop and out through wireless on the laptop to the internet.

Many thanks everyone for helping me out with this.
Means we can work out of my "den" and access the web without taking up one of the valuable USB ports on the Pi or investing in a powered USB hub.

Hurray!
Hi ifenelon,

I'm trying to much the same as you and have set up my internet connection on my laptop as shown. I've plugged my pi and laptop together but have had no sucess so far getting them to talk to each other (I've tried some of the stuff above)-can I ask what you did on your pi's end to get it going?

thanks!

ifenelon
Posts: 17
Joined: Wed Jul 11, 2012 11:24 am

Re: Internet Connection Sharing?

Sun Jul 15, 2012 8:41 pm

I didn't need to do anything on the Pi. I got everything to talk to each other by setting up the bridge between my wired and wireless networks on the laptop and all seemed to work.

Perhaps I just got lucky..!

I am running Windows 7 and followed the YouTube video mentioned previously.

I think I needed to wait a short while for the Pi to connect up.
Once you have the bridge set up, try to ping a couple of known URLs from the Pi command line before trying to access web pages through the browser.

Cheers,

Ian

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Internet Connection Sharing?

Sun Jul 15, 2012 9:44 pm

Keep in mind that this is Windows we're talking about here, so networking stuff will work on an "on and off" basis. With networking under Windows, things frequently work for a while, then stop working, then start working again, and so on. Sometimes, you need to kick things from time to time to keep them working.

I speak from much experience.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

007-half
Posts: 14
Joined: Wed May 30, 2012 4:23 pm

Re: Internet Connection Sharing?

Mon Jul 16, 2012 4:24 pm

Indeed, "Where's that confounded bridge?" :)

monkeymatt501
Posts: 3
Joined: Sun Jul 15, 2012 4:45 pm

Re: Internet Connection Sharing?

Mon Jul 16, 2012 8:26 pm

More sucess than yesterday (in that setting up a bridge no longer disables my internet connection on my windows 7 laptop) but the pi keeps returning 'unknown host' both when I try to ping and on midori. Any suggestions out there- thanks for helping a linux rookie!

007-half
Posts: 14
Joined: Wed May 30, 2012 4:23 pm

Re: Internet Connection Sharing?

Tue Jul 17, 2012 6:30 am

monkeymatt501 wrote:More sucess than yesterday (in that setting up a bridge no longer disables my internet connection on my windows 7 laptop) but the pi keeps returning 'unknown host' both when I try to ping and on midori. Any suggestions out there- thanks for helping a linux rookie!
I gave up with the bridge, finally found this works:-

Ethernet cable (normal) from RPi to Window 7 laptop.

Internet Connection Sharing set-up as per "http://windows.microsoft.com/en-us/wind ... on-Sharing"

Hope that helps.

ifenelon
Posts: 17
Joined: Wed Jul 11, 2012 11:24 am

Re: Internet Connection Sharing?

Tue Jul 17, 2012 10:22 am

I got the bridge working after having trouble with ICS, using those instructions...
Looks like the answer is to try both ICS / Bridge, one at a time until one of them works!

Thanks everyone. Great forum. :)

monkeymatt501
Posts: 3
Joined: Sun Jul 15, 2012 4:45 pm

Re: Internet Connection Sharing?

Tue Jul 17, 2012 4:49 pm

cheers for all your help guys, sadly still not connected despite trying both the above repeatedly. the closest I can get is with the network bridge when i run the

Code: Select all

sudo dhclient -v eth0
it does tell me I'm bound to 192.168.0.1 buuuut still no response from pinging.
When I try to use the ICS (through my WIFI) in windows I get an error message saying it cannot be enabled as a LAN connection is already configured with the IP address that is needed for automatic IP addressing. I don't have the pi connected at the time. (I also suspect this is what is going wrong when connecting over the bridge)
Had a bit of a look but I'm not sure how to proceed-I assume I need to change some settings with my LAN connection but I'm not sure how to proceed effectively.
Any (and all) advice most welcome, cheers.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Internet Connection Sharing?

Tue Jul 17, 2012 5:25 pm

Question: Can you ping (say) 192.168.1.1 (or whatever your upstream hosts's IP is) ?
Usually, failures to ping (say) google.com, are caused by lack of DNS, and the fix is to see if you can ping by IP address.

Can you ping 8.8.8.8 (which seems to work for some reason) ?

Suggestion: Look into the program called "pump". pump has always worked fine for me in setting up IP connections under Linux. I think it is no longer considered kewl by the "in crowd"; I'm not sure why this is.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
Felim_Doyle
Posts: 9
Joined: Mon Oct 15, 2012 3:08 pm
Location: Aylesbury, Buckinghamshire, UK

Re: Internet Connection Sharing?

Mon Oct 22, 2012 1:48 pm

I have a Windows XP Pro PC acting as my Network Bridge with an IP address of 192.168.0.1 and DHCP enabled. I have two other Windows XP laptops connected to the Network Bridge via a 5-port switch and these can access the shared internet connection without any additional configuration.

When I run the dhclient command on my RasPi it fails after five attempts with "No DHCPOFFERS received. No working leases in persistent database - sleeping." and trying to ping 192.168.0.1 on the RasPi results in "connect: Network is unreachable". An ifconfig -a -v command shows no IP address but does show both RX and TX traffic so it has been trying!

A ping of 8.8.8.8 from the RasPi fails but works from the Windows machine although this is not surprising since an nslookup of 8.8.8.8 on the PC reports it as "google-public-dns-a.google.com".

I'll try connecting the RasPi directly to the cable modem and rebooting the cable modem and maybe the RasPi too. At least that should confirm if the physical hardware is working.
Félim
Aylesbury, Buckinghamshire, UK

User avatar
Felim_Doyle
Posts: 9
Joined: Mon Oct 15, 2012 3:08 pm
Location: Aylesbury, Buckinghamshire, UK

Re: Internet Connection Sharing?

Mon Oct 22, 2012 2:32 pm

I can confirm that connecting the RasPi directly to the cable modem and rebooting the cable modem was successful. My ISP allocated it a new IP address and all of the expected internet functionality worked. However, as I need to have the other machines connected too, I do need to get the RasPi working through the Windows based bridge.

So, what crucial step have I missed out?

I'll reboot the Windows machine just in case the DHCP Server isn't behaving itself.
Félim
Aylesbury, Buckinghamshire, UK

User avatar
Felim_Doyle
Posts: 9
Joined: Mon Oct 15, 2012 3:08 pm
Location: Aylesbury, Buckinghamshire, UK

Re: Internet Connection Sharing?

Mon Oct 22, 2012 4:09 pm

Well that was it, the Windows machine did need a reboot for some reason to kick-start DHCP. Once it was back up I ran the dhclient command on the RasPi and it was successfully allocated an IP address of 192.168.0.20.

The other Windows clients would not have noticed there was a problem as they had been allocated IP addresses days ago which were still valid.
Félim
Aylesbury, Buckinghamshire, UK

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Internet Connection Sharing?

Mon Oct 22, 2012 4:32 pm

FWIW, I've noticed that Windows ICS (which I use a lot, so I a) know what I'm talking about and b) am not doing the usual "Well, I never use it, so..." schtick) is a, like most things Windows, finicky at times (generally, during the setup/configuration phase) and takes frequent reboots to keep it working. But when it works, it works, and it is "free".

Just for laughs, you might try re-wiring your network, making the Pi the "gateway" - using iptables and so on. That was one of the thing I always thought of as a good use of the Pi.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Return to “Troubleshooting”