Preparing a Raspberry Pi to be used as a Gateway
Share Raspberry Pi Wi-Fi Internet to Ethernet
In this step, the Raspberry Pi must be connected to the Internet via Wi-Fi, and the PLC must be connected to the Raspberry Pi via the Ethernet connection.
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:
2. To configure the DHCP client, open the configuration file
and paste denyinterfaces eth0
at the end of the file. Close the configuration file (Esc, :w (Enter), :q (Enter)
).
3. Next, open the network interfaces
and paste the following lines at the end of the file:
Close 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