Skip to content

Instantly share code, notes, and snippets.

@girishkalele
Last active June 17, 2016 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save girishkalele/905e5e4a260e9c88cbce1504caa8fc99 to your computer and use it in GitHub Desktop.
Save girishkalele/905e5e4a260e9c88cbce1504caa8fc99 to your computer and use it in GitHub Desktop.
Launder using routing into a loopback tunnel
#!/bin/bash
# SIGSTOP kube-proxy
kill -STOP `ps auxwww | grep kube-proxy | grep -v /bin/sh | grep -v grep | awk '{print $2}'`
export NODEID="3"
export CBRA="10.244.$NODEID.1"
export ETHA="10.128.0.$NODEID"
# GRE point to point tunnel to launder packets
ip tunnel add laundryin mode gre remote $ETHA local $CBRA
ip link set laundryin up
ip tunnel add laundryout mode gre local $ETHA remote $CBRA
ip link set laundryout up
# Create a routing table named laundromat pointing to the laundry tunnel
echo 200 laundromat >> /etc/iproute2/rt_tables
ip route add default dev laundryin table laundromat
# PBR rules to push packets into the laundromat
ip rule add fwmark 0x4000/0x4000 iif cbr0 lookup laundromat priority 1000
ip rule add from all iif laundryout lookup default priority 2000
ip rule add from all iif cbr0 oif cbr0 lookup laundromat priority 3000
# Need to prevent masquerade into the tunnel
iptables -t nat -I KUBE-POSTROUTING 1 -o laundryin -m mark --mark 0x4000/0x4000 -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment