Preparing a Raspberry Pi to be used as a Gateway
Share Raspberry Pi Wi-Fi Internet to Ethernet
You will now configure the Raspberry Pi to share the Wi-Fi Internet connection to Ethernet. Run the following commands on the Raspberry Pi.
1. (Optional) Update the Raspberry Pi:
sudo apt-get update
sudo apt-get upgrade2. To configure the DHCP client, open the configuration file
sudo vi /etc/dhcpcd.confand paste denyinterfaces eth0 at the end of the file. Close the configuration file (Esc, :w (Enter), :q (Enter)).
3. Next, open the network interfaces
sudo vi /etc/network/interfacesand paste the following lines at the end of the file:
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.66.1
netmask 255.255.255.0
network 192.168.66.0
broadcast 192.168.66.255Close the network interface file (Esc, :w (Enter), :q (Enter)).
4. Install and configure the DHCP service to automatically assign IP addresses for every device in the Ethernet Port. Install dnsmasq and create a new configuration:
Add the following lines to the file
and close the configuration (Esc, :w (Enter), :q (Enter)).
5. Reboot the Raspberry Pi.
Afterwards, we need to reopen the SSH connection.
6. Now, we forward the Internet connection from Wifi to the Ethernet port where the PLC is connected by setting IPv4 forwarding. Open the /etc/systcl.conf file:
Uncomment the following line by removing the # (line 28):
Save and close the file (Esc, :w (Enter), :q (Enter)).
7. Activate IP forwarding by running the following command:
8. Now, we install iptables and add firewall rules. Run the following commands one at a time:
9. Check that the changes were made and save the rules:
To automatically reload these rules after every reboot, edit the /etc/rc.local file:
Paste the following line before exit 0:
Save and close the file (Esc, :w (Enter), :q (Enter)).
10. To check the firewall settings, run
The routing table should look like this:
Now, you can check the SDA console to see if the connection to the Gateway was established and if the PLC is connected.
Last updated