Difference between revisions of "Internet sharing"

From ArchWiki
Jump to: navigation, search
m (Instructions)
m (some formal, format)
Line 1: Line 1:
 
[[Category:Networking (English)]]
 
[[Category:Networking (English)]]
 
[[Category:HOWTOs (English)]]
 
[[Category:HOWTOs (English)]]
 
 
{{i18n_links_start}}
 
{{i18n_links_start}}
 
{{i18n_entry|English|Internet_Share}}
 
{{i18n_entry|English|Internet_Share}}
Line 8: Line 7:
 
{{i18n_links_end}}
 
{{i18n_links_end}}
  
=Preface=
+
==Preface==
 
+
 
Let's assume you have an internet connection and you want to share it. There are two main ways to do that.
 
Let's assume you have an internet connection and you want to share it. There are two main ways to do that.
  
Line 16: Line 14:
 
1. ----> |router| ---> |switch| --->-<
 
1. ----> |router| ---> |switch| --->-<
 
                                       pc2 ..etc
 
                                       pc2 ..etc
 
+
  internet
+
  internet
 
2. ------> |pc1 (router)| --> pc2..etc
 
2. ------> |pc1 (router)| --> pc2..etc
 
</pre>
 
</pre>
  
=Instructions=
+
==Instructions==
 
+
 
+
 
I'll explain the second way (it is easier and requires one less machine).
 
I'll explain the second way (it is easier and requires one less machine).
 
<ol>
 
<ol>
Line 38: Line 34:
 
<pre>ifconfig eth1 192.168.0.1 netmask 255.255.255.0
 
<pre>ifconfig eth1 192.168.0.1 netmask 255.255.255.0
 
ifconfig eth1 up</pre></li>
 
ifconfig eth1 up</pre></li>
 +
 
<li>Enter that same information in your '''/etc/rc.conf''' so that this card is set up correctly earch time your computer starts.
 
<li>Enter that same information in your '''/etc/rc.conf''' so that this card is set up correctly earch time your computer starts.
 
'''Note''': If you use '''Wicd''', you don't do this.
 
'''Note''': If you use '''Wicd''', you don't do this.
Line 53: Line 50:
 
/etc/rc.d/iptables save
 
/etc/rc.d/iptables save
 
/etc/rc.d/iptables start</pre></li>
 
/etc/rc.d/iptables start</pre></li>
 +
 
<li>Add iptables in your DAEMONS array in your /etc/rc.conf so that it is started each time.</li>
 
<li>Add iptables in your DAEMONS array in your /etc/rc.conf so that it is started each time.</li>
  
Line 61: Line 59:
 
:'''DNS:''' The same DNS as the first PC
 
:'''DNS:''' The same DNS as the first PC
  
do this like this (eth0 is assumed to be your network interface on PC2 with which you are connected to PC1):
+
Proceed like this (eth0 is assumed to be your network interface on PC2 with which you are connected to PC1):
 
<pre>ifconfig eth0 192.168.0.2 netmask 255.255.255.0
 
<pre>ifconfig eth0 192.168.0.2 netmask 255.255.255.0
 
ifconfig eth0 up
 
ifconfig eth0 up
Line 70: Line 68:
 
You can figure out the address of the nameserver by looking into the /etc/resolv.conf of PC1, if its internet connection is already established.</li></ol>
 
You can figure out the address of the nameserver by looking into the /etc/resolv.conf of PC1, if its internet connection is already established.</li></ol>
  
Note: Of course, this also works with a mobile broadband connection (usually called ppp0 on PC1)
+
{{Note| Of course, this also works with a mobile broadband connection (usually called ppp0 on PC1)}}
  
That's it! The second PC should now have internet.
+
That's it. The second PC should now have internet.
  
=See Also=
+
==See also==
 
*[[Sharing ppp connection with wlan interface]]
 
*[[Sharing ppp connection with wlan interface]]
 
*[[Simple stateful firewall HOWTO]]
 
*[[Simple stateful firewall HOWTO]]
 
*[[NAT'ing firewall - Share your broadband connection]]
 
*[[NAT'ing firewall - Share your broadband connection]]

Revision as of 17:20, 16 November 2009

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

Preface

Let's assume you have an internet connection and you want to share it. There are two main ways to do that.

   internet                           pc1
1. ----> |router| ---> |switch| --->-<
                                      pc2 ..etc
 
   internet
2. ------> |pc1 (router)| --> pc2..etc

Instructions

I'll explain the second way (it is easier and requires one less machine).

  1. Install a second network card to the first PC.
  2. Connect the two PCs (using crossover cable or a switch).
  3. Let's assume that the first card (with the internet) is called eth0 and the other one (for the sharing) is called eth1. (If those two keep switching at every boot read this ).
  4. Configure the second network card with:
    IP: 192.168.0.1
    Netmask: 255.255.255.0
    or enter in a console (as root)
    ifconfig eth1 192.168.0.1 netmask 255.255.255.0
    ifconfig eth1 up
  5. Enter that same information in your /etc/rc.conf so that this card is set up correctly earch time your computer starts. Note: If you use Wicd, you don't do this.
    eth1="eth1 192.168.0.1 netmask 255.255.255.0"
    INTERFACES=(lo eth0 eth1)
  6. Enable packet forwarding. To do so, write a "1" to /proc/sys/net/ipv4/ip_forward with:
    echo 1 > /proc/sys/net/ipv4/ip_forward
  7. Then edit /etc/sysctl.conf and set 1 to the net.ipv4.ip_forward (It should be net.ipv4.ip_forward=1). This will make that change persistant after a reboot.
  8. (If you haven't already) Install iptables and enter this rule (for the forwarding of the internet to the second PC) and save iptables.
    pacman -S iptables
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    /etc/rc.d/iptables save
    /etc/rc.d/iptables start
  9. Add iptables in your DAEMONS array in your /etc/rc.conf so that it is started each time.
  10. Go to the second PC and set:
    IP: 192.168.0.2
    Netmask: 255.255.255.0
    Gateway: 192.168.0.1
    DNS: The same DNS as the first PC
    Proceed like this (eth0 is assumed to be your network interface on PC2 with which you are connected to PC1):
    ifconfig eth0 192.168.0.2 netmask 255.255.255.0
    ifconfig eth0 up
    route add default gw 192.168.0.1 eth0
    echo "nameserver <adr of nameserver>" >> /etc/resolv.conf
    
    You can figure out the address of the nameserver by looking into the /etc/resolv.conf of PC1, if its internet connection is already established.
Note: Of course, this also works with a mobile broadband connection (usually called ppp0 on PC1)

That's it. The second PC should now have internet.

See also