I have a Raspberry Pi3B box where I have set up OpenVPN server as I have on a number of other units before.
But this is different in that it is dual homed, it has both an eth0 and a wlan0 network interface.
Either or both can be used depending on where and how it is hooked up when it starts.
Now I wonder how to set up openvpn and iptables such that I don't have to specify which interface is going to be used?
Both interfaces are getting an address from DHCP in the same network and I have reserved x.x.x.173 and 174 for the two connections in the router. So both use the same Internet gateway etc.
What I want is to have openvpn listen on
all network interfaces (which I think it does out of the box).
I also want it to route traffic over the
same network as it was connected through, so if a client connects on 173 traffic will go through 173 and the same for 174.
QUESTIONS:
1. OpenVPN server settings
Is there any special configuration I have to use in order for the server to listen to both interfaces?
I thought that I could create 2 port forward rules in the router, one for x.x.x.173:1194 and the other for x.x.x.174:1194 where the incoming port would be 1194 for the eth0 interface and 1195 for the wlan0 interface but both pointing to the 1194 port on the RPi.
Or do I have to create a second openvpn server instance that listens on 1195 and not translate the port number in the router?
2. IPTABLES setup
This is where I am having trouble since I am not really understanding the inner workings of iptables...
In the past I have had only a single interface and in the iptables entries the network interface was spelled out with the IP address.
But I think this is no good, you should not have to reconfigure iptables if the box gets a new address, right?
So how should the proper iptables rules look like to cover both interfaces without specifying their network addresses?
Currently I have the following for testing:
sudo iptables-save
# Generated by iptables-save v1.4.21 on Tue May 29 09:20:48 2018
*filter
:INPUT ACCEPT [350:29013]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [304:44808]
COMMIT
# Completed on Tue May 29 09:20:48 2018
# Generated by iptables-save v1.4.21 on Tue May 29 09:20:48 2018
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [2:134]
:POSTROUTING ACCEPT [2:134]
-A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 192.168.119.173
-A POSTROUTING -s 10.8.0.0/24 -o wlan0 -j SNAT --to-source 192.168.119.174
COMMIT
# Completed on Tue May 29 09:20:48 2018
I would like destination to be the same as from where the client connected. And I do not want to specify the IP address in the rule, it should be the interface itself, but how?
And what about MASQUERADE? I have seen this in iptables before, is it needed and if so how do I create it properly?
I am sorry if these are "basic" questions but I never got my head around iptables so I am using cook-book instructions here and they differ...