Port Forwarding with Resin 2.0 on RPi 3

raspberrypi3

#1

Hi all, I have an RPi3 connected to a wireless network and an ethernet device with a static IP plugged into the RPi’s ethernet port. I need to be able to forward the port so the ethernet device is accessible via WiFi.

I had this configuration working with the same setup using resin 1.24.xx base image and the connman service by updating the config.json file in the resin-boot image:

".........
files":{"network/settings":"[global]\nOfflineMode=false\n
TimeUpdates=manual\n\n[WiFi]\nEnable=true\nTethering=false\n\n
[Wired]\nEnable=true\nTethering=false\n\n[Bluetooth]\nEnable=true\n
Tethering=false","network/network.config":"[service_home_ethernet]\n
Type = ethernet\nIPv4 = 192.168.0.10/255.255.255.0/192.168.0.10\nNameservers = 8.8.8.8,8.8.4.4\n\n
[service_home_wifi]\nHidden = true\n
Type = wifi\nName = SSIDHERE\nPassphrase = PSKHERE\nNameservers = 8.8.8.8,8.8.4.4"}
....

This allowed me to access the page served by the ethernet connected device via the IP of the RPi on the network.

With Resin v2.0 I have attempted modifying/creating a new file in /system-connections (similar to: Useful Comment)

As such:

I have created a new file called resin-ethernet which contains:

[connection]
id=resin-ethernet
type=ethernet
interface-name=eth0

[ipv4]
method=manual
type=Ethernet
address=192.168.0.10
netmask=255.255.255.0
gateway=192.168.0.10

[ipv6]
addr-gen-mode=stable-privacy
method=auto

I’m still having no luck with getting this to work. I am wondering what I need to change to get this to work as it did on Resin v1.24 with Connman?


Enable Port forwarding for Raspberry Pi OTG network
#2

Hey @Cwright11, according to NetworkManager.conf docs, Your [ipv4] section is not correct.
It should be like

[ipv4]
method=manual
address1=192.168.0.10/24,192.168.0.10

Can you give it a try?


#3

Hi @nghiant2710, thanks for your reply!

Unfortunately, this change didn’t solve the problem. The Pi is still unable to ping the device connected via the ethernet port.
By creating the resin-ethernet file and placing it inside resin-boot/system-connections will it automatically be utilised or is there another step to activate the interface?

The goal of the system is to have the RPi at a static address (e.g. 10.4.0.100) and then have the eth0 interface configured at 192.168.0.10/24,192.168.0.10. The app then takes care of forwarding the ports so when you are on the network and visit 10.4.0.100 you will be served the page of the eth0 connected device.

This was achieved as shown in original post through the config.json file.

Any tips on converting this to a Resin 2.0.0 friendly version?


#4

If you drop a valid Network Manager connection file inside /boot/system-connections directory, Network manager will pick it up.

Oh, I notice there is a resin-wifi configuration file already there. So you need to use the Network Manager DBUS API to disable the connection called resin-wifi and enable the connection called resin-ethernet.


#5

Okay, I believe the file is valid, these are the contents now:

[connection]
id=resin-ethernet
type=ethernet
interface-name=eth0
permissions=
secondaries=

[ethernet]
mac-address-blacklist=

[ipv4]
method=manual
address1=192.168.0.10/24,192.168.0.10
dns=8.8.8.8;8.8.4.4;
dns-search=

[ipv6]    
addr-gen-mode=stable-privacy
dns-search=
method=auto

The above is based on the sample in the resin 2.0.0 documentation.

With the resin-wifi file, I still need this active as the wifi is the means for both the pi and the ethernet connected device to connect to the network. They are sharing the connection essentially.

The problem I am having at the moment is that the ethernet connection is constantly trying to be the main connection to the network. Is there a way to set wlan0 as the main connection and only use eth0 as a gateway for the attached device?


#6

This is a bit more concise explanation of what i’m trying to accomplish:

I’m using resin 2.0 on a raspberry pi 3 which has a wifi connection to a network and then shares this connection with a device plugged into the ethernet port. I’ve added the network configuration file for eth0 in the network connections folder but i’m having trouble when running my app. It is trying to use the ethernet connection to set up resin VPN and connect to internet.
How can I set the image up to prioritise wlan0 as the main interface?


#7

I think you may need to set the autoconnect-priority inside the connection files, more info here


#8

Thanks @joe, I gave it a try by setting the wifi connection up with priority 1 and left the ethernet at default 0 and still have the same problem. If anything is plugged into the ethernet port the device will go offline. If i remove the cable however the wifi will pick back up and it will recover.

I’ve read through the connection, wifi and ethernet sections of the manual and can’t seem to see a setting to ensure the wifi interface is the main connection to use.

I feel as though I am missing something simple, In my first post, that JSON snippet was all that was needed to get Resin to cooperative in V1.24, (This part: "network/network.config":"[service_home_ethernet]\n Type = ethernet\nIPv4 = 192.168.0.10/255.255.255.0/192.168.0.10\nNameservers = 8.8.8.8,8)

Is there another file I need to modify to achieve a result?


#9

It’s definitely possible using Network manager connections only e.g.
http://askubuntu.com/questions/359856/share-wireless-internet-connection-through-ethernet
http://askubuntu.com/questions/3063/share-wireless-connection-with-wired-ethernet-port

Have you tried changing the connection method?
Search https://developer.gnome.org/NetworkManager/stable/ref-settings.html for shared


#10

Thanks @joe!

Got there in the end with setting the ipv4 in ethernet file to ‘shared’. Originally I needed to have a static address as well in the 192.168.0.x range but conceded based on the docs forcing the shared adapter to have a 10.42.x.1 address. This just meant I had to change the addresses on the ethernet connected peripherals.

Thanks again!


#11

Hi @Cwright11. I am understanding from the NetworkManager documentation that the the mode=shared defaults to 10.42.x.1. It sounds like you chose that option over assigning a different static IP as described in the doc? Did you do this because this assignment did not work? I just tried IP mapping option and am not having success.