{"id":318,"date":"2015-06-09T07:47:07","date_gmt":"2015-06-08T23:47:07","guid":{"rendered":"http:\/\/finaldie.com\/blog\/?p=318"},"modified":"2015-11-06T02:41:56","modified_gmt":"2015-11-05T18:41:56","slug":"control-your-traffic-principle","status":"publish","type":"post","link":"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/","title":{"rendered":"Control your Traffic &#8212; Principle"},"content":{"rendered":"<p>Everyday, we view a lot of websites, we see many videos without care about how it works. Do you want to know the details? just follow me to take a look, and to see how to control it as well.<\/p>\n<h1>Basic workflow<\/h1>\n<p>The workflow of browser &#8212; website.<\/p>\n<div style=\"width: 480px; height: 360px; margin: 10px; position: relative;\"><iframe id=\"oNoLImk_SpwA\" style=\"width: 480px; height: 360px;\" src=\"https:\/\/www.lucidchart.com\/documents\/embeddedchart\/26bd5c94-86fa-473c-b5e5-2276f1ee8730\" width=\"300\" height=\"150\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/div>\n<ul>\n<li>User inputs a website url<\/li>\n<li>Browser sends a dns query to dns server for this domain<\/li>\n<li>Browser receives the domain <strong>ip<\/strong> records<\/li>\n<li>Browser sends a query to the website server<\/li>\n<li>Browser receives the response data of from the website server<\/li>\n<li>Browser draws the website by the data<\/li>\n<li>User views the website contents<\/li>\n<\/ul>\n<p>The two major transactions in the workflow:<br \/>\n1) DNS server transaction<br \/>\n2) Web server transaction<\/p>\n<h1>What&#8217;s the meaning of Control Traffic<\/h1>\n<p>So controlling the traffic means we need to control <strong>dns query<\/strong> as well as <strong>web server query<\/strong>.<\/p>\n<p><strong>Notes:<\/strong> From above we can see that before sending query to the website server, we need know the IP address of the website and the mapping &#8220;domain &lt;&#8211;&gt; \u00a0IP&#8221; stored in the DNS server. And normally, the DNS query step is hidden for users.<\/p>\n<h1>Why we need to Control the Traffic?<\/h1>\n<p>Before that, we need to know the reason, right?<\/p>\n<p>In some cases, we want to:<br \/>\n1) Connect some websites directly<br \/>\n2) Connect some websites by proxy A (high speed)<br \/>\n3) Connect some websites by proxy B (more security)<br \/>\n&#8230;<\/p>\n<h1>How to Control<\/h1>\n<h2>How to Control DNS Query<\/h2>\n<p>Here we only talk about how to control the DNS from the client side. Because we cannot touch the DNS server, we cannot control it.<\/p>\n<p>There are so many DNS clients we can use. I just recommend the <strong>dnsmasq<\/strong> for a beginner, since it&#8217;s a full feature DNS client, and easy to start with.<\/p>\n<h3>Dnsmasq<\/h3>\n<p>For example, you can configure your dns config and put it into \/etc\/dnsmasq.d\/example.conf:<\/p>\n<pre><code>server=\/.google.com\/8.8.8.8\n<\/code><\/pre>\n<p>The configuration means to use Google&#8217;s DNS server to resolve the domain like *.google.com. Normally, some DNS servers, like openDNS which are geo based DNS, would return the IPs closest to your location, so it would speed up your query time.<\/p>\n<h2>How to Control Website Query (http query)<\/h2>\n<p>In this step, we&#8217;ve already got the IP of the website. And we want connect with this IP by a proxy. So, here we can use <strong>iptables<\/strong> by maintaining an IP list in iptables and forwarding the traffic to the specific proxy if matched.<\/p>\n<h1>The End<\/h1>\n<p>Now, you can write your own dnsmasq configuration file and plan your traffic path with dnsmasq + iptable.<\/p>\n<p>Ok, this article is just a brief introduction. There are some problems we have to face:<br \/>\n1) What if the <strong>DNS server<\/strong> returns wrong IP records?<br \/>\n2) What if the <strong>DNS query<\/strong> is hijacked?<br \/>\n3) It&#8217;s really hard to maintain the IP list for the <strong>iptables<\/strong>. Is there any other way to handle it? (IPSet)<\/p>\n<p>I&#8217;ll talk about these next time. Have fun :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Everyday, we view a lot of websites, we see many videos without care about how it works. Do you want to know the details? just follow me to take a look, and to see how to control it as well. Basic workflow The workflow of browser &#8212; website. User inputs a website url Browser sends &#8230; <a title=\"Control your Traffic &#8212; Principle\" class=\"read-more\" href=\"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/\" aria-label=\"More on Control your Traffic &#8212; Principle\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,17],"tags":[21,20,13,19],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Control your Traffic - Principle - Final Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Control your Traffic - Principle - Final Blog\" \/>\n<meta property=\"og:description\" content=\"Everyday, we view a lot of websites, we see many videos without care about how it works. Do you want to know the details? just follow me to take a look, and to see how to control it as well. Basic workflow The workflow of browser &#8212; website. User inputs a website url Browser sends ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/\" \/>\n<meta property=\"og:site_name\" content=\"Final Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hu.yuzhang\" \/>\n<meta property=\"article:published_time\" content=\"2015-06-08T23:47:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-11-05T18:41:56+00:00\" \/>\n<meta name=\"author\" content=\"final\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hyzwowtools\" \/>\n<meta name=\"twitter:site\" content=\"@hyzwowtools\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"final\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/\",\"url\":\"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/\",\"name\":\"Control your Traffic - Principle - Final Blog\",\"isPartOf\":{\"@id\":\"https:\/\/finaldie.com\/blog\/#website\"},\"datePublished\":\"2015-06-08T23:47:07+00:00\",\"dateModified\":\"2015-11-05T18:41:56+00:00\",\"author\":{\"@id\":\"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3\"},\"breadcrumb\":{\"@id\":\"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/finaldie.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Control your Traffic &#8212; Principle\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/finaldie.com\/blog\/#website\",\"url\":\"https:\/\/finaldie.com\/blog\/\",\"name\":\"Final Blog\",\"description\":\"As simple as possible...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/finaldie.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3\",\"name\":\"final\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/finaldie.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g\",\"caption\":\"final\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Control your Traffic - Principle - Final Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/","og_locale":"en_US","og_type":"article","og_title":"Control your Traffic - Principle - Final Blog","og_description":"Everyday, we view a lot of websites, we see many videos without care about how it works. Do you want to know the details? just follow me to take a look, and to see how to control it as well. Basic workflow The workflow of browser &#8212; website. User inputs a website url Browser sends ... Read more","og_url":"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/","og_site_name":"Final Blog","article_publisher":"https:\/\/www.facebook.com\/hu.yuzhang","article_published_time":"2015-06-08T23:47:07+00:00","article_modified_time":"2015-11-05T18:41:56+00:00","author":"final","twitter_card":"summary_large_image","twitter_creator":"@hyzwowtools","twitter_site":"@hyzwowtools","twitter_misc":{"Written by":"final","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/","url":"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/","name":"Control your Traffic - Principle - Final Blog","isPartOf":{"@id":"https:\/\/finaldie.com\/blog\/#website"},"datePublished":"2015-06-08T23:47:07+00:00","dateModified":"2015-11-05T18:41:56+00:00","author":{"@id":"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3"},"breadcrumb":{"@id":"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/finaldie.com\/blog\/control-your-traffic-principle\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/finaldie.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Control your Traffic &#8212; Principle"}]},{"@type":"WebSite","@id":"https:\/\/finaldie.com\/blog\/#website","url":"https:\/\/finaldie.com\/blog\/","name":"Final Blog","description":"As simple as possible...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/finaldie.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3","name":"final","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/finaldie.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g","caption":"final"}}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts\/318"}],"collection":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/comments?post=318"}],"version-history":[{"count":12,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts\/318\/revisions"}],"predecessor-version":[{"id":333,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts\/318\/revisions\/333"}],"wp:attachment":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/media?parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/categories?post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/tags?post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}