Difference between revisions of "Sharing PPP Connection"

From ArchWiki
Jump to: navigation, search
m (moved Sharing ppp connection with eth interface to Sharing PPP Connection: more concise; merging another article onto this one)
(Merging another article about sharing PPP with this article)
Line 67: Line 67:
  
 
= Sharing via WLAN =
 
= Sharing via WLAN =
 +
 +
== Requirements ==
 +
 +
The following programs must have been installed in order to share the ppp connection:
 +
# Programs for configuring your wlan card (package '''wireless_tools''')
 +
# Programs for configuring generic network interface card (package '''net-tools''')
 +
# The '''iptables''' program which is used to manipulate how data is passed through your machine from your clients and back (package '''iptables''')
 +
# '''dnsmasq''' software for acting as a DHCP and DNS caching server (package '''dnsmasq''')
 +
 +
The following conditions must also have been met:
 +
# You must have a working ppp connection (I'm using [[Bluetooth_GPRS_Howto|bluetooth+gprs]] to connect to the Internet)
 +
# You must have a working wlan interface card (in terms of "can be used in Linux")
 +
 +
== Instructions ==
 +
 +
<ol>
 +
<li>Set the ppp connection up.</li>
 +
<li>Set the wlan connection up. Choose ssid and select ad-hoc as network type. In the following I'm assuming that you are using interface named '''''wlan0'''''. Set the wlan interface up address for example 192.168.0.254 . Setting up the interface is usually done by running the '''iwconfig''' program as root, with syntax like: <pre>iwconfig wlan0 essid "My_Free_Wlan" mode Ad-Hoc</pre> After that you can assign an ip address to the interface as usual, by running (again, as root): <pre>ifconfig wlan0 192.168.0.254</pre> Please note that different wlan cards may be configured differently and one should adapt this documentation accordingly.
 +
<li>Set the kernel to router mode. This is done by running as root: <pre>echo 1 > /proc/sys/net/ipv4/ip_forward</pre></li>
 +
<li>Configure '''dnsmasq'''. Make the following changes to /etc/dnsmasq.conf (uncomment if necessary): <pre>
 +
domain-needed
 +
bogus-priv
 +
interface=wlan0 (or whatever interface your wlan is)
 +
dhcp-range=192.168.0.1,192.168.0.100,12h
 +
</pre></li>
 +
<li>Start dnsmasq as root: <pre>/etc/rc.d/dnsmasq start</pre></li>
 +
<li>Finally, set firewall to forward connections to and from the Internet for clients connecting to your wlan. This is done by issuing (you guessed it right, as root again): <pre>iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE</pre> In the above the '''''ppp0''''' interface is the used ppp interface, you can substitute it for yours if needed.</li>
 +
<li>You are done! Happy surfing</li>
 +
</ol>
 +
 +
{{Warning|The previous configuration has no security options enabled!<br>If you are using firewall, you should adapt this documentation to suit your needs.<br>Same applies also to setting up keys for wlan interface.}}
 +
 +
== Sharing script ==
 +
 +
As requested at ArchCon 2010, a quick script for sharing eth0 over wlan0 on an ad-hoc network.
 +
 +
<pre>
 +
#!/bin/bash
 +
 +
iwconfig wlan0 mode ad-hoc
 +
iwconfig wlan0 essid proxywlan
 +
ifconfig wlan0 192.168.11.1 up
 +
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
 +
echo 1 > /proc/sys/net/ipv4/ip_forward
 +
</pre>
 +
 +
== See Also ==
 +
 +
*[[Internet Share]]
 +
*[[Simple stateful firewall HOWTO]]
 +
*[[NAT'ing firewall - Share your broadband connection]]
 +
*[[Wireless Setup]]
 +
*[[USB 3G Modem]]

Revision as of 12:02, 10 April 2011


Sharing via wired ethernet

Requirements

The following programs must have been installed in order to share the ppp connection:

  1. Programs for configuring generic network interface card (package net-tools)
  2. The iptables program which is used to manipulate how data is passed through your machine from your clients and back (package iptables)
  3. dnsmasq software for acting as a DHCP and DNS caching server (package dnsmasq)
  4. If you want to share the ppp connection with more computers you need to setup a network bridge. (package bridge-utils)


The following conditions must also have been met:

  1. You must have a working ppp connection
  2. You must have a working an extra eth interface card (in terms of "can be used in Linux")

Instructions

  1. Set the ppp connection up.
  2. you can assign an ip address to the interface as usual, by running (again, as root):
    ifconfig eth1 192.168.0.254
  3. Set the kernel to router mode. This is done by running as root:
    echo 1 > /proc/sys/net/ipv4/ip_forward
  4. Configure dnsmasqd. Make the following changes to /etc/dnsmasq.conf (uncomment if necessary):
    domain-needed
    bogus-priv
    interface=eth1 (or whatever interface your wlan is)
    dhcp-range=192.168.0.1,192.168.0.100,12h
    
  5. Start the dnsmasqd, as root:
    /etc/rc.d/dnsmasq start
  6. Finally, set firewall to forward connections to and from the Internet for clients connecting to your wlan. This is done by issuing (you guessed it right, as root again):
    iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
    In the above the ppp0 interface is the used ppp interface, you can substitute it for yours if needed.
  7. You are done! Happy surfing
Warning: The previous configuration has no security options enabled!
If you are using firewall, you should adapt this documentation to suit your needs.
Same applies also to setting up keys for wlan interface.

Network Bridge

Let's assume your ppp connection is on eth0, and you want to share the connection on eth1 and eth2.

ifconfig eth1 0.0.0.0 #remove IP from eth0
ifconfig eth1 up #ensure the interface is up
ifconfig eth2 0.0.0.0 #remove IP from eth1
ifconfig eth2 up #ensure the interface is up
brctl addbr br0 #create br0 node
brctl addif br0 eth1 #add eth0 to bridge br0
brctl addif br0 eth2 #add eth1 to bridge br0
ifconfig br0 192.168.0.254

change your interface in dnsmasq.conf to br0

interface=br0 

then start dnsmasq

/etc/rc.d/dnsmasq start

now you can connect to the internet using eth1 or eth2.

See Also

Sharing via WLAN

Requirements

The following programs must have been installed in order to share the ppp connection:

  1. Programs for configuring your wlan card (package wireless_tools)
  2. Programs for configuring generic network interface card (package net-tools)
  3. The iptables program which is used to manipulate how data is passed through your machine from your clients and back (package iptables)
  4. dnsmasq software for acting as a DHCP and DNS caching server (package dnsmasq)

The following conditions must also have been met:

  1. You must have a working ppp connection (I'm using bluetooth+gprs to connect to the Internet)
  2. You must have a working wlan interface card (in terms of "can be used in Linux")

Instructions

  1. Set the ppp connection up.
  2. Set the wlan connection up. Choose ssid and select ad-hoc as network type. In the following I'm assuming that you are using interface named wlan0. Set the wlan interface up address for example 192.168.0.254 . Setting up the interface is usually done by running the iwconfig program as root, with syntax like:
    iwconfig wlan0 essid "My_Free_Wlan" mode Ad-Hoc
    After that you can assign an ip address to the interface as usual, by running (again, as root):
    ifconfig wlan0 192.168.0.254
    Please note that different wlan cards may be configured differently and one should adapt this documentation accordingly.
  3. Set the kernel to router mode. This is done by running as root:
    echo 1 > /proc/sys/net/ipv4/ip_forward
  4. Configure dnsmasq. Make the following changes to /etc/dnsmasq.conf (uncomment if necessary):
    domain-needed
    bogus-priv
    interface=wlan0 (or whatever interface your wlan is)
    dhcp-range=192.168.0.1,192.168.0.100,12h
    
  5. Start dnsmasq as root:
    /etc/rc.d/dnsmasq start
  6. Finally, set firewall to forward connections to and from the Internet for clients connecting to your wlan. This is done by issuing (you guessed it right, as root again):
    iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
    In the above the ppp0 interface is the used ppp interface, you can substitute it for yours if needed.
  7. You are done! Happy surfing
Warning: The previous configuration has no security options enabled!
If you are using firewall, you should adapt this documentation to suit your needs.
Same applies also to setting up keys for wlan interface.

Sharing script

As requested at ArchCon 2010, a quick script for sharing eth0 over wlan0 on an ad-hoc network.

#!/bin/bash

iwconfig wlan0 mode ad-hoc
iwconfig wlan0 essid proxywlan
ifconfig wlan0 192.168.11.1 up
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

See Also