{"id":144,"date":"2019-10-31T19:37:23","date_gmt":"2019-10-31T19:37:23","guid":{"rendered":"http:\/\/blog.davcloud.top\/?p=144"},"modified":"2020-01-26T17:03:40","modified_gmt":"2020-01-26T17:03:40","slug":"internal-network-penetration-with-frp-service","status":"publish","type":"post","link":"https:\/\/blog.davcloud.top\/?p=144","title":{"rendered":"Internal network penetration with Frp Service"},"content":{"rendered":"\n<h2>Abstract<\/h2>\n\n\n\n<p>This article aims at introducing what is internal network penetration, and how to achieve it with the open source project Frp on Github on Linux system.<\/p>\n\n\n\n<h2>What is Internal Network Penetration\uff1f<\/h2>\n\n\n\n<p>Internal network penetration, which is called Network Address Translation(NAT) penetration as well. It is used to build the connection between the device in public network and internal network.<\/p>\n\n\n\n<h2>Why we need Internal Network Penetration?<\/h2>\n\n\n\n<p>In order to access the internet, each device should have an address so that the communication between internet and device can be built, which the address is named public IP address. The public IP address are commonly used now is IPv4 address, with the format like xxx.xxx.xxx.xxx. With these addresses, different devices on the internet can access to the internet or access between each other. In the diagram below, Device 1, 2 and 3 can access to the internet, and they can access to each other across the internet as well.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"336\" src=\"https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/10\/IMG_2019-10-31T20-36-46-1-1024x336.jpg\" alt=\"\" class=\"wp-image-157\" srcset=\"https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/10\/IMG_2019-10-31T20-36-46-1-1024x336.jpg 1024w, https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/10\/IMG_2019-10-31T20-36-46-1-300x98.jpg 300w, https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/10\/IMG_2019-10-31T20-36-46-1-768x252.jpg 768w, https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/10\/IMG_2019-10-31T20-36-46-1.jpg 1751w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>However, with the increasing of devices access to the internet, the public IPv4 addresses are not enough to support so much devices. Therefore, to avoid this problem, network operators use Network Address Translation(NAT) techonology. It build a internal network with one public IPv4 address, and many devices in the internal sharing the same public IPv4 address to access the internet. In the diagram below, Device 1, 2 and 3 in NAT 1 can access to the internet with sharing IP address 1, and Device 4, 5 and 6 in NAT 2 can access to the internet with sharing IP address 2. However, because of NAT shielding, devices in two NAT cannot access to devices in another NAT because there is no specific IP address for each device in the same NAT.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"379\" src=\"https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/10\/IMG_2019-10-31T21-26-35-1024x379.jpg\" alt=\"\" class=\"wp-image-172\" srcset=\"https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/10\/IMG_2019-10-31T21-26-35-1024x379.jpg 1024w, https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/10\/IMG_2019-10-31T21-26-35-300x111.jpg 300w, https:\/\/blog.davcloud.top\/wp-content\/uploads\/2019\/10\/IMG_2019-10-31T21-26-35-768x284.jpg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>To solve the problem, internal network penetration allows device in a NAT to be mapped to the public network, and accessed by any devices can access to the internet.<\/p>\n\n\n\n<p>The most famous internal network penetration service is Ngrok, which the first generation project is opened on Github. However, the second generation is not an open source. Therefore, in this article, we use another open source internal network penetration service Frp instead.<\/p>\n\n\n\n<h2>What is Frp?<\/h2>\n\n\n\n<p>Frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet. As of now, it supports tcp &amp; udp, as well as http and https protocols, where requests can be forwarded to internal services by domain name.<\/p>\n\n\n\n<p>The Github project:  <a href=\"https:\/\/github.com\/fatedier\/frp\">https:\/\/github.com\/fatedier\/frp<\/a> <\/p>\n\n\n\n<h2>What can it do?<\/h2>\n\n\n\n<p>With Frp, we can map the service in internal network to the public network. For example, a web page is deploy on the raspberry pi in a internal network, we can map it on a cloud server with public IP address, and then we can access it by the public IP address.<\/p>\n\n\n\n<h2>Deploy Frp service<\/h2>\n\n\n\n<h3>Requirement<\/h3>\n\n\n\n<ol><li>A service deploy on the <em><code>port_internal<\/code><\/em> port of the device with internal IP address <em><code>ip_internal<\/code><\/em> in the internal network. Take raspberry pi with raspbian as example.<\/li><li>A server with independent public IP address <em><code>ip_public<\/code><\/em>, and service map to <em><code>port_public<\/code><\/em> port. Take CentOS 7 as example.<\/li><li>Frp server and client download from Github.<\/li><li>Assume <em><code>port_internal<\/code><\/em> is 7001, <em><code>ip_internal<\/code><\/em> is 192.168.123.101, <code>ip_public<\/code> is 123.456.789.100, <code>port_public<\/code> is 7010.<\/li><\/ol>\n\n\n\n<h3>Step 1. Check internal network access<\/h3>\n\n\n\n<p>Check whether the service in internal network can be accessed by the web address: <em><code>http:\/\/192.168.123.101:7001<\/code><\/em>, make sure it can work correctly.<\/p>\n\n\n\n<h3>Step 2. Download Frp from Github<\/h3>\n\n\n\n<p>Download the latest or required version of Frp from Github, pay attention to the operating system.<\/p>\n\n\n\n<h3>Step 3. Deploy Frp server<\/h3>\n\n\n\n<p>Allow 7000 and 7010 port in firewall on the server management system.<\/p>\n\n\n\n<p>Upload frps, frps.ini to the server, put them into dir <em><code>~\/frp_server<\/code><\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~\nmkdir frp_server\nmv frps frp_server\nmv frps.ini frp_server<\/code><\/pre>\n\n\n\n<p>Modify frps.ini: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># frps.ini\n[common]\n# frps server port\nbind_port = 7000<\/code><\/pre>\n\n\n\n<p>Start frps: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/frps -c .\/frps.ini<\/code><\/pre>\n\n\n\n<h3>Step 4. Deploy Frp client<\/h3>\n\n\n\n<p>Allow 7001 in firewall on raspberry pi, we use ufw to manage the firewall. Details of ufw firewall configuration, see my article below:<\/p>\n\n\n\n<figure class=\"wp-block-embed-wordpress aligncenter wp-block-embed is-type-wp-embed is-provider-davcloud-blog\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"oY055qgMlR\"><a href=\"https:\/\/blog.davcloud.top\/?p=224\">Use ufw to config the firewall on Debian<\/a><\/blockquote><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Use ufw to config the firewall on Debian&#8221; &#8212; davcloud_Blog\" src=\"https:\/\/blog.davcloud.top\/?p=224&#038;embed=true#?secret=uDcFGw5VGV#?secret=oY055qgMlR\" data-secret=\"oY055qgMlR\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 7001\nsudo ufw enable<\/code><\/pre>\n\n\n\n<p>Modify frpc.ini:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># frpc.ini\n[common]\nserver_addr = 123.456.789.100\nserver_port = 7000                # Frp server port\n\n[my_service]\ntype = tcp\nlocal_ip = 192.168.123.101\nlocal_port = 7001\nremote_port = 7010<\/code><\/pre>\n\n\n\n<p>Start frpc:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/frpc -c .\/frpc.ini<\/code><\/pre>\n\n\n\n<h3>Step 5. Access service with public IP<\/h3>\n\n\n\n<p>Now, we can access the service on internal network device by <em><code>http:\/\/123.456.789.100:7010<\/code><\/em>.<\/p>\n\n\n\n<h3>Attention<\/h3>\n\n\n\n<ol><li>The version of server and client of Frp should be match(in the same version).<\/li><li>If the service can access in internal network but cannot access in public network, please make sure the firewall of the server with public IP allows the remote port.<\/li><\/ol>\n\n\n\n<h2>The end<\/h2>\n\n\n\n<p>Above is the basic use of Frp internal network penetration, to use more functions of Frps, such as dashboard, udp , stcp, token, please check the README file of the Frp Github project at  <a href=\"https:\/\/github.com\/fatedier\/frp\">https:\/\/github.com\/fatedier\/frp<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Abstract This article aims at introducing what is internal network penetration, and how to achieve it with the open source project Frp on Github on Linux system. What is Internal Network Penetration\uff1f Internal network penetration, which is called Network Address Translation(NAT) penetration as well. It is used to build the connection between the device in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[34,35],"_links":{"self":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/144"}],"collection":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=144"}],"version-history":[{"count":75,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":793,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/144\/revisions\/793"}],"wp:attachment":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}