I have a Wifi stick to connect to a wireless network, but unfortunately the vendor did not care to supply a reliable Linux driver, and the connection every so often gets lost. Since I also have a Raspberry Pi, I wanted to try and use that for internet access via ethernet cable. Having used the setup for almost a week now, I can say that it is better than the previous one although the Wifi router does not seem to be the best either, because the connection quality significantly decreases when there is lots of traffic.
Anyway, I configured my Raspberry using these
howtos and docs. The following instructions
are a blend of what I found in there. They assume you have already connected
your machine (most likely a desktop computer) to the interface named
using an ethernet cable. In this guide,
eth0 is given the address
First, install dnsmasq which is used as a DHCP server to provide your machine with an IP address.
sudo apt install dnsmasq
/etc/dnsmasq.conf and add the following values:
interface=eth0 listen-address=192.168.2.1 bind-interfaces domain-needed bogus-priv dhcp-range=192.168.2.50,192.168.2.150,12h
This will configure
dnsmasq to use addresses starting from
/etc/dhcpcd.conf and add the following at the end to configure
with a static address:
interface eth0 static ip_address=192.168.2.1/24
dhcpcd to make the new settings go into effect:
sudo service dhcpcd restart
Configure port forwarding as described in the docs:
/etc/sysctl.confand uncomment this line:
Add a masquerade for outbound traffic on
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
Save the iptables rule.
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
/etc/rc.localand add this just above “exit 0” to install these rules on boot.
iptables-restore < /etc/iptables.ipv4.nat
Reboot and ensure it still functions.
Now, your machine will automatically get an IP address when it is connected to the Rapsberry, and it will, assuming the Pi is itself connected, use that connection to access the internet.