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
I'll explain the second way (it is easier and requires one less machine).
- Install a second network card to the first PC.
- 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.
- 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 ).
- Configure the second network card with:
- IP: 192.168.0.1
- Netmask: 255.255.255.0
ifconfig eth1 192.168.0.1 netmask 255.255.255.0 ifconfig eth1 up
- To make this permanent, install netcfg if you don't have it and set up a network profile in /etc/network.d, drawing on the examples in /etc/network.d/examples. Or, put the above lines in /etc/rc.local.
- 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
- Then edit /etc/sysctl.conf and set net.ipv4.ip_forward=1. This will make that change persistant after a reboot.
- (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
- 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
net.ipv4.ip_forward=1 net.ipv6.conf.default.forwarding=1 net.ipv6.conf.all.forwarding=1
- Start iptables:
- Add iptables in your DAEMONS array in your /etc/rc.conf so that it is started each time.
- 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
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.confYou 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.