Hi,
I've set up a Raspberry Pi (distro Raspbian) at home as a media server which I regularly access from outside my network via SSH and other ports.
Recently, I've decided to subscribe to a commercial VPN service after what I've configured my Raspbian with OpenVPN.
After long hours of searching, reading and testing, I found out how to ssh into my server while it's redirecting all traffic from eth0 to tun0. Simply by running:
ip rule add from <internal IP of SSH server/VPN client> table 10
ip route add default via <internal IP of gateway/router> table 10
I added a couple of scripts in /etc/init.d/ to open the VPN connection on boot, and another script that runs the two lines above once the VPN connection is established. So, with the setup above, I can ssh into my server from work without a problem.
My problem is that as soon the two ip commands above are ran, I can't ssh into my server locally (ie. ssh pi@192.168.0.170).
I know this is what keeps me from connecting because if I remove the script from uptade-rc.d (which runs the two ip commands above), then I'm able to ssh into my server locally (but not remotely). And when I run these two ip commands, then the opposite happens: I can ssh remotely but not locally.
Hope it all makes sense, and that you can put me in the right directions in regards to being able to ssh to the pi from both local and remote networks.
Below are some configs that might be useful.
Thanks a lot for your help in advance!
iptables
pi@raspberrypi /etc/iptables $ sudo iptables-save
# Generated by iptables-save v1.4.14 on Fri May 29 10:27:22 2015
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [685:277225]
:fail2ban-ssh - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state INVALID -j DROP
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 32400 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 5850 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 4285 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 72 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -s 192.168.0.0/24 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 22 -j fail2ban-ssh
-A INPUT -i eth0 -p tcp -m tcp --dport 58846 -j ACCEPT
-A fail2ban-ssh -j RETURN
COMMIT
# Completed on Fri May 29 10:27:22 2015
Routes - openvpn connection is closed
pi@raspberrypi /etc/iptables $ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
Sysctl setup as per this post
pi@raspberrypi /etc/iptables $ sudo sysctl -a | grep \\.rp_filter
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.eth0.rp_filter = 1
net.ipv4.conf.lo.rp_filter = 1
Route list
default via 192.168.0.1 dev eth0
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.170