LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-05-2014, 04:19 PM   #1
prompt32
LQ Newbie
 
Registered: Oct 2013
Location: Greece
Posts: 7

Rep: Reputation: Disabled
Question How to share Internet Access through ethernet cable


Hi, my question here is : How to share Internet Access through ethernet cable

I have connect 2 machines trhough en ETH cable by success (ping each other, up/down load files, ssh ).
So, now, i want to share my wirelless internet connection.

Here is my setup :
Code:
                                              // >> INTERNET
                                            //
                                ((*))  << //
     ------                wlan0  |            --------
    |      |                      |            |      |
    | pc-1 |                      +---------->>| pc-2 |
    |      |                                   |      |
     ------                                    --------
       || PCI eth                    onBoard ETH  ||
       || <<<=================================>>> ||
       ||  eth0        eth-X cable          eth0  ||
  -----------                                -----------
  |          |                               |          |
  -----------                                -----------
    eth0                                      eth0
      ip: 10.10.10.11/24                        ip: 10.10.10.10/24
      bc: 10.10.10.255                          bc: 10.10.10.255
                                             wlan0
                                                ip: 192.168.1.64/24
                                                bc: 192.168.1.255
                                                gw: 192.168.1.254
( pc-2 ) - Kernel IP routing table
Code:
  Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  0.0.0.0         192.168.1.254   0.0.0.0         UG    0      0        0 wlan0
  10.10.10.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0
  192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0
Some test pings :
Code:
ping -I wlan0 -c 1 10.10.10.10 : error !
ping -I wlan0 -c 1 google.com : ok.
ping -I eth0 -c 1 192.168.1.254 : error !
ping -I eth0 -c 1 google.com : error !
Can somebody give me some help here ?
PS: i would like to do it, not through the NetworkManager

thanks
 
Old 04-05-2014, 06:07 PM   #2
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware
Posts: 441

Rep: Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574
Hi. You will have to set up IP masquerading with NAT (Network Address Translation) on your local gateway box (i.e. "pc-2"), so that connections coming from "pc-1" and directed to hosts on the Internet will be automatically forwarded from the internal (10.10.10.10) to the external (192.168.1.64) interface. This is possible by defining rules with the "iptables" command, which is part of netfilter, the default firewalling and packet filtering software on GNU/Linux systems. There are also several front-ends for iptables that can help with setting up the rules (one or more front-ends might already be included in your distribution).

Some related documentation:
Documentation about the netfilter/iptables project
IP Masquerade and Network Address Translation
Linux IP Masquerade HOWTO
Linux 2.4 NAT HOWTO

Regards

Last edited by Philip Lacroix; 04-05-2014 at 07:52 PM. Reason: link added
 
Old 04-05-2014, 06:15 PM   #3
Steve R.
Member
 
Registered: Jun 2009
Location: Morehead City, NC
Distribution: Mint 20.3
Posts: 521

Rep: Reputation: 98
Why are you proposing the configuration shown? Why not use a router? We have a variety of devices that can simultaneously connect to the internet through a router (24/7). One limitation of your configuration is that pc-2 would have to be on in-order for pc-1 to have Internet access. This reminds that Microsoft Windows Version ??? (circa 1990 something) which used to have the option of designating one computer as a "gateway" so that other computers on the home LAN could access the internet. Anyway, beyond the advice of using a router, I do not have the technical knowledge you are requesting.
 
Old 04-05-2014, 07:12 PM   #4
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware
Posts: 441

Rep: Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574
Quote:
Originally Posted by Steve R. View Post
Why not use a router?
Apart from giving a LAN the access to another network (e.g. the Internet), a gateway box is useful whenever you want to have some additional (and controlled) filtering protection for your internal machines. B.t.w. the concept of gateway was not invented by wind0w$, but many years before, when networking was. While the configuration proposed by the OP shows only one box as part of the internal LAN, he might as well use a switch to allow more machines to connect through the gateway. Of course this makes more sense if a firewall is also configured and enabled on the gateway itself, while plugging the machine/switch directly into the (ISP) router would remove that additional and controlled filtering "layer".

Last edited by Philip Lacroix; 04-05-2014 at 07:55 PM.
 
Old 04-05-2014, 08:13 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,001

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
It was a great drawing for a first time question too.

Pretty sure Philip Lacroix has the solution that you asked for.

Since you say manager, see alt solutions here maybe. https://help.ubuntu.com/community/In...nectionSharing
 
Old 04-05-2014, 08:50 PM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
this is what i do:
http://www.linuxquestions.org/questi...6/#post3804866
 
Old 04-10-2014, 10:35 AM   #7
prompt32
LQ Newbie
 
Registered: Oct 2013
Location: Greece
Posts: 7

Original Poster
Rep: Reputation: Disabled
1st of all, iwant to thanks all that reply.
I use Linux in both machine (Debian,kernel 3.12.6)

i still read the documentation that 'Philip Lacroix' points to, its more than full ...
because some already examples, found on net dont work in my case (or maybe i do something wrong ...)

Like, in 'schneidz's example ,
if i set the gateway of an iface, at an address on a different network, the (route, ip route,..),
dont accept this by error : "interface unreachable"

ie:
Code:
route add  -net 10.10.10.0 netmask 255.255.255.0 gw 192.168.1.254 dev eth0
SIOCADDRT: Network is unreachable
and for what i have notice so far,
i think that to enable ip4-forwarding by the echo command,
before or after the route/iptable commands, have a meaning in the way, the above commands acts...,
Is this true, or not ?


I read the posts, but i will post again when i will have something to say, or when solved,
dont think my silince as ignorance.
Thank's

Last edited by prompt32; 04-10-2014 at 10:40 AM.
 
Old 11-16-2014, 06:33 PM   #8
prompt32
LQ Newbie
 
Registered: Oct 2013
Location: Greece
Posts: 7

Original Poster
Rep: Reputation: Disabled
How to share Internet Access through ethernet cable. DONE.

Quote:
route add -net 10.10.10.0 netmask 255.255.255.0 gw 192.168.1.254 dev eth0
The above and similar code dont work for me on 'pc-2' machine, (maybe because 2 interfaces exists ...)

but
Code:
route add default gw 192.168.1.254
works fine, (of course this happens, after NetworkManager associated the wlan0 interface), so:

according to the settings in my 1st post;

1) set the deafult gateway on the pc-1, points to the 'eth0' interface of the 'pc-2'
2) run a small script of iptables rules, for 'pc-2'

1)
Code:
route add default gw 10.10.10.10
2) let's say eth0-iptables.sh
Code:
#!/bin/bash

[ -n "$IFACE" -a "$IFACE" != "eth0" ] && exit 0


echo_iptables (){
	  iptables -nvL --line-numbers 
	  return 0
	  }

[ "$1" = "show" ] && \
	echo_iptables && \
	exit 0


echo "[i] `basename $0`, Clear IPtables ..."

	iptables -F
	iptables -X
	iptables -t nat -F
	iptables -t nat -X
	iptables -t mangle -F
	iptables -t mangle -X
	iptables -P INPUT ACCEPT
	iptables -P OUTPUT ACCEPT
	iptables -P FORWARD ACCEPT


[ "$1" = "stop" -o "$MODE" = "stop" ] && \
	echo "[*] `basename $0`, Nothing to do, exit." && \
	echo_iptables && \
	exit 0

	iptables -F INPUT
	iptables -A INPUT -j ACCEPT

	iptables -F FORWARD
	iptables -A FORWARD -j ACCEPT

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



echo "[i] `basename $0`, IPtables are now set to :" && echo_iptables


sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1
exit 0
Code:
You can add this code to '/etc/rc.local'
BUT, I PREFFER TO, ..., make two links of this script,
  1) /etc/network/if-up.d/ - Scripts to execute when an/all interface(s) goes UP
  2) /etc/network/if-post-down.d/ - Scripts to execute when an/all interface(s) goes DOWN  

 When system calls this scripts, it sets the following vars
     IFACE - the name of the interface or all 
      MODE - 'stop' when an ie : ifdown <iface> command happens
           - 'start' when an inerface goes up
   ADDRFAM - 'inet'
I know its been a long time, but it was such a long time ....

... really thanks, everyone, here !
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to share internet through ethernet cable? ThemePark Linux - Networking 9 09-18-2013 07:10 PM
How to share internet connection through a crossover cable. Inkit Linux - General 6 03-07-2011 07:08 PM
how to share internet with a cable modem? zovres Linux - Networking 1 03-23-2004 07:44 AM
laptop can access samba server via ethernet cable but not wireless? cmisip Linux - Wireless Networking 4 05-24-2003 01:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration