Pages

Tuesday, June 5, 2012

SSH VPN with remote routing


VPN Client

tun0 Private IP
192.168.100.253


VPN Server

tun0 Private IP
192.168.100.254
Public IP
1.2.3.4
Public Interface
eth0


Server
Install Packages
yum install tunctl
Create tun0
tunctl -t tun0
Configure tun0
ifconfig tun0 192.168.100.254 netmask 255.255.255.0 pointopoint 192.168.100.253
Configure sshd for tunnel
vi /etc/ssh/sshd_config
PermitTunnel yes
Restart sshd for Modified Configuration
service sshd restart

Enable forward
sysctl –w net.ipv4.ip_forward=1
iptables -I FORWARD -i tun0 -o eth0 -j ACCEPT
iptables -I FORWARD -i eth0 -o tun0 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.100.253/24 -o eth0 -j MASQUERADE


Local
Install Packages
yum install tunctl
Create tun0
tunctl -t tun0
Configure tun0
ifconfig tun0 192.168.100.253 netmask 255.255.255.0 pointopoint 192.168.100.254
Connect
ssh -w0:0 1.2.3.4

Configure routing (special destination goes through remote gateway / VPN Server)
route add -net some_ip/prefix dev tun0
(e.g. route add -net 140.112.31.0/24 dev tun0)