Difference between revisions of "Internet sharing"

From ArchWiki
Jump to: navigation, search
(Instructions: fixed rc.conf configuration to conform to the new format)
(Instructions: corrected rc.conf configuration)
Line 39: Line 39:
gateway=<your gateway>
INTERFACES=(lo eth0 eth1)</pre></li>
INTERFACES=(lo eth0 eth1)</pre></li>

Revision as of 23:29, 7 October 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Internet sharing#)

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Internet sharing#)


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
2. ------> |pc1 (router)| --> pc2..etc


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. If one of the two computers has a gigabit ethernet card, a regular ethernet cable might work.
  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:
    or enter in a console (as root)
    ifconfig eth1 netmask
    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 do not do this.
    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
  9. Edit /etc/conf.d/iptables and enable IP forwarding there (IPTABLES_FORWARD=1). Or, the recommended alternative is to edit /etc/sysctl.conf and add the lines
  10. Start iptables:
    /etc/rc.d/iptables start
  11. Add iptables in your DAEMONS array in your /etc/rc.conf so that it is started each time.
  12. Go to the second PC and set:
    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 netmask
    ifconfig eth0 up
    route add default gw 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