Linux Advanced Routing Tutorial

National vs. International Traffic

Google's public DNS server B is clearly an off-shore international destination. However, one of the root DNS servers, namely with IP, is present here in New Zealand. At the moment, the traceroute to still shows the ADSL path:

[workstation] ~ $ /usr/sbin/traceroute
traceroute to (, 30 hops max, 
 ↪40 byte packets using UDP
 1 (  
    ↪0.175 ms  0.126 ms  0.125 ms
 2 (  
    ↪0.861 ms  0.840 ms  0.825 ms
 3  core-adsl.isp2 (218.101.x.y)  22.456 ms  22.298 ms  23.501 ms
 4 (192.203.154.x)  21.035 ms  20.928 ms  21.268 ms
 5 (192.203.154.y)  20.689 ms  21.724 ms  24.187 ms
 6 (  26.680 ms  26.059 ms  25.427 ms

This is clearly national traffic, and it should go out via the SHDSL link as per our plan. We can do that manually and set the appropriate route on our core router:

[router] ~ # ip route add via 
 ↪dev vlan-shdsl

A side note about NAT'ing: we also need to translate (or "masquerade" or NAT) the office address range to our SHDSL public IP If we didn't, the packet's source IP would be, and the replies would never find their way back to my workstation, as this address range is not routable in the public Internet. Discussing firewalls and NATs is out of scope of this article, but to get you going, here's the simplest magic command:

[router] ~ # iptables -t nat -A POSTROUTING -s 
 ↪-o vlan-shdsl -j DNAT --to

All packets with a source address from the range leaving through the interface vlan-shdsl will get the source rewritten to We didn't need to set up any masquerading for the ADSL path, because there the ADSL router NATs all our outgoing traffic.

Now, let's check the new network path:

[workstation] ~ $ /usr/sbin/traceroute
traceroute to (, 30 hops max, 
 ↪40 byte packets using UDP
 1 (  
    ↪0.190 ms  0.129 ms  0.125 ms
 2  rt-shdsl.isp1 (  2.676 ms  2.599 ms  2.632 ms
 3  rt3.isp1 (  2.715 ms  2.680 ms  2.591 ms
 4 (192.203.154.z)  2.919 ms  3.033 ms  3.088 ms
 5 (  3.007 ms  2.670 ms  2.864 ms

That's lot better. The first hop remains the same, that's my workstation's router, but the second hop is no longer the ADSL modem. Instead, it's the SHDSL ISP1's core router. It also clearly shows the latency improvement—from 26ms over ADSL to 3ms over SHDSL.

Let's remove the manual route again to avoid any confusion down the road and query the routing table:

[router] ~ # ip route get from 
 ↪ iif vlan-office from via 
 ↪dev vlan-shdsl        # SHDSL

[router] ~ # ip route delete via 
 ↪dev vlan-shdsl

[router] ~ # ip route get from 
 ↪ iif vlan-office from via 
 ↪dev vlan-adsl      # ADSL

So all we need now is a list of all national IP addresses, put them in the routing table, and we're done. But how? Manually? Even in a small country like New Zealand there are hundreds of local IP addresses and prefixes, and the list is dynamic and changes daily. There is no way such a list could be managed manually. We need a better tool.


Michal Ludvig works for Enterprise IT Ltd in New Zealand as a senior Linux engineer. He's got root access to some of the largest New Zealand corporations, but since he tends to forget his passwords, he is, in general, pretty harmless.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


bahce00's picture

Coverage of the 2007 MWRC has been fairly comprehensive.

very good, post more please

florian's picture

very good post... more on routing with bird/quagga and or advanced routing with linux is welcome. thanks.

nice read! bird config file

Moosa's picture

nice read! bird config file killed the purpose of obscuring AS no. in the table.(just saying)

Very nice and informative.

khappieinstein's picture

Very nice and informative. Inspired me to start Experimenting again. Thanks again. Keep writing. It been long i have touch base with LINUX.