2013年1月2日星期三

How To Make A Split Connection Path From China And OutSideWorld



1, First , we need to know all the China’s ip address.Look at what do in the following:
cd ~
mkdir as
cd as
# Download the ip allocated file from APNIC
wget ftp://ftp.arin.net/pub/stats/arin/delegated-arin-latest
“Some lines are followed”
apnic|AU|ipv4|203.135.184.0|1024|20090615|allocated
apnic|IN|ipv4|203.135.188.0|256|20090616|assigned
apnic|SG|ipv4|203.135.189.0|256|20090616|assigned

# Split it . we just need the ipaddress and the reverse netmask number
cat delegated-apnic-latest | grep ‘apnic|CN’ | grep ipv4 | gawk -F\| ‘{print $4″ “$5}’ > temp.ip+subnet

203.135.184.0 1024
203.135.188.0 256
203.135.189.0 256

# The Following is a php script, that will reverse the reverse netmask number to the netmask, and also generate the route command, and the 192.168.50.1 is also my gateway
<?php
// Generage a array ,that 1=>2^1; ….10=>2^10
$subnet[0]=1;
for ($i=1;$i<=32;$i++) {
$subnet[$i]=$subnet[$i-1]*2;
}



$subnet=array_flip($subnet); // reverse the name and value, so I have

$file=fopen(“temp.ip+subnet”,”r”);

while ( !feof($file)) {
$line = fgets($file);
$line_split = explode(” “,$line);

$ipaddress = $line_split[0];
$subnetnumber= $line_split[1];
$subnetnumber = 32-$subnet[$subnetnumber*1];
echo “route add -net $ipaddress/$subnetnumber gw 192.168.50.1\n”;
}
?>



2. Now you can delete the default gateway that the dhcp gived to you, and you can surface the Chinese Websites by the static routes. So, If now you have a gateway that outside China, such as Japan , USA, now you can add a default gateway to the outside interface.

In my way, I get a openvpn gateway to Japan, So I add a default gateway to it.

route add -net 0.0.0.0/0 gw tun0

3. Another Question?

DNS? This is a big problem, I am still searching in it.And now ,I have some results on it.

1> Do not use the DNS that ISP allocated to you

2> Do not use the 8.8.4.4 that located outside China.(You will be redirect to Chinese outside servers if the website have foreign server)

3> Do use a personal DNS in forward Model, and do not add a forwarders on it , if you do that ,you will fall down to the attention 2.

the forllowing is my DNS bind configuration. It is so easy, and simple:

options
{
forward only;
dump-file “data/cache_dump.db”;
statistics-file “data/named_stats.txt”;
memstatistics-file “data/named_mem_stats.txt”;
};

logging
{
channel defualt_debug {
file “data/named.run”;
severity dynamic;
};
};

view “any”
{
match-clients { any; };
match-destinations { any; };
#include “/etc/named.root.hints”;
#include “/etc/named.rfc1912.zones”;
};

没有评论:

发表评论