2014年6月27日 星期五

sample tinc-up script to send only forwarded packets to VPN

#!/bin/bash

#match /etc/iproute2/rt_tables
TABLE=$INTERFACE
MARK=0x1

ifconfig $INTERFACE 192.168.11.254 netmask 255.255.0.0

echo 1 >/proc/sys/net/ipv4/conf/eth0/proxy_arp
echo 1 >/proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
echo 1 >/proc/sys/net/ipv4/ip_forward

#To accept asymmetrically routed (outgoing routes and incoming routes are different) packets
echo 2 > /proc/sys/net/ipv4/conf/$INTERFACE/rp_filter

ip route add default dev $INTERFACE table $TABLE
ip rule add fwmark $MARK table $TABLE

iptables -A PREROUTING -t mangle -d 172.16.11.0/24 -j ACCEPT
iptables -A PREROUTING -t mangle -d 192.168.11.0/24 -j ACCEPT
iptables -A PREROUTING -t mangle -j MARK --set-mark $MARK