Thursday, August 18, 2011

Howto reroute your network traffic

Howto reroute traffic through a client inside a private network in case of an emergency? I was just in such a situation where I had to ask that question and come to an answer also. In other words, my broadband went down.

  • 1 USB dongle

Time to cook: 5 minutes

I have a computer in my network called kiwi that has the ip and normally connects with interface eth2 to the LAN and to internet through tomato-router( on said LAN

I don't know how to do these things in fancy GUIs so here's some command line magic

sudo su
ip route dev eth2 proto kernel scope link src metric 1 dev ppp0 proto kernel scope link src
default via dev eth2 proto static

ip route del default
ip route add default via dev ppp0  proto static
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -o ppp0 -i eth2 -s -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE

Finally I needed to add a static route to my tomato-router
Destination, Gateway:, Subnet Mask:, Metric: 0
Now my entire network was able to connect to the internet almost as well(dongle prone to overheating when transferring data) as it had before my broadband went down

No comments:

Tip me if you like what you're reading