Difference between revisions of "Sharing PPP Connection"

From ArchWiki
Jump to: navigation, search
(cleaned up the article a litte. modified, but not tested: ifconfig -> ip is pretty safe. there's still iwconfig -> iw, but i don't use PPP so not gonna break that just yet)
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Networking]]
 
[[Category:Networking]]
{{i18n|Sharing PPP Connection}}
 
  
== Sharing via wired ethernet ==
+
== Requirements ==
=== Requirements ===
+
Before proceeding, you must make sure:
The following programs must have been installed in order to share the ppp connection:
+
# You must have a working PPP connection.
# Programs for configuring generic network interface card (package '''net-tools''')
+
# You must have an extra Ethernet interface card in your computer with which to share your connection.
# 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''')
+
# 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:
+
== Installing ==
# You must have a working ppp connection
+
The following packages must be [[Pacman|installed]] from the [[official repositories]] for both Wired and Wireless sharing:
# You must have a working an extra eth interface card (in terms of "can be used in Linux")
+
* {{Pkg|iptables}}: for controlling packets in your network.
 +
* {{Pkg|dnsmasq}}: for acting as a DHCP and DNS caching server.
 +
* {{Pkg|bridge-utils}}: for setting up a network bridge.
  
=== Instructions ===
+
Depending on whether you want to share a wireless or wired connection, you also have to install:
<ol>
+
* '''wired''': {{Pkg|iproute2}} or {{Pkg|net-tools}} (this article uses {{ic|iproute2}} since {{ic|net-tools}} is no longer maintained).
<li>Set the ppp connection up.</li>
+
* '''wireless''': {{Pkg|wireless_tools}}.
you can assign an ip address to the interface as usual, by running (again, as root): <pre>ifconfig eth1 192.168.0.254</pre>
+
 
<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>
+
== Sharing via Wired Ethernet ==
<li>Configure '''dnsmasqd'''. Make the following changes to /etc/dnsmasq.conf (uncomment if necessary): <pre>
+
 
 +
* Set the PPP connection up.
 +
: You can assign an IP address to the interface as usual, by running (as root):
 +
# ip addr add 192.168.0.254 dev eth0
 +
* Set the kernel to router mode. This is done by running:
 +
# echo 1 > /proc/sys/net/ipv4/ip_forward
 +
