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.


Ingredients:
  • 1 USB dongle

Time to cook: 5 minutes

I have a computer in my network called kiwi that has the ip 192.168.1.120 and normally connects with interface eth2 to the LAN and to internet through tomato-router(192.168.1.1) 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
192.168.1.0/24 dev eth2 proto kernel scope link src 192.168.1.120 metric 1
10.64.64.64 dev ppp0 proto kernel scope link src 85.78.143.39
default via 192.168.1.1 dev eth2 proto static

ip route del default
ip route add default via 10.64.64.64 dev ppp0  proto static
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -o ppp0 -i eth2 -s 192.168.1.0/24 -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 0.0.0.0, Gateway: 192.168.1.120, Subnet Mask: 0.0.0.0, 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