Author Topic: Internet Sharing  (Read 1418 times)

Offline kjpetrie

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 4001
Re: Internet Sharing
« Reply #15 on: January 24, 2013, 04:04:10 PM »
You need to write your iptables and similar commands into a script to be executed on every boot. Here is mine:
Code: [Select]
#!/bin/sh

# local Shell script to NAT Internet connections to

# chkconfig: 35 28 62
# description: Shares internet connection from ethernet via wifi

### BEGIN INIT INFO
# Provides:          ipsharing
# Required-Start:    $network $shorewall
# Required-Stop:     $network $shorewall
# Default-Start:     3 5
# Default-Stop:      0 1 2 4 6
# Short-Description: Start Internet sharing
# Description:       Shares internet connection from ethernet via wifi
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# Lock files
SYSCONF_FILE=/var/lock/subsys/shared

# Other Services
ROUTING_DELAY=20

start_forwarding () {
  # Now set up NAT
  echo 1 > /proc/sys/net/ipv4/ip_forward
  iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  /sbin/iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  /sbin/iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
}

stop_forwarding () {
  iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
  /sbin/iptables -D FORWARD -i wlan0 -o eth0 -j ACCEPT
  /sbin/iptables -D FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  echo 0 > /proc/sys/net/ipv4/ip_forward
}

start () {
if [ -f $SYSCONF_FILE ]; then
gprintf "Already shared\n"
exit 1
fi
# Work round broken start order
sleep $ROUTING_DELAY
start_forwarding
touch $SYSCONF_FILE
}

stop () {
if [ -f $SYSCONF_FILE ]; then
stop_forwarding
rm -f $SYSCONF_FILE
else
gprintf "Not shared\n"
fi
}

case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
quickrestart)
ROUTING_DELAY=1
stop
start
;;
status)
if [ -f $SYSCONF_FILE ]; then
echo 'shared'
exit 0
else
echo 'Not shared'
exit 1
fi
;;
*)
echo "Usage: $0 [start|stop|restart|quickrestart|status]"
exit -1
esac

exit 0

You'll need to adapt the code in the start_forwarding and stop_forwarding functions, but otherwise it should be the right structure for an init script. Save as /etc/init.d/rc.d/netshare (or whatever name you want) and set it executable (chmod 755). Then open PCC, go to System -> Control services by starting or stopping them and select netshare (or whatever you called it) to start at boot.
« Last Edit: January 24, 2013, 04:05:55 PM by kjpetrie »
-----------
KJP
-----------------------------------------------------------
PClos64 RC1 on Intel D945GCLF2 motherboard (Atom 330), 2GB DDR2 RAM, Maxtor STM325031, HL-DT-ST DVDRAM GSA-H42N, Amilo LSL 3220T monitor. Also Acer 5810TG (with custom kernel) and Asus eeePC 2G surf

Offline pclinmike

  • Hero Member
  • *****
  • Posts: 637
  • I Only 'Clean' Windows !.
Re: Internet Sharing
« Reply #16 on: January 25, 2013, 10:02:01 AM »
You need to write your iptables and similar commands into a script to be executed on every boot.

You'll need to adapt the code in the start_forwarding and stop_forwarding functions, but otherwise it should be the right structure for an init script. Save as /etc/init.d/rc.d/netshare (or whatever name you want) and set it executable (chmod 755). Then open PCC, go to System -> Control services by starting or stopping them and select netshare (or whatever you called it) to start at boot.


Thank you that did the trick, ;D  I copied your script (un-modifiered !) and followed your description, just called it 'iPhone-net-share' .
Tried a few re-boots and shut downs all seems to be working on the shared machine  ;D

@Andrzej Thankyou for your advice, you have Not read the rest of my posts above ! as you would have noted I did try 'Hostapd' see post #1 & #8 above.
Michael.
From South-Derbyshire, England.U.K.Earth.

I Normally Do A Search Before I Post A New Question !.

Thanks to all who replied to my posts.

Offline pclinmike

  • Hero Member
  • *****
  • Posts: 637
  • I Only 'Clean' Windows !.
Re: Internet Sharing
« Reply #17 on: January 25, 2013, 07:53:04 PM »
I have been tying to set up a security key of WPA-PSK on the wireless card but with NO luck.

With Ad-Hoc mode set it will only let you set WEP-Open (which is hackable !).

I have been trying to use setting in PCC, also 'iwconfig'   Do I need to use ' WPA_Supplicant'  and 'wpa_supplicant  GUI'  (WPA_GUI) if so how do I do it ?.