* Configure {{ic|dnsmasqd}}. Make the following changes to {{ic|/etc/dnsmasq.conf}} (uncomment if necessary):
 +
{{hc|/etc/dnsmasq.conf|<nowiki>
 
domain-needed
 
domain-needed
 
bogus-priv
 
bogus-priv
interface=eth1 (or whatever interface your wlan is)
+
interface=eth0 # change to your chosen interface
dhcp-range=192.168.0.1,192.168.0.100,12h
+
dhcp-range=192.168.0.1,192.168.0.100,12h</nowiki>
</pre></li>
+
}}
<li>Start the dnsmasqd, as root: <pre>/etc/rc.d/dnsmasq start</pre></li>
+
* [[Daemons#Managing_daemons|Start]] the '''dnsmasq''' daemon.
<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>
+
* Finally, set firewall to forward connections to and from the Internet for clients connecting to your WLAN. This is done by issuing:
<li>You are done! Happy surfing</li>
+
# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
</ol>
+
:In the above the '''ppp0''' interface is the used PPP interface, you can substitute it for yours if needed.
 +
* You are done! Happy surfing!
  
{{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.}}
+
{{Warning|The previous configuration has no security options enabled. If you are using a firewall, you should adapt this documentation to suit your needs. Same applies also to setting up keys for WLAN interface.}}
  
 
=== Network Bridge ===
 
=== Network Bridge ===
Let's assume your ppp connection is on eth0, and you want to share the connection on eth1 and eth2.
+
Let's assume your PPP connection is on {{ic|eth0}}, and you want to share the connection on {{ic|eth1}} and {{ic|eth2}}.
  
  ifconfig eth1 0.0.0.0 #remove IP from eth0
+
  # ip addr add 0.0.0.0 dev eth1  # remove IP from eth0
  ifconfig eth1 up #ensure the interface is up
+
  # ip link set eth1 up           # ensure the interface is up
  
  ifconfig eth2 0.0.0.0 #remove IP from eth1
+
  # ip addr add 0.0.0.0 dev eth2  # remove IP from eth1
  ifconfig eth2 up #ensure the interface is up
+
  # ip link set eth2 up           # ensure the interface is up
  
  brctl addbr br0 #create br0 node
+
  # brctl addbr br0               # create br0 node
  brctl addif br0 eth1 #add eth0 to bridge br0
+
  # brctl addif br0 eth1         # add eth0 to bridge br0
  brctl addif br0 eth2 #add eth1 to bridge br0
+
  # brctl addif br0 eth2         # add eth1 to bridge br0
  
  ifconfig br0 192.168.0.254
+
  # ip addr add 192.168.0.254 dev br0
change your interface in dnsmasq.conf to br0
+
change your interface in {{ic|dnsmasq.conf}} to {{ic|br0}}:
 
  interface=br0  
 
  interface=br0  
 +
and [[Daemons#Managing_daemons|restart]] the '''dnsmasq''' daemon.
  
then start dnsmasq
+
Now you should be able to connect to the internet using {{ic|eth1}} or {{ic|eth2}}.
/etc/rc.d/dnsmasq start
+
  
now you can connect to the internet using eth1 or eth2.
+
== Sharing via WLAN ==
  
=== See Also ===
+
=== Instructions ===
*[[Internet Share]]
+
*[[Simple stateful firewall HOWTO]]
+
*[[NAT'ing firewall - Share your broadband connection]]
+
*[[Wireless Setup]]
+
*[[USB 3G Modem]]
+
  
== Sharing via WLAN ==
+
* Set up the PPP connection.
=== Requirements ===
+
* Set up the WLAN connection: choose an SSID and select Ad-hoc as network type. In the following it is assumed that you are using the {{ic|wlan0}} interface.
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:
+
: Set the {{ic|wlan0}} interface up address for example 192.168.0.254. Setting up the interface is usually done by running:
# You must have a working ppp connection (I'm using [[Bluetooth_GPRS_Howto|bluetooth+gprs]] to connect to the Internet)
+
# iwconfig wlan0 essid "MyFreeWlan" mode ad-hoc
# You must have a working wlan interface card (in terms of "can be used in Linux")
+
  
=== Instructions ===
+
: After that you can assign an IP address to the interface as usual, by running:  
<ol>
+
# ip addr add 192.168.0.254 dev wlan0
<li>Set the ppp connection up.</li>
+
: Please note that different wlan cards may be configured differently and one should adapt this documentation accordingly.
<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.
+
* Set the kernel to router mode. This is done by running:
<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>
+
# echo 1 > /proc/sys/net/ipv4/ip_forward
<li>Configure '''dnsmasq'''. Make the following changes to /etc/dnsmasq.conf (uncomment if necessary): <pre>
+
* Configure '''dnsmasq'''. Make the following changes to {{ic|/etc/dnsmasq.conf}} (uncomment if necessary):
 +
{{hc|etc/dnsmasq.conf|<nowiki>
 
domain-needed
 
domain-needed
 
bogus-priv
 
bogus-priv
interface=wlan0 (or whatever interface your wlan is)
+
interface=wlan0   # change to your interface
dhcp-range=192.168.0.1,192.168.0.100,12h
+
dhcp-range=192.168.0.1,192.168.0.100,12h</nowiki>
</pre></li>
+
}}
<li>Start dnsmasq as root: <pre>/etc/rc.d/dnsmasq start</pre></li>
+
* [[Daemons#Managing_daemons|Start]] the '''dnsmasq''' daemon.
<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>
+
* Finally, set firewall to forward connections to and from the Internet for clients connecting to your WLAN. This is done by issuing:  
<li>You are done! Happy surfing</li>
+
# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
</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.}}
+
: In the above the '''ppp0''' interface is assumed to be the used PPP interface, you can substitute it for yours if needed.
 +
* You are done! Happy surfing!
  
=== Sharing script ===
+
{{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.}}
As requested at ArchCon 2010, a quick script for sharing eth0 over wlan0 on an ad-hoc network.
+
  
<pre>
+
== Sharing Script ==
 +
A quick script for sharing {{ic|eth0}} over {{ic|wlan0}} on an ad-hoc network.
 +
{{hc|ethoverwlan.sh|
 
#!/bin/bash
 
#!/bin/bash
  
 
iwconfig wlan0 mode ad-hoc
 
iwconfig wlan0 mode ad-hoc
 
iwconfig wlan0 essid proxywlan
 
iwconfig wlan0 essid proxywlan
ifconfig wlan0 192.168.11.1 up
+
ip addr add 192.168.0.254 dev wlan0
 +
ip link set wlan0 up
 
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
 
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
 
echo 1 > /proc/sys/net/ipv4/ip_forward
 
echo 1 > /proc/sys/net/ipv4/ip_forward
</pre>
+
}}
  
=== See Also ===
+
== See Also ==
*[[Internet Share]]
+
* [[Internet Share]]
*[[Simple stateful firewall HOWTO]]
+
* [[Simple stateful firewall HOWTO]]
*[[NAT'ing firewall - Share your broadband connection]]
+
* [[NAT'ing firewall - Share your broadband connection]]
*[[Wireless Setup]]
+
* [[Wireless Setup]]
*[[USB 3G Modem]]
+
* [[USB 3G Modem]]

Revision as of 21:27, 7 March 2013


Requirements

Before proceeding, you must make sure:

  1. You must have a working PPP connection.
  2. You must have an extra Ethernet interface card in your computer with which to share your connection.

Installing

The following packages must be installed from the official repositories for both Wired and Wireless sharing:

  • iptables: for controlling packets in your network.
  • dnsmasq: for acting as a DHCP and DNS caching server.
  • bridge-utils: for setting up a network bridge.

Depending on whether you want to share a wireless or wired connection, you also have to install:

Sharing via Wired Ethernet

  • Set the PPP connection up.
You can assign an IP address to the interface as usual, by running (as root):
# ip addr add 192.168.0.254 dev eth0
  • Set the kernel to router mode. This is done by running:
# echo 1 > /proc/sys/net/ipv4/ip_forward
  • Configure dnsmasqd. Make the following changes to /etc/dnsmasq.conf (uncomment if necessary):
/etc/dnsmasq.conf
domain-needed
bogus-priv
interface=eth0 # change to your chosen interface
dhcp-range=192.168.0.1,192.168.0.100,12h
  • Start the dnsmasq daemon.
  • Finally, set firewall to forward connections to and from the Internet for clients connecting to your WLAN. This is done by issuing:
# 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.
  • You are done! Happy surfing!
Warning: The previous configuration has no security options enabled. If you are using a 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.

# ip addr add 0.0.0.0 dev eth1  # remove IP from eth0
# ip link set eth1 up           # ensure the interface is up
# ip addr add 0.0.0.0 dev eth2  # remove IP from eth1
# ip link set 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
# ip addr add 192.168.0.254 dev br0

change your interface in dnsmasq.conf to br0:

interface=br0 

and restart the dnsmasq daemon.

Now you should be able to connect to the internet using eth1 or eth2.

Sharing via WLAN

Instructions

  • Set up the PPP connection.
  • Set up the WLAN connection: choose an SSID and select Ad-hoc as network type. In the following it is assumed that you are using the wlan0 interface.
Set the wlan0 interface up address for example 192.168.0.254. Setting up the interface is usually done by running:
# iwconfig wlan0 essid "MyFreeWlan" mode ad-hoc
After that you can assign an IP address to the interface as usual, by running:
# ip addr add 192.168.0.254 dev wlan0
Please note that different wlan cards may be configured differently and one should adapt this documentation accordingly.
  • Set the kernel to router mode. This is done by running:
# echo 1 > /proc/sys/net/ipv4/ip_forward
  • Configure dnsmasq. Make the following changes to /etc/dnsmasq.conf (uncomment if necessary):
etc/dnsmasq.conf
domain-needed
bogus-priv
interface=wlan0    # change to your interface
dhcp-range=192.168.0.1,192.168.0.100,12h
  • Start the dnsmasq daemon.
  • Finally, set firewall to forward connections to and from the Internet for clients connecting to your WLAN. This is done by issuing:
# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
In the above the ppp0 interface is assumed to be the used PPP interface, you can substitute it for yours if needed.
  • 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

A quick script for sharing eth0 over wlan0 on an ad-hoc network.

ethoverwlan.sh
#!/bin/bash

iwconfig wlan0 mode ad-hoc
iwconfig wlan0 essid proxywlan
ip addr add 192.168.0.254 dev wlan0
ip link set wlan0 up
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

See Also