I installed the WPA_GUI ran it from root terminal, but that did not seem to work !.

I also changed the config file in /etc/wpa_supplicant .
---------------------------------------------------------------------------------------------------------------------------------

# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1F:16:A9:AA:4B 
          inet addr:192.168.0.164  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:64 errors:0 dropped:0 overruns:0 frame:0
          TX packets:94 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7378 (7.2 KiB)  TX bytes:10529 (10.2 KiB)
          Interrupt:16

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

wlan0     Link encap:Ethernet  HWaddr 00:24:2C:A2:73:7B 
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:36 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:6863 (6.7 KiB)

# iwconfig wlan0

wlan0     IEEE 802.11bgn  ESSID:"Acer-Share" 
          Mode:Ad-Hoc  Frequency:2.412 GHz  Cell: 2A:D4:63:58:DF:E8   
          Tx-Power=16 dBm   
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on
         


# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         smoothwall-firewall 0.0.0.0         UG    5      0        0 eth0
loopback        *               255.0.0.0       U     0      0        0 lo
link-local      *               255.255.0.0     U     5      0        0 eth0
link-local      *               255.255.0.0     U     35     0        0 wlan0
192.168.0.0     *               255.255.255.0   U     5      0        0 eth0
192.168.1.0     *               255.255.255.0 
Michael.
From South-Derbyshire, England.U.K.Earth.

I Normally Do A Search Before I Post A New Question !.

Thanks to all who replied to my posts.

Offline Yankee

  • Hero Member
  • *****
  • Posts: 1490
  • In theory, theory=practice, in practice ???
Re: Internet Sharing
« Reply #18 on: January 25, 2013, 08:12:04 PM »
The internet gateway has to be configured WPA
as well as the wireless card.   You probably already
did that.    If WEP works I'd try that.
ASUS EeePc 900HA netbook  1.6 Ghz Atom CPU  1GB RAM
160 GB internal HD    Seagate 250 GB USB portable drive 
Intel ‎Mobile 945GSE Integrated Graphics Controller
Atheros AR242x/AR542x Wireless Network Adapter
Intel (N10/ICH7 Family) High Definition Audio
Dynex 5-Button Wired Optical Mouse
LXDE

Offline pclinmike

  • Hero Member
  • *****
  • Posts: 637
  • I Only 'Clean' Windows !.
Re: Internet Sharing
« Reply #19 on: January 26, 2013, 02:41:11 PM »
The internet gateway has to be configured WPA
as well as the wireless card.   You probably already
did that.    If WEP works I'd try that.
WEP works but is not safe as it can be cracked in 10-15 mins.
Michael.
From South-Derbyshire, England.U.K.Earth.

I Normally Do A Search Before I Post A New Question !.

Thanks to all who replied to my posts.

Offline pclinmike

  • Hero Member
  • *****
  • Posts: 637
  • I Only 'Clean' Windows !.
Re: Internet Sharing
« Reply #20 on: January 26, 2013, 02:52:00 PM »
Still looking for a way to set up WPA at least security on the wireless card, when it in Ad-Hoc mode there seems to be problems setting anything other 'open' or 'wep' .
I found 'wicd' (pronounced "wicked"), in synaptic, the write up says it can set up wpa and other security settings, I have installed it but I have to disable all other network managers.
I have KDE D.E. on this laptop.
I have tried renaming /etc/netprofile and /etc/networkmanager so they do not work but there seems to be something else setting up the wireless card.

Have I disabled them in the correct place ?.

What else do I need to disable and how ?.
Michael.
From South-Derbyshire, England.U.K.Earth.

I Normally Do A Search Before I Post A New Question !.

Thanks to all who replied to my posts.

Offline Yankee

  • Hero Member
  • *****
  • Posts: 1490
  • In theory, theory=practice, in practice ???
Re: Internet Sharing
« Reply #21 on: January 27, 2013, 12:13:26 PM »
WEP works but is not safe as it can be cracked in 10-15 mins.


Slightly off-topic, hope you don't mind.    WPA cracks also but
takes hours.    Our PCL msec should issue an alert if this is seen.
Can't believe the modem-router or network program, perhaps
Wicd or Network Manager doesn't keep a log of these packets
that fail to enter properly.

http://lifehacker.com/5873407/how-to-crack-a-wi+fi-networks-wpa-password-with-reaver


Just FYI
ASUS EeePc 900HA netbook  1.6 Ghz Atom CPU  1GB RAM
160 GB internal HD    Seagate 250 GB USB portable drive 
Intel ‎Mobile 945GSE Integrated Graphics Controller
Atheros AR242x/AR542x Wireless Network Adapter
Intel (N10/ICH7 Family) High Definition Audio
Dynex 5-Button Wired Optical Mouse
LXDE

Offline pclinmike

  • Hero Member
  • *****
  • Posts: 637
  • I Only 'Clean' Windows !.
Re: Internet Sharing
« Reply #22 on: February 26, 2013, 06:08:34 AM »
My daughter came over for the weekend and I set up her new laptop as above, when we went back to her uni halls the Ad-Hoc network connected to her phone ok but we could not get on the internet.  :'(
Looking for Network settings on her iphone we could not set the setting for 'Tethering' only to find out that we would have to pay extra for that service  :'(  :(
Good old Apple, I told her not to get an iphone  :)
Michael.
From South-Derbyshire, England.U.K.Earth.

I Normally Do A Search Before I Post A New Question !.

Thanks to all who replied to my posts.

Offline kjpetrie

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 4001
Re: Internet Sharing
« Reply #23 on: February 26, 2013, 06:41:23 AM »
What are you trying to do again? I thought you wanted to connect the iphone to the Internet by wifi. Are you saying Apple won't allow its wifi interface to be used unless you pay extra, or are you trying to use the iphone as the gateway?

If you want to do what I thought you want, you shouldn't need tethering, and whoever advised you has misunderstood your need.
« Last Edit: February 26, 2013, 06:47:19 AM by kjpetrie »
-----------
KJP
-----------------------------------------------------------
PClos64 RC1 on Intel D945GCLF2 motherboard (Atom 330), 2GB DDR2 RAM, Maxtor STM325031, HL-DT-ST DVDRAM GSA-H42N, Amilo LSL 3220T monitor. Also Acer 5810TG (with custom kernel) and Asus eeePC 2G surf

Offline pclinmike

  • Hero Member
  • *****
  • Posts: 637
  • I Only 'Clean' Windows !.
Re: Internet Sharing
« Reply #24 on: February 26, 2013, 07:30:13 AM »
I know the system works as I shared the internet from her new laptop to her old laptop (which I have now) as a test before we went back to her uni.

I have just been looking on Apple support forums and there are loads of people having the same issue with connecting to a Ad-Hoc network but have no problem connecting to a router or access point.

I'm looking at getting wifi access point and setting it up in her room next time we go to see her at the uni.

Edit ...'Tethering' Yes your are correct that is not the word I wanted.

Definition:

iPhone Tethering is a technique in which an iPhone is used as a wireless modem to provide Internet access to a computer or other Wi-Fi-enabled device, like an iPad or iPod touch.
« Last Edit: February 26, 2013, 07:38:38 AM by pclinmike »
Michael.
From South-Derbyshire, England.U.K.Earth.

I Normally Do A Search Before I Post A New Question !.

Thanks to all who replied to my posts.

Offline pclinmike

  • Hero Member
  • *****
  • Posts: 637
  • I Only 'Clean' Windows !.
Re: Internet Sharing
« Reply #25 on: February 28, 2013, 04:08:12 PM »
Michael.
From South-Derbyshire, England.U.K.Earth.

I Normally Do A Search Before I Post A New Question !.

Thanks to all who replied to my posts.

Offline neelakantanr

  • New Friend
  • *
  • Posts: 7
Re: Internet Sharing
« Reply #26 on: April 15, 2013, 03:14:43 AM »
i am sure you solved the problem;

i normally use windows and there i use connectify which is a gui based program which can run on xp.win7 or win8; once you install it, you can share your ethernet (Wired) internet over wifi to other laptop, android or iphone or itabs. very simple and elegant program

coming to pclinux, i tried various options, (first we have to understand, modern user wants a gui based program and clear simple instructions and not command-line -instructions and saving of files for next boot!)

seeing the option of sharing the internet, i thought the option shall be simple but no so in pclinux

regards
neelakantan

Offline kjpetrie

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 4001
Re: Internet Sharing
« Reply #27 on: April 15, 2013, 03:33:30 AM »
If you think that, learn to write one. That's how FOSS advances.
-----------
KJP
-----------------------------------------------------------
PClos64 RC1 on Intel D945GCLF2 motherboard (Atom 330), 2GB DDR2 RAM, Maxtor STM325031, HL-DT-ST DVDRAM GSA-H42N, Amilo LSL 3220T monitor. Also Acer 5810TG (with custom kernel) and Asus eeePC 2G surf