This commit is contained in:
arraykeys
2021-05-11 13:40:18 +08:00
commit 94fffdbd84
159 changed files with 223308 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GOPROXY Manual</title>
<meta name="description" content="GOPROXY Manual,GOPROXY 帮助手册">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<style>*{-webkit-font-smoothing:antialiased;-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-text-size-adjust:none;-webkit-touch-callout:none;box-sizing:border-box}body:not(.ready){overflow:hidden}body:not(.ready) .app-nav,body:not(.ready)>nav,body:not(.ready) [data-cloak]{display:none}div#app{font-size:30px;font-weight:lighter;margin:40vh auto;text-align:center}div#app:empty:before{content:"Loading..."}.emoji{height:19.2px;height:1.2rem;vertical-align:middle}.progress{background-color:#42b983;background-color:var(--theme-color,#42b983);height:2px;left:0;position:fixed;right:0;top:0;transition:width .2s,opacity .4s;width:0;z-index:5}.search .search-keyword,.search a:hover{color:#42b983;color:var(--theme-color,#42b983)}.search .search-keyword{font-style:normal;font-weight:700}body,html{height:100%}body{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;color:#34495e;font-family:Source Sans Pro,Helvetica Neue,Arial,sans-serif;font-size:15px;letter-spacing:0;margin:0;overflow-x:hidden}img{max-width:100%}a[disabled]{cursor:not-allowed;opacity:.6}kbd{border:1px solid #ccc;border-radius:3px;display:inline-block;font-size:12px!important;line-height:12px;margin-bottom:3px;padding:3px 5px;vertical-align:middle}.task-list-item{list-style-type:none}li input[type=checkbox]{margin:0 .2em .25em -1.6em;vertical-align:middle}.app-nav{left:0;margin:25px 60px 0 0;position:absolute;right:0;text-align:right;z-index:2}.app-nav p{margin:0}.app-nav>a{margin:0 16px;margin:0 1rem;padding:5px 0}.app-nav li,.app-nav ul{display:inline-block;list-style:none;margin:0}.app-nav a{color:inherit;font-size:16px;text-decoration:none;transition:color .3s}.app-nav a.active,.app-nav a:hover{color:#42b983;color:var(--theme-color,#42b983)}.app-nav a.active{border-bottom:2px solid #42b983;border-bottom:2px solid var(--theme-color,#42b983)}.app-nav li{display:inline-block;margin:0 16px;margin:0 1rem;padding:5px 0;position:relative}.app-nav li ul{background-color:#fff;border:1px solid #ddd;border-bottom-color:#ccc;border-radius:4px;box-sizing:border-box;display:none;max-height:calc(100vh - 61px);overflow-y:scroll;padding:10px 0;position:absolute;right:-15px;text-align:left;top:100%;white-space:nowrap}.app-nav li ul li{display:block;font-size:14px;line-height:16px;line-height:1rem;margin:0;margin:8px 14px;white-space:nowrap}.app-nav li ul a{display:block;font-size:inherit;margin:0;padding:0}.app-nav li ul a.active{border-bottom:0}.app-nav li:hover ul{display:block}.app-nav.no-badge{margin-right:25px}.github-corner{border-bottom:0;position:fixed;right:0;text-decoration:none;top:0;z-index:1}.github-corner svg{color:#fff;fill:#42b983;fill:var(--theme-color,#42b983);height:80px;width:80px}.github-corner:hover .octo-arm{-webkit-animation:a .56s ease-in-out;animation:a .56s ease-in-out}main{display:block;position:relative;width:100vw;height:100%;z-index:0}.anchor{display:inline-block;text-decoration:none;transition:all .3s}.anchor span{color:#34495e}.anchor:hover{text-decoration:underline}.sidebar{border-right:1px solid rgba(0,0,0,.07);overflow-y:auto;padding:40px 0 0;top:0;bottom:0;left:0;position:absolute;transition:-webkit-transform .25s ease-out;transition:transform .25s ease-out;transition:transform .25s ease-out,-webkit-transform .25s ease-out;width:300px;z-index:3}.sidebar>h1{margin:0 auto 16px;margin:0 auto 1rem;font-size:24px;font-size:1.5rem;font-weight:300;text-align:center}.sidebar>h1 a{color:inherit;text-decoration:none}.sidebar>h1 .app-nav{display:block;position:static}.sidebar .sidebar-nav{line-height:2em;padding-bottom:40px}.sidebar ul{margin:0;padding:0}.sidebar li>p{font-weight:700;margin:0}.sidebar ul,.sidebar ul li{list-style:none}.sidebar ul li a{border-bottom:none;display:block}.sidebar ul li ul{padding-left:20px}.sidebar::-webkit-scrollbar{width:4px}.sidebar::-webkit-scrollbar-thumb{background:transparent;border-radius:4px}.sidebar:hover::-webkit-scrollbar-thumb{background:hsla(0,0%,53%,.4)}.sidebar:hover::-webkit-scrollbar-track{background:hsla(0,0%,53%,.1)}.sidebar-toggle{background-color:transparent;background-color:hsla(0,0%,100%,.8);border:0;outline:none;padding:10px;bottom:0;left:0;position:absolute;text-align:center;transition:opacity .3s;width:30px;width:284px;z-index:4}.sidebar-toggle .sidebar-toggle-button:hover{opacity:.4}.sidebar-toggle span{background-color:#42b983;background-color:var(--theme-color,#42b983);display:block;margin-bottom:4px;width:16px;height:2px}body.sticky .sidebar,body.sticky .sidebar-toggle{position:fixed}.content{padding-top:60px;top:0;right:0;bottom:0;left:300px;position:absolute;transition:left .25s ease}.markdown-section{margin:0 auto;max-width:800px;padding:30px 15px 40px;position:relative}.markdown-section>*{box-sizing:border-box;font-size:inherit}.markdown-section>:first-child{margin-top:0!important}.markdown-section hr{border:none;border-bottom:1px solid #eee;margin:2em 0}.markdown-section table{border-collapse:collapse;border-spacing:0;display:block;margin-bottom:16px;margin-bottom:1rem;overflow:auto;width:100%}.markdown-section th{font-weight:700}.markdown-section td,.markdown-section th{border:1px solid #ddd;padding:6px 13px}.markdown-section tr{border-top:1px solid #ccc}.markdown-section p.tip,.markdown-section tr:nth-child(2n){background-color:#f8f8f8}.markdown-section p.tip{border-bottom-right-radius:2px;border-left:4px solid #f66;border-top-right-radius:2px;margin:2em 0;padding:12px 24px 12px 30px;position:relative}.markdown-section p.tip code{background-color:#efefef}.markdown-section p.tip em{color:#34495e}.markdown-section p.tip:before{background-color:#f66;border-radius:100%;color:#fff;content:"!";font-family:Dosis,Source Sans Pro,Helvetica Neue,Arial,sans-serif;font-size:14px;font-weight:700;left:-12px;line-height:20px;position:absolute;width:20px;height:20px;text-align:center;top:14px}.markdown-section p.warn{background:rgba(66,185,131,.1);border-radius:2px;padding:16px;padding:1rem}body.close .sidebar{-webkit-transform:translateX(-300px);transform:translateX(-300px)}body.close .sidebar-toggle{width:auto}body.close .content{left:0}@media print{.app-nav,.github-corner,.sidebar,.sidebar-toggle{display:none}}@media screen and (max-width:768px){.github-corner,.sidebar,.sidebar-toggle{position:fixed}.app-nav{margin-top:16px}.app-nav li ul{top:30px}main{height:auto;overflow-x:hidden}.sidebar{left:-300px;transition:-webkit-transform .25s ease-out;transition:transform .25s ease-out;transition:transform .25s ease-out,-webkit-transform .25s ease-out}.content{left:0;max-width:100vw;position:static;padding-top:20px;transition:-webkit-transform .25s ease;transition:transform .25s ease;transition:transform .25s ease,-webkit-transform .25s ease}.app-nav,.github-corner{transition:-webkit-transform .25s ease-out;transition:transform .25s ease-out;transition:transform .25s ease-out,-webkit-transform .25s ease-out}.sidebar-toggle{background-color:transparent;width:auto;padding:30px 30px 10px 10px}body.close .sidebar{-webkit-transform:translateX(300px);transform:translateX(300px)}body.close .sidebar-toggle{background-color:hsla(0,0%,100%,.8);transition:background-color 1s;width:284px;padding:10px}body.close .content{-webkit-transform:translateX(300px);transform:translateX(300px)}body.close .app-nav,body.close .github-corner{display:none}.github-corner .octo-arm{-webkit-animation:a .56s ease-in-out;animation:a .56s ease-in-out}.github-corner:hover .octo-arm{-webkit-animation:none;animation:none}}@-webkit-keyframes a{0%,to{-webkit-transform:rotate(0);transform:rotate(0)}20%,60%{-webkit-transform:rotate(-25deg);transform:rotate(-25deg)}40%,80%{-webkit-transform:rotate(10deg);transform:rotate(10deg)}}@keyframes a{0%,to{-webkit-transform:rotate(0);transform:rotate(0)}20%,60%{-webkit-transform:rotate(-25deg);transform:rotate(-25deg)}40%,80%{-webkit-transform:rotate(10deg);transform:rotate(10deg)}}section.cover{-webkit-box-align:center;-ms-flex-align:center;align-items:center;background-position:50%;background-repeat:no-repeat;background-size:cover;height:100vh;display:none}section.cover .cover-main{-webkit-box-flex:1;-ms-flex:1;flex:1;margin:-20px 16px 0;text-align:center;z-index:1}section.cover a{color:inherit}section.cover a,section.cover a:hover{text-decoration:none}section.cover p{line-height:24px;line-height:1.5rem;margin:1em 0}section.cover h1{color:inherit;font-size:40px;font-size:2.5rem;font-weight:300;margin:10px 0 40px;margin:.625rem 0 2.5rem;position:relative;text-align:center}section.cover h1 a{display:block}section.cover h1 small{bottom:-7px;bottom:-.4375rem;font-size:16px;font-size:1rem;position:absolute}section.cover blockquote{font-size:24px;font-size:1.5rem;text-align:center}section.cover ul{line-height:1.8;list-style-type:none;margin:1em auto;max-width:500px;padding:0}section.cover .cover-main>p:last-child a{border-color:#42b983;border:1px solid var(--theme-color,#42b983);border-radius:2rem;box-sizing:border-box;color:#42b983;color:var(--theme-color,#42b983);display:inline-block;font-size:16.8px;font-size:1.05rem;letter-spacing:1.6px;letter-spacing:.1rem;margin-right:16px;margin-right:1rem;padding:.75em 32px;padding:.75em 2rem;text-decoration:none;transition:all .15s ease}section.cover .cover-main>p:last-child a:last-child{background-color:#42b983;background-color:var(--theme-color,#42b983);color:#fff;margin-right:0}section.cover .cover-main>p:last-child a:last-child:hover{color:inherit;opacity:.8}section.cover .cover-main>p:last-child a:hover{color:inherit}section.cover blockquote>p>a{border-bottom:2px solid #42b983;border-bottom:2px solid var(--theme-color,#42b983);transition:color .3s}section.cover blockquote>p>a:hover{color:#42b983;color:var(--theme-color,#42b983)}section.cover.show{display:-webkit-box;display:-ms-flexbox;display:flex}section.cover.has-mask .mask{background-color:#fff;opacity:.8;position:absolute;top:0;width:100%;height:100%}.sidebar,body{background-color:#fff}.sidebar{color:#364149}.sidebar li{margin:6px 0 6px 15px}.sidebar ul li a{color:#505d6b;font-size:14px;font-weight:400;overflow:hidden;text-decoration:none;text-overflow:ellipsis;white-space:nowrap}.sidebar ul li a:hover{text-decoration:underline}.sidebar ul li ul{padding:0}.sidebar ul li.active>a{border-right:2px solid;color:#42b983;color:var(--theme-color,#42b983);font-weight:600}.app-sub-sidebar li:before{content:"-";padding-right:4px;float:left}.markdown-section h1,.markdown-section h2,.markdown-section h3,.markdown-section h4,.markdown-section strong{color:#2c3e50;font-weight:600}.markdown-section a{color:#42b983;color:var(--theme-color,#42b983);font-weight:600}.markdown-section h1{font-size:32px;font-size:2rem;margin:0 0 16px;margin:0 0 1rem}.markdown-section h2{font-size:28px;font-size:1.75rem;margin:45px 0 12.8px;margin:45px 0 .8rem}.markdown-section h3{font-size:24px;font-size:1.5rem;margin:40px 0 9.6px;margin:40px 0 .6rem}.markdown-section h4{font-size:20px;font-size:1.25rem}.markdown-section h5,.markdown-section h6{font-size:16px;font-size:1rem}.markdown-section h6{color:#777}.markdown-section figure,.markdown-section p{margin:1.2em 0}.markdown-section ol,.markdown-section p,.markdown-section ul{line-height:25.6px;line-height:1.6rem;word-spacing:.8px;word-spacing:.05rem}.markdown-section ol,.markdown-section ul{padding-left:24px;padding-left:1.5rem}.markdown-section blockquote{border-left:4px solid #42b983;border-left:4px solid var(--theme-color,#42b983);color:#858585;margin:2em 0;padding-left:20px}.markdown-section blockquote p{font-weight:600;margin-left:0}.markdown-section iframe{margin:1em 0}.markdown-section em{color:#7f8c8d}.markdown-section code{border-radius:2px;color:#e96900;font-size:12.8px;font-size:.8rem;margin:0 2px;padding:3px 5px;white-space:pre-wrap}.markdown-section code,.markdown-section pre{background-color:#f8f8f8;font-family:Roboto Mono,Monaco,courier,monospace}.markdown-section pre{-moz-osx-font-smoothing:initial;-webkit-font-smoothing:initial;line-height:24px;line-height:1.5rem;margin:1.2em 0;overflow:auto;padding:0 22.4px;padding:0 1.4rem;position:relative;word-wrap:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#8e908c}.token.namespace{opacity:.7}.token.boolean,.token.number{color:#c76b29}.token.punctuation{color:#525252}.token.property{color:#c08b30}.token.tag{color:#2973b7}.token.string{color:#42b983;color:var(--theme-color,#42b983)}.token.selector{color:#6679cc}.token.attr-name{color:#2973b7}.language-css .token.string,.style .token.string,.token.entity,.token.url{color:#22a2c9}.token.attr-value,.token.control,.token.directive,.token.unit{color:#42b983;color:var(--theme-color,#42b983)}.token.keyword{color:#e96900}.token.atrule,.token.regex,.token.statement{color:#22a2c9}.token.placeholder,.token.variable{color:#3d8fd1}.token.deleted{text-decoration:line-through}.token.inserted{border-bottom:1px dotted #202746;text-decoration:none}.token.italic{font-style:italic}.token.bold,.token.important{font-weight:700}.token.important{color:#c94922}.token.entity{cursor:help}.markdown-section pre>code{-moz-osx-font-smoothing:initial;-webkit-font-smoothing:initial;background-color:#f8f8f8;border-radius:2px;color:#525252;display:block;font-family:Roboto Mono,Monaco,courier,monospace;font-size:12.8px;font-size:.8rem;line-height:inherit;margin:0 2px;max-width:inherit;overflow:inherit;padding:2.2em 5px;white-space:inherit}.markdown-section code:after,.markdown-section code:before{letter-spacing:.8px;letter-spacing:.05rem}code .token{-moz-osx-font-smoothing:initial;-webkit-font-smoothing:initial;min-height:24px;min-height:1.5rem}pre:after{color:#ccc;content:attr(data-lang);font-size:9.6px;font-size:.6rem;font-weight:600;height:15px;line-height:15px;padding:5px 10px 0;position:absolute;right:0;text-align:right;top:0}</style>
</head>
<body>
<div id="app">loading……</div>
</body>
<script>
window.$docsify = {
name: 'GOPROXY',
maxLevel: 2,
repo: 'snail007/goproxy',
homepage:"manual.md",
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/docsify/4.9.1/docsify.min.js"></script>
</html>
+1864
View File
@@ -0,0 +1,1864 @@
## How to Install
  
### 1. Linux Install
[click me get Linux installation](https://github.com/snail007/goproxy/blob/master/README_ZH.md#%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85-goproxy)
### 2. MacOS Install
[click me get MacOS installation](https://github.com/snail007/proxy_admin_free/blob/master/README_ZH.md#%E8%A7%86%E9%A2%91%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B)
### 3. Windows Install
[click me get Windows installation](https://github.com/snail007/proxy_admin_free/blob/master/README_ZH.md#%E8%A7%86%E9%A2%91%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B)
### 4. Others Install
[click me get Windows installation](https://github.com/snail007/goproxy/blob/master/README_ZH.md#%E6%89%8B%E5%8A%A8%E5%AE%89%E8%A3%85-goproxy)
## Purchase Commercial Edition
This manual describes the functions, all of which are included in the commercial version; the free version of advanced functional parameters such as authentication is not included;
If you encounter some commands when you use the free version to execute some commands, a prompt similar to the following xxx parameter does not exist, indicating that this parameter is a function of the commercial version.
`err: unknown long flag '-a'`
Comparison between the features of the free version and the commercial version, detailed operations on how to purchase and use the commercial version [please click here to view](https://snail.gitee.io/proxy/page/free_vs_commercial_en/)
## First Start
### 1. Environment
The manual tutorial, the default system is linux, the program is proxy; all operations require root privileges;
If you are windows, please use the windows version of proxy.exe.
  
### 2. Using configuration files
The next tutorial will introduce the usage method through the command line parameters, or you can get the parameters by reading the configuration file.
The specific format is to specify the configuration file by the @ symbol, for example: proxy @configfile.txt
The format in configfile.txt is that the first line is the name of the subcommand, and the second line starts with one parameter per line.
Format: `parameter Parameter value`, direct write parameter without parameter value, for example: --nolog
For example, the contents of configfile.txt are as follows:
```shell
Http
-t tcp
-p :33080
--forever
```
### 3. Debug output
By default, the information output by the log does not include the number of file lines. In some cases, in order to troubleshoot the program, the problem is quickly located.
You can use the --debug parameter to output the number of lines of code and milliseconds.
### 4. Using log files
By default, the log is displayed directly in the console. If you want to save to a file, you can use the --log parameter.
For example: --log proxy.log, the log will be output to the proxy.log to facilitate troubleshooting.
### 5. Generate the certificate file required for encrypted communication
The http, tcp, udp proxy process communicates with the upstream. For security, we use encrypted communication. Of course, we can choose not to encrypt the communication. All the communication and the upstream communication in this tutorial are encrypted, and the certificate file is required.
1. Generate a self-signed certificate and key file with the following command.
`proxy keygen -C proxy`
The certificate file proxy.crt and the key file proxy.key will be generated under the current program directory.
2. Use the following command to generate a new certificate using the self-signed certificate proxy.crt and the key file proxy.key: goproxy.crt and goproxy.key.
`proxy keygen -s -C proxy -c goproxy`
The certificate file goproxy.crt and the key file goproxy.key will be generated under the current program directory.
3. By default, the domain name inside the certificate is random and can be specified using the `-n test.com` parameter.
4. More usage: `proxy keygen --help`.
### 6. Running in the background
After the proxy is executed by default, you cannot close the command line if you want to keep the proxy running.
If you want to run the proxy in the background, the command line can be closed, just add the --daemon parameter at the end of the command.
For example:
`proxy http -t tcp -p "0.0.0.0:38080" --daemon`
### 7. Guardian running
The daemon runs the parameter --forever, for example: `proxy http --forever` ,
The proxy will fork the child process, and then monitor the child process. If the child process exits abnormally, restart the child process after 5 seconds.
This parameter is matched with the background running parameter --daemon and log parameter --log, which can guarantee that the proxy will always execute in the background without accidentally exiting.
And you can see the output log content of the proxy through the log file.
For example: `proxy http -p ":9090" --forever --log proxy.log --daemon`
### 8. Security advice
When the VPS is behind the nat device, the vps network card IP is the intranet IP. At this time, you can use the -g parameter to add the vps external network ip to prevent the infinite loop.
Suppose your vps external network ip is 23.23.23.23. The following command sets 23.23.23.23 with the -g parameter.
`proxy http -g "23.23.23.23"`
### 9. Load balancing and high availability
The HTTP(S)\SOCKS5\SPS proxy supports upper-level load balancing and high availability, and multiple upstream repeat-P parameters can be used.
The load balancing policy supports five types, which can be specified by the `--lb-method` parameter:
Roundrobin used in turn
Leastconn uses the minimum number of connections
Leasttime uses the least connection time
Hash uses a fixed upstream based on the client address
Weight Select a upstream according to the weight and number of connections of each upstream
prompt:
1. The load balancing check interval can be set by `--lb-retrytime` in milliseconds.
2. The load balancing connection timeout can be set by `--lb-timeout` in milliseconds.
3. If the load balancing policy is weight, the -P format is: 2.2.2.2: 3880?w=1, where 1 is the weight and an integer greater than 0.
4. If the load balancing policy is hash, the default is to select the upstream based on the client address. You can select the upstream by using the destination address of the access `--lb-hashtarget`.
5. The TCP proxies has no parameter `--lb-hashtarget`.
6. Default is load balancing + high availability mode. If the parameter `--lb-onlyha` is used, only the high availability mode is used, then a node is selected according to the load balancing strategy, and this node will be used until it is not alive, then another node will be selected for using, thus cycling.
7. If the all nodes are not alive, a random node will be selected for using.
### 10. Agent springboard jump
Http (s) agent, SPS agent, intranet penetration, tcp agent support the connection of upstreams through intermediate third-party agents,
The parameters are: --jumper, all the formats are as follows:
```text
 http://username:password@host:port
 http://host:port
 https://username:password@host:port
 https://host:port
 socks5://username:password@host:port
 socks5://host:port
 socks5s://username:password@host:port
 socks5s://host:port
 ss://method:password@host:port
```
Http,socks5 represents the normal http and socks5 proxy.
Https,socks5s represents the http and socks5 agents protected by tls.
That is http proxy over TLS, socks over TLS.
### 11. Domain Name Black and White List
The socks/http(s)/sps proxy supports domain name black and white lists.
Use the --stop parameter to specify a domain name blacklist file, then the connection will be disconnected when the user connects these domains in the file.
Specify a domain name whitelist file with the --only parameter, then the connection will be disconnected when the user connects to a domain other than those domains in the file.
If both --stop and --only are set, then only --only will work.
The format of the black and white domain name list file is as follows:
```text
**.baidu.com
*.taobao.com
A.com
192.168.1.1
192.168.*.*
?.qq.com
```
Description:
1. One domain name per line, domain name writing supports wildcards `*` and `?`, `*` represents any number of characters, `?` represents an arbitrary character,
2.`**.baidu.com` Matches no matter how many levels all suffixes are ..baidu.com`.
3.`*.taobao.com` The matching suffix is the third-level domain name of `.taobao.com`.
4. It can also be an IP address directly.
5.`#` at the beginning of the comment.
### 12. Client IP Blacklist and Whitelist
socks/http(s)/sps/tcp/udp/dns/ intranet penetration bridge/intranet penetration tbridge, support client IP black and white list.
Use the --ip-deny parameter to specify a client IP blacklist list file, then the connection will be disconnected when the user's IP is in this file.
  
Use the --ip-allow parameter to specify a client IP whitelist file, then the connection will be disconnected when the user's IP is not in the file.
If both --ip-deny and --ip-allow are set, then only --ip-allow will work.
The format of the client IP blacklist and whitelist file is as follows:
```text
192.168.1.1
192.168.*.*
192.168.1?.*
```
Description:
1. One domain name per domain, domain name writing supports wildcards `*` and `?`, `*` represents any number of characters, `?` represents an arbitrary character.
2.`#` at the beginning of the comment.
### 13. Protocol loading file
There are many places in the proxy's various proxy functions to set a file. For example: --blocked Specifies a domain name list file that goes directly to the upper level. The parameter value is the path of the file.
If the parameter supports the protocol loading file, the file path can be not only the file path, but also:
a. The base64 encoding at the beginning of "base64://" indicates the contents of the above file, for example: base64://ajfpoajsdfa=
b. "str://" at the beginning of the English comma separated multiple, such as: str://xxx, yyy
The proxy's blocked, direct, stop, only, hosts, resolve.rules, rewriter.rules, ip.allow, ip.deny files support protocol loading.
### 14.Concurrent client connections
socks5\sps\http proxies, the parameter that controls the number of concurrent client connections is: `--max-conns-rate`, which controls the maximum number of client connections per second, default: 20, 0 is unlimited
### 15 Listen on multiple ports
"tcp / http / socks / sps" supports listen on multiple ports and range ports.
Under normal circumstances, it is sufficient to listen on one port, but if you need to listen on multiple ports, the -p parameter is supported.
The format is: `-p 0.0.0.0:80,0.0.0.0:443,.0.0.0.0:8000-9000,:5000-6000`, more The bindings can be separated by commas.
## 1.HTTP Proxies
### 1.1. Ordinary level HTTP proxy
![1.1](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/http-1.png)
`proxy http -t tcp -p "0.0.0.0:38080"`
  
Listen port argument `-p` can be:
```text
-p ":8081" listen on 8081
-p ":8081,:8082" listen on 8081 and 8082
-p ":8081,:8082,:9000-9999" listen on 8081 and 8082 and 9000 and 9001 to 9999, 1002 total ports
```
### 1.2. Ordinary secondary HTTP proxy
![1.2](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/http-2.png)
Use local port 8090, assuming the upstream HTTP proxy is `22.22.22.22:8080`
`proxy http -t tcp -p "0.0.0.0:8090" -T tcp -P "22.22.22.22:8080" `
We can also specify the black and white list file of the website domain name, one domain name per line, the matching rule is the rightmost match, for example: baidu.com, the match is *.*.baidu.com, the blacklist domain name goes directly to the upstream agent, whitelist The domain name does not go to the upstream agent.
`proxy http -p "0.0.0.0:8090" -T tcp -P "22.22.22.22:8080" -b blocked.txt -d direct.txt`
  
### 1.3.HTTP secondary agent (encryption)
> Note: The `proxy.crt` and `proxy.key` used by the secondary proxy should be consistent with the primary proxy.
![1.3](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/http-tls-2.png)
Level 1 HTTP proxy (VPS, IP: 22.22.22.22)
`proxy http -t tls -p ":38080" -C proxy.crt -K proxy.key`
  
Secondary HTTP proxy (local Linux)
`proxy http -t tcp -p ":8080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
Then access the local port 8080 is to access the proxy port 38080 on the VPS.
  
Secondary HTTP proxy (local windows)
`proxy.exe http -t tcp -p ":8080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
Then set your windos system, the proxy that needs to go through the proxy Internet program is http mode, the address is: 127.0.0.1, the port is: 8080, the program can access the Internet through vps through the encrypted channel.
  
### 1.4.HTTP Level 3 Agent (Encryption)
![1.3](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/http-tls-3.png)
Level 1 HTTP proxy VPS_01, IP: 22.22.22.22
`proxy http -t tls -p ":38080" -C proxy.crt -K proxy.key`
Secondary HTTP proxy VPS_02, IP: 33.33.33.33
`proxy http -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
Level 3 HTTP proxy (local)
`proxy http -t tcp -p ":8080" -T tls -P "33.33.33.33:28080" -C proxy.crt -K proxy.key`
Then accessing the local port 8080 is to access the proxy port 38080 on the primary HTTP proxy.
  
### 1.5.Basic certification
For the proxy HTTP protocol, we can perform Basic authentication. The authenticated username and password can be specified on the command line.
`proxy http -t tcp -p ":33080" -a "user1:pass1" -a "user2:pass2"`
For multiple users, repeat the -a parameter.
It can also be placed in a file in the format of a "username:password" and then specified with -F.
`proxy http -t tcp -p ":33080" -F auth-file.txt`
  
In addition, the http(s) proxy also integrates external HTTP API authentication. We can specify an http url interface address with the --auth-url parameter.
Then when there is a user connection, the proxy will request the url in GET mode, and bring the following four parameters. If the HTTP status code 204 is returned, the authentication is successful.
In other cases, the authentication failed.
For example:
`proxy http -t tcp -p ":33080" --auth-url "http://test.com/auth.php"`
When the user connects, the proxy will request the url ("http://test.com/auth.php") in GET mode.
Take five parameters: user, pass, ip, local_ip, target:
Http://test.com/auth.php?user={USER}&pass={PASS}&ip={IP}&local_ip={LOCAL_IP}&target={TARGET}
User: username
Pass: password
Ip: User's IP, for example: 192.168.1.200
Local_ip: IP of the server accessed by the user, for example: 3.3.3.3
Target: URL accessed by the user, for example: http://demo.com:80/1.html or https://www.baidu.com:80
If there is no -a or -F or --auth-url parameter, the Basic authentication is turned off.
### 1.6. HTTP proxy traffic is forced to go to the upper HTTP proxy
By default, the proxy will intelligently determine whether a website domain name is inaccessible. If it is not accessible, it will go to the upper level HTTP proxy. With --always, all HTTP proxy traffic can be forced to go to the upper HTTP proxy.
`proxy http --always -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
### 1.7.HTTP(S) via SSH relay
![1.7](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/http-ssh-1.png)
Description: The principle of ssh transfer is to use the forwarding function of ssh, that is, after you connect to ssh, you can access the target address through ssh proxy.
Suppose there is: vps
- IP is 2.2.2.2, ssh port is 22, ssh username is: user, ssh user password is: demo
- The user's ssh private key name is user.key
#### *1.7.1 How to ssh username and password*
Local HTTP(S) proxy port 28080, executing:
`proxy http -T ssh -P "2.2.2.2:22" -u user -D demo -t tcp -p ":28080"`
#### *1.7.2 How to ssh username and key*
Local HTTP(S) proxy port 28080, executing:
`proxy http -T ssh -P "2.2.2.2:22" -u user -S user.key -t tcp -p ":28080"`
### 1.8.KCP protocol transmission
![1.8](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/http-kcp.png)
The KCP protocol requires the --kcp-key parameter to set a password for encrypting and decrypting data.
Level 1 HTTP proxy (VPS, IP: 22.22.22.22)
`proxy http -t kcp -p ":38080" --kcp-key mypassword`
  
Secondary HTTP proxy (local Linux)
`proxy http -t tcp -p ":8080" -T kcp -P "22.22.22.22:38080" --kcp-key mypassword`
Then access the local port 8080 is to access the proxy port 38080 on the VPS, the data is transmitted through the kcp protocol, note that the kcp is the udp protocol, so the firewall needs to release the 380p udp protocol.
### 1.9 HTTP(S) Reverse Proxy
![1.9](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/fxdl.png)
The proxy not only supports the proxy setting in other software, but also provides proxy services for other software. It also supports directly parsing the requested website domain name to the proxy listening ip, and then the proxy listens to the 80 and 443 ports, then the proxy will automatically You proxy access to the HTTP(S) website you need to access.
How to use:
On the "last level proxy proxy" machine, because the proxy is to be disguised as all websites, the default HTTP port of the website is 80, HTTPS is 443, and the proxy can listen to ports 80 and 443. Parameters -p multiple addresses with commas segmentation.
`proxy http -t tcp -p :80,:443`
This command starts a proxy agent on the machine, and listens to ports 80 and 443 at the same time. It can be used as a normal proxy, or directly resolve the domain name that needs to be proxyed to the IP of this machine.
If there is a upstream agent, then refer to the above tutorial to set the upstream, the use is exactly the same.
`proxy http -t tcp -p :80,:443 -T tls -P "2.2.2.2:33080" -C proxy.crt -K proxy.key`
Note:
The DNS resolution result of the server where the proxy is located cannot be affected by the custom resolution, otherwise it will be infinite loop. The proxy proxy should specify the `--dns 8.8.8.8` parameter.
### 1.10 HTTP(S) Transparent Proxy
This mode needs to have a certain network foundation. If the related concepts are not understood, please search for it yourself.
Assuming the proxy is now running on the router, the startup command is as follows:
`proxy http -t tcp -p :33080 -T tls -P "2.2.2.2:33090" -C proxy.crt -K proxy.key`
Then add the iptables rule, here are the reference rules:
```shell
#Upper proxy server IP address:
Proxy_server_ip=2.2.2.2
#路由器Running port for proxy listening:
Proxy_local_port=33080
#The following does not need to be modified
#create a new chain named PROXY
Iptables -t nat -N PROXY
# Ignore your PROXY server's addresses
# It's very IMPORTANT, just be careful.
Iptables -t nat -A PROXY -d $proxy_server_ip -j RETURN
# Ignore LANs IP address
Iptables -t nat -A PROXY -d 0.0.0.0/8 -j RETURN
Iptables -t nat -A PROXY -d 10.0.0.0/8 -j RETURN
Iptables -t nat -A PROXY -d 127.0.0.0/8 -j RETURN
Iptables -t nat -A PROXY -d 169.254.0.0/16 -j RETURN
Iptables -t nat -A PROXY -d 172.16.0.0/12 -j RETURN
Iptables -t nat -A PROXY -d 192.168.0.0/16 -j RETURN
Iptables -t nat -A PROXY -d 224.0.0.0/4 -j RETURN
Iptables -t nat -A PROXY -d 240.0.0.0/4 -j RETURN
# Anything to port 80 443 should be redirected to PROXY's local port
Iptables -t nat -A PROXY -p tcp --dport 80 -j REDIRECT --to-ports $proxy_local_port
Iptables -t nat -A PROXY -p tcp --dport 443 -j REDIRECT --to-ports $proxy_local_port
# Apply the rules to nat client
Iptables -t nat -A PREROUTING -p tcp -j PROXY
# Apply the rules to localhost
Iptables -t nat -A OUTPUT -p tcp -j PROXY
```
- Clear the entire chain iptables -F Chain names such as iptables -t nat -F PROXY
- Delete the specified user-defined chain iptables -X chain name such as iptables -t nat -X PROXY
- Remove rules from the selected chain iptables -D chain name Rule details such as iptables -t nat -D PROXY -d 223.223.192.0/255.255.240.0 -j RETURN
### 1.11 Custom DNS
--dns-address and --dns-ttl parameters, used to specify the dns (--dns-address) used by the proxy to access the domain name.
And the analysis result cache time (--dns-ttl) seconds, to avoid system dns interference to the proxy, in addition to the cache function can also reduce the dns resolution time to improve access speed.
For example:
`proxy http -p ":33080" --dns-address "8.8.8.8:53" --dns-ttl 300`
### 1.12 Custom encryption
The proxy's http(s) proxy can encrypt tcp data via tls standard encryption and kcp protocol on top of tcp, in addition to support customization after tls and kcp.
Encryption, that is to say, custom encryption and tls|kcp can be used in combination. The internal use of AES256 encryption, you only need to define a password when you use it.
Encryption is divided into two parts, one is whether the local (-z) encryption and decryption, and the other is whether the transmission with the upstream (-Z) is encrypted or decrypted.
Custom encryption requires both ends to be proxy. The following two levels and three levels are used as examples:
Secondary instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy http -t tcp -z demo_password -p :7777`
Local secondary execution:
`proxy http -T tcp -P 2.2.2.2:777 -Z demo_password -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through encrypted transmission with the upstream.
Three-level instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy http -t tcp -z demo_password -p :7777`
Execute on the secondary vps (ip: 3.3.3.3):
`proxy http -T tcp -P 2.2.2.2:7777 -Z demo_password -t tcp -z other_password -p :8888`
Local three-level execution:
`proxy http -T tcp -P 3.3.3.3:8888 -Z other_password -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through encrypted transmission with the upstream.
### 1.13 Compressed transmission
The proxy http(s) proxy can encrypt tcp data through tls standard encryption and kcp protocol on top of tcp, and can also compress data before custom encryption.
That is to say, compression and custom encryption and tls|kcp can be used in combination. Compression is divided into two parts, one part is local (-m) compression transmission.
Part of it is compressed with the upstream (-M) transmission.
Compression requires both sides to be proxy. Compression also protects (encrypted) data to a certain extent. The following uses Level 2 and Level 3 as examples:
Secondary instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy http -t tcp -m -p :7777`
Local secondary execution:
`proxy http -T tcp -P 2.2.2.2:777 -M -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through compression with the upstream.
Three-level instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy http -t tcp -m -p :7777`
Execute on the secondary vps (ip: 3.3.3.3):
`proxy http -T tcp -P 2.2.2.2:7777 -M -t tcp -m -p :8888`
Local three-level execution:
`proxy http -T tcp -P 3.3.3.3:8888 -M -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through compression with the upstream.
### 1.14 Load Balancing
The HTTP(S) proxy supports upper-level load balancing, and multiple upstream repeat-P parameters can be used.
`proxy http --lb-method=hash -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080`
### 1.14.1 Setting the retry interval and timeout time
`proxy http --lb-method=leastconn --lb-retrytime 300 --lb-timeout 300 -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080 -t tcp - p :33080`
### 1.14.2 Setting weights
`proxy http --lb-method=weight -T tcp -P 1.1.1.1:33080?w=1 -P 2.1.1.1:33080?w=2 -P 3.1.1.1:33080?w=1 -t tcp - p :33080`
### 1.14.3 Use the target address to select the upstream
`proxy http --lb-hashtarget --lb-method=hash -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080 -t tcp -p :33080`
### 1.15 Speed limit
The speed limit is 100K, which can be specified by the `-l` parameter, for example: 100K 2000K 1M . 0 means no limit.
`proxy http -t tcp -p 2.2.2.2:33080 -l 100K`
### 1.16 Specifying Outgoing IP
The `--bind-listen` parameter can be used to open the client connection with the portal IP, and use the portal IP as the outgoing IP to access the target website. If the incorrect IP is bound, the proxy will not work. At this point, the proxy will try to bind the target without binding the IP, and the log will prompt.
`proxy http -t tcp -p 2.2.2.2:33080 --bind-listen`
### 1.17 Certificate parameters use base64 data
By default, the -C, -K parameter is the path to the crt certificate and the key file.
If it is the beginning of base64://, then the latter data is considered to be base64 encoded and will be used after decoding.
### 1.18 Intelligent mode
Intelligent mode setting, can be one of intelligent|direct|parent.
The default is: intelligent.
The meaning of each value is as follows:
`--intelligent=direct`, the targets in the blocked are not directly connected.
`--intelligent=parent`, the target that is not in the direct is going to the higher level.
`--intelligent=intelligent`, blocked and direct have no targets, intelligently determine whether to use the upstream access target.
### 1.19 Help
`proxy help http`
## 2.TCP Proxies
  
### 2.1. Ordinary level TCP proxy
![2.1](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/tcp-1.png)
Local execution:
`proxy tcp -p ":33080" -T tcp -P "192.168.22.33:22"`
Then access the local port 33080 is to access port 22 of 192.168.22.33.
  
The `-p` parameter supports :
```text
  -p ":8081" listen on 8081
  -p ":8081,:8082" listen on 8081 and 8082
  -p ":8081,:8082,:9000-9999" listen on 8081 and 8082 and 9000, 9001 to 9999 for a total of 1002 ports
```
If the number of local listening ports is greater than 1, the corresponding upper port corresponding to the local port will be connected, and the port in `-P` will be ignored.
If you need a connection from all ports, connect to the upper specified port, you can add the parameter `--lock-port`.
such as:
`proxy tcp -p ":33080-33085" -T tcp -P "192.168.22.33:0"`
Then the connection of the `33080` port will connect to the `33080` port of 192.168.22.33, and the other ports are similar. The local and upper ports are the same. At this time, the port in the parameter `-P` uses `0`.
If you want to connect the ports of `33080`, `33081`, etc. to the `22` port of 192.168.22.33, you can add the parameter `--lock-port`.
`proxy tcp -p ":33080-33085" -T tcp -P "192.168.22.33:22" --lock-port`
### 2.2. Ordinary secondary TCP proxy
![2.2](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/tcp-2.png)
VPS (IP: 22.22.2.33) is executed:
`proxy tcp -p ":33080" -T tcp -P "127.0.0.1:8080"`
Local execution:
`proxy tcp -p ":23080" -T tcp -P "22.22.22.33:33080"`
Then access the local port 23080 is to access port 8020 of 22.22.22.33.
  
### 2.3. Ordinary three-level TCP proxy
![2.3](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/tcp-3.png)
Primary TCP proxy VPS_01, IP: 22.22.22.22
`proxy tcp -p ":38080" -T tcp -P "66.66.66.66:8080"`
Secondary TCP proxy VPS_02, IP: 33.33.33.33
`proxy tcp -p ":28080" -T tcp -P "22.22.22.22:38080"`
Level 3 TCP proxy (local)
`proxy tcp -p ":8080" -T tcp -P "33.33.33.33:28080"`
Then access the local port 8080 is to access the port 8080 of 66.66.66.66 through the encrypted TCP tunnel.
  
### 2.4. Encrypting secondary TCP proxy
![2.4](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/tcp-tls-2.png)
VPS (IP: 22.22.2.33) is executed:
`proxy tcp -t tls -p ":33080" -T tcp -P "127.0.0.1:8080" -C proxy.crt -K proxy.key`
Local execution:
`proxy tcp -p ":23080" -T tls -P "22.22.22.33:33080" -C proxy.crt -K proxy.key`
Then access the local port 23080 is to access the port 8080 of 22.22.22.33 through the encrypted TCP tunnel.
  
### 2.5.Encrypting Level 3 TCP Agent
![2.5](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/tcp-tls-3.png)
Primary TCP proxy VPS_01, IP: 22.22.22.22
`proxy tcp -t tls -p ":38080" -T tcp -P "66.66.66.66:8080" -C proxy.crt -K proxy.key`
Secondary TCP proxy VPS_02, IP: 33.33.33.33
`proxy tcp -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
Level 3 TCP proxy (local)
`proxy tcp -p ":8080" -T tls -P "33.33.33.33:28080" -C proxy.crt -K proxy.key`
Then access the local port 8080 is to access the port 8080 of 66.66.66.66 through the encrypted TCP tunnel.
  
### 2.6 Connecting to a upstream through a proxy
Sometimes the network where the proxy is located cannot directly access the external network. You need to use an https or socks5 proxy to access the Internet. Then this time
The -J parameter can help you to connect the proxy to the peer-P through the https or socks5 proxy when mapping the proxy tcp port, mapping the external port to the local.
The -J parameter format is as follows:
Https proxy writing:
The proxy needs authentication, username: username password: password
Https://username:password@host:port
Agent does not require authentication
Https://host:port
Socks5 proxy writing:
The proxy needs authentication, username: username password: password
Socks5://username:password@host:port
Agent does not require authentication
Socks5://host:port
Host: the IP or domain name of the proxy
Port: the port of the proxy
### 2.7 Specify Outgoing IP
When the TCP proxy is a superior type (parameter: -T) is tcp, it supports the specified exit IP. Using the `--bind-listen` parameter, you can open the client to connect with the portal IP, and use the portal IP as the outgoing IP to access the target website. If an incorrect IP is bound, the proxy will not work, the proxy will try to bind the target without binding the IP, and the log will prompt.
`proxy tcp -p ":33080" -T tcp -P" 192.168.22.33:22" -B`
### 2.8 Speed limit, connections limit
The parameter `--max-conns` can limit the maximum number of connections per port.
For example, limit the maximum number of connections per port:
`proxy tcp -p ":33080" -T tcp -P "192.168.22.33:22" --max-conns 1000`
The parameter `--rate-limit` can limit the rate of each tcp connection.
For example, limit the connection rate of each tcp to 100k/s:
`proxy tcp -p ":33080" -T tcp -P "192.168.22.33:22" --rate-limit 100k`
### 2.9 Compressed transmission
`--c` controls whether to compress transmission between local and client, default false;` --C` controls whether to compress transmission between local and upstream, default false.
Examples:
VPS (IP: 22.22.22.33) implementation:
`proxy tcp -t tcp --c -p ":33080" -T tcp -P "127.0.0.1:8080"`
Local execution:
`proxy tcp -t tcp -p ":23080" -T tcp -P "22.22.22.33:33080" --C`
### 2.10 View Help
`proxy help tcp`
## 3.UDP Proxies
  
### 3.1. Ordinary UDP proxy
![3.1](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/udp-1.png)
Local execution:
`proxy udp -p ":5353" -T udp -P "8.8.8.8:53"`
Then access the local UDP: 5353 port is to access 8.8.8.8 UDP: 53 port.
  
The `-p` parameter supports :
```text
  -p ":8081" listen on 8081
  -p ":8081,:8082" listen on 8081 and 8082
  -p ":8081,:8082,:9000-9999" listen on 8081 and 8082 and 9000, 9001 to 9999 for a total of 1002 ports
```
If the number of local listening ports is greater than 1, the corresponding upper port corresponding to the local port will be connected, and the port in `-P` will be ignored.
If you need a connection from all ports, connect to the upper specified port, you can add the parameter `--lock-port`.
such as:
`proxy udp -p ":33080-33085" -T udp -P "192.168.22.33:0"`
Then the connection of the `33080` port will connect to the `33080` port of 192.168.22.33, and the other ports are similar. The local and upper ports are the same. At this time, the port in the parameter `-P` uses `0`.
If you want to connect the ports of `33080`, `33081`, etc. to the `2222` port of 192.168.22.33, you can add the parameter `--lock-port`.
`proxy udp -p ":33080-33085" -T udp -P "192.168.22.33:2222" --lock-port`
### 3.2. Ordinary secondary UDP proxy
![3.2](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/udp-2.png)
VPS (IP: 22.22.2.33) is executed:
`proxy tcp -p ":33080" -T udp -P "8.8.8.8:53"`
Local execution:
`proxy udp -p ":5353" -T tcp -P "22.22.22.33:33080"`
Then access the local UDP: 5353 port is through the TCP tunnel, through the VPS access 8.8.8.8 UDP: 53 port.
  
### 3.3. Ordinary three-level UDP proxy
![3.3](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/udp-3.png)
Primary TCP proxy VPS_01, IP: 22.22.22.22
`proxy tcp -p ":38080" -T udp -P "8.8.8.8:53"`
Secondary TCP proxy VPS_02, IP: 33.33.33.33
`proxy tcp -p ":28080" -T tcp -P "22.22.22.22:38080"`
Level 3 TCP proxy (local)
`proxy udp -p ":5353" -T tcp -P "33.33.33.33:28080"`
Then access to the local 5353 port is through the TCP tunnel, through the VPS to access port 8.8.8.8.
  
### 3.4. Encrypting secondary UDP proxy
![3.4](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/udp-tls-2.png)
VPS (IP: 22.22.2.33) is executed:
`proxy tcp -t tls -p ":33080" -T udp -P "8.8.8.8:53" -C proxy.crt -K proxy.key`
Local execution:
`proxy udp -p ":5353" -T tls -P "22.22.22.33:33080" -C proxy.crt -K proxy.key`
Then access the local UDP: 5353 port is through the encrypted TCP tunnel, through the VPS access 8.8.8.8 UDP: 53 port.
  
### 3.5. Encryption Level 3 UDP Agent
![3.5](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/udp-tls-3.png)
Primary TCP proxy VPS_01, IP: 22.22.22.22
`proxy tcp -t tls -p ":38080" -T udp -P "8.8.8.8:53" -C proxy.crt -K proxy.key`
Secondary TCP proxy VPS_02, IP: 33.33.33.33
`proxy tcp -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
Level 3 TCP proxy (local)
`proxy udp -p ":5353" -T tls -P "33.33.33.33:28080" -C proxy.crt -K proxy.key`
Then access the local 5353 port is to access the 8.8.8.8 port 53 through VPS_01 through the encrypted TCP tunnel.
### 3.6 Specify Outgoing IP
When the UDP upstream proxies (parameter: -T) is udp, it supports the specified outgoing IP. Using the `--bind-listen` parameter, you can open the client to connect with the server IP, and use the server IP as the outgoing IP to access the target. If an incorrect IP is bound, the proxy will not work.
`proxy udp -p ":33080" -T udp -P "192.168.22.33:2222" -B`
### 3.7 Help
`proxy help udp`
## 4. Expose Intranet
### 4.1 principle description
Intranet penetration, divided into two versions, "multi-link version" and "multiplexed version", generally like a web service, this service is not a long-term connection, it is recommended to use "multi-link version", if it is to keep long The time connection suggests using a "multiplexed version."
1. Multi-link version, the corresponding sub-command is tserver, tclient, tbridge.
1. Multiplexed version, the corresponding subcommand is server, client, bridge.
1. The parameters of the multi-link version and the multiplex version are exactly the same.
1. The multiplexed version of the server, client can open the compressed transmission, the parameter is --c.
1. server, client either open compression, or not open, can not open only one.
The following tutorial uses the "multiplexed version" as an example to illustrate how to use it.
The intranet penetration consists of three parts: client, server, and bridge; client and server actively connect to the bridge for bridging.
### 4.2 TCP common usage
Background:
- Company Machine A provides web service port 80
- There is a VPS, public network IP: 22.22.22.22
Demand:
At home, you can access the port 80 of company machine A by accessing port 28080 of the VPS.
  
Steps:
Execute on vps
    `proxy bridge -p ":33080" -C proxy.crt -K proxy.key`
    `proxy server -r ":28080@:80" -P "127.0.0.1:33080" -C proxy.crt -K proxy.key`
  
1. Execute on company machine A
    `proxy client -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
Complete
  
### 4.3 WeChat interface local development
Background:
- Your own notebook provides nginx service port 80
- There is a VPS, public network IP: 22.22.22.22
Demand:
Fill in the address in the webpage callback interface configuration of WeChat's development account: http://22.22.22.22/calback.php
Then you can access the calback.php under the 80 port of the notebook. If you need to bind the domain name, you can use your own domain name.
For example: wx-dev.xxx.com resolves to 22.22.22.22, and then in your own notebook nginx
Configure the domain name wx-dev.xxx.com to the specific directory.
  
Steps:
1. Execute on vps to ensure that port 80 of vps is not occupied by other programs.
    `proxy bridge -p ":33080" -C proxy.crt -K proxy.key`
    `proxy server -r ":80@:80" -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
1. Execute on your laptop
    `proxy client -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
Complete
  
### 4.4 UDP common usage
Background:
- Company Machine A provides DNS resolution service, UDP: port 53
- There is a VPS, public network IP: 22.22.22.22
  
Demand:
At home, you can use the company machine A to perform domain name resolution services by setting the local dns to 22.22.22.22.
  
Steps:
Execute on vps
    `proxy bridge -p ":33080" -C proxy.crt -K proxy.key`
    `proxy server --udp -r ":53@:53" -P "127.0.0.1:33080" -C proxy.crt -K proxy.key`
1. Execute on company machine A
    `proxy client -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
Complete
  
### 4.5 advanced usage one
Background:
- Company Machine A provides web service port 80
- There is a VPS, public network IP: 22.22.22.22
  
Demand:
In order to be safe, I don't want to have access to the company machine A on the VPS, and I can access the port 28080 of the machine at home.
Access to port 80 of company machine A via an encrypted tunnel.
  
Steps:
Execute on vps
    `proxy bridge -p ":33080" -C proxy.crt -K proxy.key`
  
1. Execute on company machine A
    `proxy client -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
  
1. Execute on your home computer
    `proxy server -r ":28080@:80" -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
  
Complete
  
### 4.6 Advanced Usage II
Tip:
If multiple clients are connected to the same bridge at the same time, you need to specify a different key, which can be set by the --k parameter, and --k can be any unique string.
Just be the only one on the same bridge.
When the server is connected to the bridge, if there are multiple clients connecting to the same bridge at the same time, you need to use the --k parameter to select the client.
Expose multiple ports by repeating the -r parameter. The format of -r is: "local IP: local port @clientHOST:client port".
  
Background:
- Company Machine A provides web service port 80, ftp service port 21
- There is a VPS, public network IP: 22.22.22.22
  
Demand:
At home, you can access the port 80 of company machine A by accessing port 28080 of the VPS.
At home, I can access the 21 port of company machine A by accessing port 29090 of the VPS.
  
Steps:
Execute on vps
    `proxy bridge -p ":33080" -C proxy.crt -K proxy.key`
    `proxy server -r ":28080@:80" -r ":29090@:21" --k test -P "127.0.0.1:33080" -C proxy.crt -K proxy.key`
1. Execute on company machine A
    `proxy client --k test -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
Complete
  
### 4.7.server -r parameter
  The full format of -r is: `PROTOCOL://LOCAL_IP:LOCAL_PORT@[CLIENT_KEY]CLIENT_LOCAL_HOST:CLIENT_LOCAL_PORT`
  
  4.7.1. Protocol PROTOCOL: tcp or udp.
  For example: `-r "udp://:10053@:53" -r "tcp://:10800@:1080" -r ":8080@:80"`
  If the --udp parameter is specified, PROTOCOL defaults to udp, then:`-r ":8080@:80"` defaults to udp;
  If the --udp parameter is not specified, PROTOCOL defaults to tcp, then: `-r ":8080@:80"` defaults to tcp;
  
  4.7.2. CLIENT_KEY: The default is default.
  For example: -r "udp://:10053@[test1]:53" -r "tcp://:10800@[test2]:1080" -r ":8080@:80"
  If the --k parameter is specified, such as --k test, then: `-r ":8080@:80"`CLIENT_KEY defaults to test;
  If the --k parameter is not specified, then: `-r ":8080@:80"`CLIENT_KEY defaults to default;
  
  4.7.3. LOCAL_IP is empty. The default is: `0.0.0.0`, CLIENT_LOCAL_HOST is empty. The default is: `127.0.0.1`;
### 4.8.server and client connect bridge through proxy
Sometimes the network where the server or client is located cannot directly access the external network. You need to use an https or socks5 proxy to access the Internet. Then this time
The -J parameter can help you to connect the server or client to the bridge via https or socks5.
The -J parameter format is as follows:
Https proxy writing:
The proxy needs authentication, username: username password: password
Https://username:password@host:port
Agent does not require authentication
Https://host:port
Socks5 proxy writing:
The proxy needs authentication, username: username password: password
Socks5://username:password@host:port
Agent does not require authentication
Socks5://host:port
Host: the IP or domain name of the proxy
Port: the port of the proxy
### 4.9. Expose HTTP service
Usually the HTTP request client will use the server's ip and port to set the HOST field, but it is not the same as the expected backend actual HOST, which causes tcp to be passed.However, the backend relies on the HOST field to locate the virtual host and it will not work. Now use the `--http-host` parameter to force the HOST field value of the http header to be the actual value of the backend.Domain names and ports can be easily solved. After using the `--http-host` parameter, two headers will be added to the header of each HTTP request. The `X-Forwarded-For` and `X-Real-IP` values are the client IP, so the backend http service can easily obtain the real IP address of the client.
The format of the `server`-http-host parameter is as follows:
`--http-host www.test.com:80@2200`, if the server listens to multiple ports, just repeat the `--http-host` parameter to set the HOST for each port.
Example:
For example, the client local nginx, 127.0.0.1:80 provides a web service, which is bound to a domain name `local.com`.
Then the server startup parameters can be as follows:
`proxy server -P :30000 -r :2500@127.0.0.1:80 --http-host local.com@2500`
Explanation:
`-r :2500@127.0.0.1:80` and `--http-host local.com:80@2500` The 2500 port is the port that the server listens locally.
When the http protocol is used to request the ip:2500 port of the server, the header HOST field of http will be set to `local.com`.
### 4.10 About traffic statistics
If you start a server docking peer separately, it is the proxy-admin control panel. You need to create a new mapping in the upper-level control panel to obtain the ID of the mapping rule.
Then start the server and add the parameter --server-id=the ID of the mapping rule to count the traffic.
### 4.11 About p2p
Intranet penetration support When the server and client network conditions are met, the server and client are directly connected through p2p. The opening method is:
When starting the bridge, server, client, add the `--p2p` parameter. The server's -r parameter can be used to enable p2p (ptcp and pudp) for the port.
If the p2p hole fails between the server and the client, the bridge transfer data is automatically switched.
### 4.12 Client key whitelist
The intranet penetrating bridge can set the client key whitelist. The parameter is --client-keys. The format can be:
a. File name, file content One client key can only contain the alphanumeric underscore, which is the value of the client startup parameter --k. Only the client key can connect to the whitelist client. The line starting with # is a comment.
b. The base64 encoding at the beginning of "base64://" is the content of the file described in a above, for example: base64://ajfpoajsdfa=
c. "str://" multiple keywords separated by a comma at the beginning, such as: str://default,company,school
The default is empty, allowing all keys.
### 4.13 Network NAT Type Judgment
Senat type judgment, easy to check whether the network supports p2p, you can execute: `proxy tools -a nattype`
### 4.14 Help
`proxy help bridge`
`proxy help server`
`proxy help client`
## 5.SOCKS5 Proxies
prompt:
SOCKS5 proxy, support CONNECT, UDP protocol, does not support BIND, supports username and password authentication.
*** If your VPS is Alibaba Cloud, Tencent Cloud is a VPS, if ifconfig can't see your public IP, you can only see the intranet IP, ***
*** Then you need to add the `-g VPS public network IP` parameter, the UDP function of the SOCKS5 proxy can work normally. ***
***The udp function of socks5 is turned off by default, and can be turned on by `--udp`. The default is a random port for handshake, and performance can be improved by fixing a port.
Set by parameter `--udp-port 0`, `0` represents a free port is randomly selected, or you can manually specify a specific port. ***
### 5.1. Ordinary SOCKS5 Agent
`proxy socks -t tcp -p "0.0.0.0:38080"`
Listen port argument `-p` can be:
```text
-p ":8081" listen on 8081
-p ":8081,:8082" listen on 8081 and 8082
-p ":8081,:8082,:9000-9999" listen on 8081 and 8082 and 9000 and 9001 to 9999, 1002 total ports
```
### 5.2. Ordinary secondary SOCKS5 agent
![5.2](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/socks-2.png)
Use local port 8090, assuming the upstream SOCKS5 proxy is `22.22.22.22:8080`
`proxy socks -t tcp -p "0.0.0.0:8090" -T tcp -P "22.22.22.22:8080" `
We can also specify the black and white list file of the website domain name, one domain name and one domain name, the matching rule is the rightmost match, for example: baidu.com, the match is *.*.baidu.com, the blacklist domain name domain name goes directly to the upstream agent, white The domain name of the list does not go to the upstream agent; if the domain name is in the blacklist and in the whitelist, the blacklist works.
`proxy socks -p "0.0.0.0:8090" -T tcp -P "22.22.22.22:8080" -b blocked.txt -d direct.txt`
  
### 5.3. SOCKS Level 2 Agent (Encryption)
![5.3](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/socks-tls-2.png)
Level 1 SOCKS proxy (VPS, IP: 22.22.22.22)
`proxy socks -t tls -p ":38080" -C proxy.crt -K proxy.key`
  
Secondary SOCKS proxy (local Linux)
`proxy socks -t tcp -p ":8080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
Then access the local port 8080 is to access the proxy port 38080 on the VPS.
  
Secondary SOCKS proxy (local windows)
`proxy.exe socks -t tcp -p ":8080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
Then set your windos system, the proxy that needs to go through the proxy Internet program is the socks5 mode, the address is: 127.0.0.1, the port is: 8080, the program can access the Internet through vps through the encrypted channel.
  
### 5.4. SOCKS Level 3 Agent (Encryption)
![5.4](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/socks-tls-3.png)
Level 1 SOCKS proxy VPS_01, IP: 22.22.22.22
`proxy socks -t tls -p ":38080" -C proxy.crt -K proxy.key`
Secondary SOCKS proxy VPS_02, IP: 33.33.33.33
`proxy socks -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
Level 3 SOCKS proxy (local)
`proxy socks -t tcp -p ":8080" -T tls -P "33.33.33.33:28080" -C proxy.crt -K proxy.key`
Then accessing the local port 8080 is to access the proxy port 38080 on the first-level SOCKS proxy.
  
### 5.5. SOCKS proxy traffic is forced to go to the upper level SOCKS proxy
By default, the proxy will intelligently determine whether a website domain name is inaccessible. If it is not accessible, it will go to the upstream SOCKS proxy. With --always, all SOCKS proxy traffic can be forced to go to the upper SOCKS proxy.
`proxy socks --always -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
  
### 5.6. SOCKS via SSH relay
![5.6](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/socks-ssh.png)
Description: The principle of ssh transfer is to use the forwarding function of ssh, that is, after you connect to ssh, you can access the target address through ssh proxy.
Suppose there is: vps
- IP is 2.2.2.2, ssh port is 22, ssh username is: user, ssh user password is: demo
- The user's ssh private key name is user.key
#### *5.6.1 How to ssh username and password*
Local SOCKS5 proxy port 28080, execute:
`proxy socks -T ssh -P "2.2.2.2:22" -u user -D demo -t tcp -p ":28080"`
#### *5.6.2 How to ssh username and key*
Local SOCKS5 proxy port 28080, execute:
`proxy socks -T ssh -P "2.2.2.2:22" -u user -S user.key -t tcp -p ":28080"`
Then access the local port 28080 is to access the target address through the VPS.
### 5.7. Certification
For the socks5 proxy protocol, we can perform username and password authentication. The authenticated username and password can be specified on the command line.
`proxy socks -t tcp -p ":33080" -a "user1:pass1" -a "user2:pass2"`
For multiple users, repeat the -a parameter.
It can also be placed in a file in the format of a "username:password" and then specified with -F.
`proxy socks -t tcp -p ":33080" -F auth-file.txt`
In addition, the socks5 agent also integrates external HTTP API authentication. We can specify an http url interface address with the --auth-url parameter.
Then when there is a user connection, the proxy will request the url in GET mode, with the following three parameters. If the HTTP status code 204 is returned, the authentication is successful.
In other cases, the authentication failed.
For example:
`proxy socks -t tcp -p ":33080" --auth-url "http://test.com/auth.php"`
When the user connects, the proxy will request the url ("http://test.com/auth.php") in GET mode.
Bring four parameters: user, pass, ip, local_ip:
Http://test.com/auth.php?user={USER}&pass={PASS}&ip={IP}&local_ip={LOCAL_IP}
User: username
Pass: password
Ip: User's IP, for example: 192.168.1.200
Local_ip: IP of the server accessed by the user, for example: 3.3.3.3
If there is no -a or -F or --auth-url parameter, the authentication is turned off.
### 5.8.KCP protocol transmission
The KCP protocol requires the --kcp-key parameter to set a password for encrypting and decrypting data.
Level 1 HTTP proxy (VPS, IP: 22.22.22.22)
`proxy socks -t kcp -p ":38080" --kcp-key mypassword`
  
Secondary HTTP proxy (local Linux)
`proxy socks -t tcp -p ":8080" -T kcp -P "22.22.22.22:38080" --kcp-key mypassword`
Then access the local port 8080 is to access the proxy port 38080 on the VPS, the data is transmitted through the kcp protocol.
notice:
When using the kcp protocol locally, you need to specify the vps public network IP with -g, and the UDP function of socks5 is fully used. At this time, -g is the IP address in the UDP address returned to the client.
### 5.9. Custom DNS
--dns-address and --dns-ttl parameters, used to specify the dns (--dns-address) used by the proxy to access the domain name.
And the analysis result cache time (--dns-ttl) seconds, to avoid system dns interference to the proxy, in addition to the cache function can also reduce the dns resolution time to improve access speed.
For example:
`proxy socks -p ":33080" --dns-address "8.8.8.8:53" --dns-ttl 300`
### 5.10 Custom Encryption
The proxy's socks proxy can encrypt tcp data through tls standard encryption and kcp protocol on top of tcp. In addition, it supports custom encryption after tls and kcp, which means that custom encryption and tls|kcp can be used together. The internal use of AES256 encryption, you only need to define a password when you use it.
Encryption is divided into two parts, one is whether the local (-z) encryption and decryption, and the other is whether the transmission with the upstream (-Z) is encrypted or decrypted.
Custom encryption requires both sides to be proxy.
The following two levels, three levels for example:
Secondary instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy socks -t tcp -z demo_password -p :7777`
Local secondary execution:
`proxy socks -T tcp -P 2.2.2.2:777 -Z demo_password -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through encrypted transmission with the upstream.
Three-level instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy socks -t tcp -z demo_password -p :7777`
Execute on the secondary vps (ip: 3.3.3.3):
`proxy socks -T tcp -P 2.2.2.2:7777 -Z demo_password -t tcp -z other_password -p :8888`
Local three-level execution:
`proxy socks -T tcp -P 3.3.3.3:8888 -Z other_password -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through encrypted transmission with the upstream.
### 5.11 Compressed transmission
The proxy's socks proxy can encrypt tcp data through custom encryption and tls standard encryption and kcp protocol on top of tcp. It can also be used before custom encryption.
Compress the data, that is, the compression function and the custom encryption and tls|kcp can be used in combination, and the compression is divided into two parts.
Part of it is local (-m) compression transmission, and part is whether the transmission with the upstream (-M) is compressed.
Compression requires both sides to be proxy, and compression also protects (encrypts) data to some extent.
The following two levels, three levels for example:
Secondary instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy socks -t tcp -m -p :7777`
Local secondary execution:
`proxy socks -T tcp -P 2.2.2.2:777 -M -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through compression with the upstream.
Three-level instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy socks -t tcp -m -p :7777`
Execute on the secondary vps (ip: 3.3.3.3):
`proxy socks -T tcp -P 2.2.2.2:7777 -M -t tcp -m -p :8888`
Local three-level execution:
`proxy socks -T tcp -P 3.3.3.3:8888 -M -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through compression with the upstream.
### 5.12 Load Balancing
The SOCKS proxy supports the upper-level load balancing, and multiple upstream repeat-P parameters can be used.
`proxy socks --lb-method=hash -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080 -p :33080 -t tcp`
### 5.12.1 Setting the retry interval and timeout time
`proxy socks --lb-method=leastconn --lb-retrytime 300 --lb-timeout 300 -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080 -p :33080 -t tcp`
### 5.12.2 Setting weights
`proxy socks --lb-method=weight -T tcp -P 1.1.1.1:33080?w=1 -P 2.1.1.1:33080?w=2 -P 3.1.1.1:33080?w=1 -p :33080 -t tcp`
### 5.12.3 Use the target address to select the upstream
`proxy socks --lb-hashtarget --lb-method=hash -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080 -p :33080 -t tcp`
### 5.13 Speed limit
The speed limit is 100K, which can be specified by the `-l` parameter, for example: 100K 2000K 1M . 0 means no limit.
`proxy socks -t tcp -p 2.2.2.2:33080 -l 100K`
### 5.14 Specifying Outgoing IP
The `--bind-listen` parameter can be used to open the client connection with the portal IP, and use the portal IP as the outgoing IP to access the target website. If the ingress IP is an intranet IP, the egress IP does not use the ingress IP.
`proxy socks -t tcp -p 2.2.2.2:33080 --bind-listen`
### 5.15 Cascade Certification
SOCKS5 supports cascading authentication, and -A can set upstream authentication information.
upstream:
`proxy socks -t tcp -p 2.2.2.2:33080 -a user:pass`
local:
`proxy socks -T tcp -P 2.2.2.2:33080 -A user:pass -t tcp -p :33080`
### 5.16 Certificate parameters use base64 data
By default, the -C, -K parameter is the path to the crt certificate and the key file.
If it is the beginning of base64://, then the latter data is considered to be base64 encoded and will be used after decoding.
### 5.17 Intelligent mode
Intelligent mode setting, can be one of intelligent|direct|parent.
The default is: intelligent.
The meaning of each value is as follows:
`--intelligent=direct`, the targets in the blocked are not directly connected.
`--intelligent=parent`, the target that is not in the direct is going to the higher level.
`--intelligent=intelligent`, blocked and direct have no targets, intelligently determine whether to use the upstream access target.
### 5.18 Fixed UDP PORT
By default, the port number of the UDP function of socks5, the proxy is installed in the `rfc1982 draft` request, which is randomly specified during the protocol handshake process and does not need to be specified in advance.
However, in some cases, you need to fix the UDP function port. You can use the parameter `--udp-port port number` to fix the port number of the UDP function. For example:
`proxy socks -t tcp -p "0.0.0.0:38080" --udp-port 38080`
### 5.19 Help
`proxy help socks`
## 6.SPS Protocol Convert
### 6.1 Function introduction
The proxy protocol conversion uses the sps subcommand. The sps itself does not provide the proxy function. It only accepts the proxy request to "convert and forward" to the existing http(s) proxy or the socks5 proxy or ss proxy; the sps can put the existing http(s) proxy or socks5 proxy or ss proxy is converted to a port that supports both http(s) and socks5 and ss proxies, and the http(s) proxy supports forward proxy and reverse proxy (SNI), converted SOCKS5 proxy, UDP function is still supported when the upper level is SOCKS5 or SS; in addition, for the existing http(s) proxy or socks5 proxy, three modes of tls, tcp, and kcp are supported, and chain connection is supported, that is, multiple sps node levels can be supported. The connection builds an encrypted channel.
The encryption methods supported by the `ss` function are: aes-128-cfb, aes-128-ctr, aes-128-gcm, aes-192-cfb, aes-192-ctr, aes-192-gcm, aes-256- Cfb , aes-256-ctr , aes-256-gcm , bf-cfb , cast5-cfb , chacha20 , chacha20-ietf , chacha20-ietf-poly1305 , des-cfb , rc4-md5 , rc4-md5-6 , salsa20 , Xchacha20
Listen port argument `-p` can be:
```text
-p ":8081" listen on 8081
-p ":8081,:8082" listen on 8081 and 8082
-p ":8081,:8082,:9000-9999" listen on 8081 and 8082 and 9000 and 9001 to 9999, 1002 total ports
```
notice:
When using the kcp protocol locally, you need to specify the vps public network IP with -g, and the UDP function of socks5 is fully used. At this time, -g is the IP address in the UDP address returned to the client.
The udp function of ss is turned off by default and can be turned on by `--ssudp`. The udp function of socks5 is turned off by default and can be turned on by `--udp`, The default is a random port for handshake, and performance can be improved by fixing a port.
Set by parameter `--udp-port 0`, `0` represents a free port is randomly selected, or you can manually specify a specific port.
### 6.2 HTTP(S) to HTTP(S)+SOCKS5+SS
Suppose there is already a normal http(s) proxy: 127.0.0.1:8080. Now we turn it into a common proxy that supports both http(s) and socks5 and ss. The converted local port is 18080, ss encryption: Aes-192-cfb, ss password: pass.
The command is as follows:
`proxy sps -S http -T tcp -P 127.0.0.1:8080 -t tcp -p :18080 -h aes-192-cfb -j pass`
Suppose there is already a tls http(s) proxy: 127.0.0.1:8080. Now we turn it into a normal proxy that supports both http(s) and socks5 and ss. The converted local port is 18080, and tls requires a certificate file. , ss encryption: aes-192-cfb, ss password: pass.
The command is as follows:
`proxy sps -S http -T tls -P 127.0.0.1:8080 -t tcp -p :18080 -C proxy.crt -K proxy.key -h aes-192-cfb -j pass`
Suppose there is already a kcp http(s) proxy (password is: demo123): 127.0.0.1:8080, now we turn it into a normal proxy that supports both http(s) and socks5 and ss. The converted local port is 18080, ss encryption: aes-192-cfb, ss password: pass.
The command is as follows:
`proxy sps -S http -T kcp -P 127.0.0.1:8080 -t tcp -p :18080 --kcp-key demo123 -h aes-192-cfb -j pass`
### 6.3 SOCKS5 to HTTP(S)+SOCKS5+SS
Suppose there is already a normal socks5 proxy: 127.0.0.1:8080, now we turn it into a common proxy that supports both http(s) and socks5 and ss. The converted local port is 18080, ss encryption: aes-192 -cfb, ss password: pass.
The command is as follows:
`proxy sps -S socks -T tcp -P 127.0.0.1:8080 -t tcp -p :18080 -h aes-192-cfb -j pass`
Suppose there is already a tls socks5 proxy: 127.0.0.1:8080, now we turn it into a common proxy that supports both http(s) and socks5 and ss. The converted local port is 18080, tls requires certificate file, ss encryption Mode: aes-192-cfb, ss password: pass.
The command is as follows:
`proxy sps -S socks -T tls -P 127.0.0.1:8080 -t tcp -p :18080 -C proxy.crt -K proxy.key -h aes-192-cfb -j pass`
Suppose there is already a kcp socks5 proxy (password: demo123): 127.0.0.1:8080, now we turn it into a common proxy that supports both http(s) and socks5 and ss. The converted local port is 18080, ss Encryption method: aes-192-cfb, ss password: pass.
The command is as follows:
`proxy sps -S socks -T kcp -P 127.0.0.1:8080 -t tcp -p :18080 --kcp-key demo123 -h aes-192-cfb -j pass`
### 6.4 SS to HTTP(S)+SOCKS5+SS
SPS upstream and local support ss protocol, the upstream can be SPS or standard ss service.
SPS locally provides HTTP(S)\SOCKS5\SPS three defaults. When the upstream is SOCKS5, the converted SOCKS5 and SS support UDP.
Suppose there is already a normal SS or SPS proxy (ss is enabled, encryption: aes-256-cfb, password: demo): 127.0.0.1:8080, now we turn it to support both http(s) and socks5 and The ordinary proxy of ss, the converted local port is 18080, the converted ss encryption mode: aes-192-cfb, ss password: pass.
The command is as follows:
`proxy sps -S ss -H aes-256-cfb -J pass -T tcp -P 127.0.0.1:8080 -t tcp -p :18080 -h aes-192-cfb -j pass`.
### 6.5 Chained connection
![6.4](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/sps-tls.png)
The above mentioned multiple sps nodes can be connected to build encrypted channels in a hierarchical connection, assuming the following vps and the home PC.
Vps01:2.2.2.2
Vps02:3.3.3.3
Now we want to use pc and vps01 and vps02 to build an encrypted channel. This example uses tls encryption or kcp. Accessing local 18080 port on the PC is to access the local 8080 port of vps01.
First on vps01 (2.2.2.2) we run a locally accessible http(s) proxy and execute:
`proxy http -t tcp -p 127.0.0.1:8080`
Then run a sps node on vps01 (2.2.2.2) and execute:
`proxy sps -S http -T tcp -P 127.0.0.1:8080 -t tls -p :8081 -C proxy.crt -K proxy.key`
Then run a sps node on vps02 (3.3.3.3) and execute:
`proxy sps -S http -T tls -P 2.2.2.2:8081 -t tls -p :8082 -C proxy.crt -K proxy.key`
Then run a sps node on the pc and execute:
`proxy sps -S http -T tls -P 3.3.3.3:8082 -t tcp -p :18080 -C proxy.crt -K proxy.key`
carry out.
### 6.6 Authentication
Sps supports http(s)\socks5 proxy authentication, which can be cascaded and has four important pieces of information:
1: The user sends the authentication information `user-auth`.
2: Set the local authentication information `local-auth`.
3: Set the connection authentication information 'parent-auth` used by the upstream.
4: The authentication information `auth-info-to-parent` that is finally sent to the upstream.
Their situation is as follows:
User-auth | local-auth | parent-auth | auth-info-to-paren
| ------ | ------ | ------ | ------
| Yes / No | Yes | Yes | From parent-auth
| Yes / No | No | Yes | From parent-auth
| Yes / No | Yes | No | No
| No | No | No | No
| Yes | No | No | From user-auth
For the sps proxy we can perform username and password authentication. The authenticated username and password can be specified on the command line.
`proxy sps -S http -T tcp -P 127.0.0.1:8080 -t tcp -p ":33080" -a "user1:pass1:0:0:" -a "user2:pass2:0:0: "`
For multiple users, repeat the -a parameter.
Can also be placed in a file, the format is one line a `username: password: number of connections: rate: upstream`, and then specified with -F.
`proxy sps -S http -T tcp -P 127.0.0.1:8080 -t tcp -p ":33080" -F auth-file.txt`
If the upstream has authentication, the lower level can set the authentication information with the -A parameter, for example:
upstream: `proxy sps -S http -T tcp -P 127.0.0.1:8080 -t tcp -p ":33080" -a "user1:pass1:0:0:" -a "user2:pass2:0: 0:"`
Subordinate: `proxy sps -S http -T tcp -P 127.0.0.1:8080 -A "user1:pass1" -t tcp -p ":33080" `
For more details on certification, please refer to `9.API Certification` and `10.Local Certification`
### 6.7 Multiple Upstream
If there are multiple upstreams, they can be specified by multiple -Ps.
such as:
`proxy sps -P http://127.0.0.1:3100 -P socks5://127.0.0.1:3200`
The complete format of `-P` is as follows:
 `protocol://a:[email protected]:33080#1`
Each section is explained below:
`protocol://` is the protocol type, possible types and contains the following:
```text
Http is equivalent to -S http -T tcp
Https is equivalent to -S http -T tls --parent-tls-single , which is http(s) proxy over TLS
Https2 is equivalent to -S http -T tls
Socks5 is equivalent to -S socks -T tcp
Socks5s is equivalent to -S socks -T tls --parent-tls-single , which is socks over TLS
Socks5s2 is equivalent to -S socks -T tls
Ss is equivalent to -S ss -T tcp
Httpws is equivalent to -S http -T ws
Httpwss is equivalent to -S http -T wss
Socks5ws is equivalent to -S socks -T ws
Socks5wss is equivalent to -S socks -T wss
```
`a:b` is the username and password of the proxy authentication. If it is ss, `a` is the encryption method, `b` is the password, and no username password can be left blank, for example: `http://2.2.2.2:33080` If the username and password are protected, special symbols can be encoded using urlencode.
`2.2.2.2:33080` is the upstream address, the format is: `IP (or domain name): port `, if the underlying is ws/wss protocol can also bring the path, such as: `2.2.2.2: 33080/ws`;
You can also set the `encryption method` and `password` of `ws\wss` by appending the query parameters `m` and `k`, for example: `2.2.2.2:33080/ws?m=aes-192-cfb&k=password`
`#1` When multiple upper-level load balancing is a weighting strategy, the weights are rarely used.
### 6.8 Custom Encryption
The proxy sps proxy can encrypt tcp data through tls standard encryption and kcp protocol on top of tcp, in addition to support after tls and kcp
Custom encryption, that is, custom encryption and tls|kcp can be used in combination, internally using AES256 encryption, only need to define it when using
A password can be used, the encryption is divided into two parts, one part is whether the local (-z) encryption and decryption, and the part is the encryption and decryption with the upstream (-Z) transmission.
Custom encryption requires both sides to be proxy.
The following two levels, three levels for example:
Suppose there is already an http(s) proxy: `6.6.6.6:6666`
Secondary instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy sps -S http -T tcp -P 6.6.6.6:6666 -t tcp -z demo_password -p :7777`
Local secondary execution:
`proxy sps -T tcp -P 2.2.2.2:777 -Z demo_password -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through encrypted transmission with the upstream.
Three-level instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy sps -S http -T tcp -P 6.6.6.6:6666 -t tcp -z demo_password -p :7777`
Execute on the secondary vps (ip: 3.3.3.3):
`proxy sps -T tcp -P 2.2.2.2:7777 -Z demo_password -t tcp -z other_password -p :8888`
Local three-level execution:
`proxy sps -T tcp -P 3.3.3.3:8888 -Z other_password -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through encrypted transmission with the upstream.
### 6.9 Compressed transmission
The proxy sps proxy can encrypt tcp data through custom encryption and tls standard encryption and kcp protocol on top of tcp. It can also be used before custom encryption.
Compress the data, that is, the compression function and the custom encryption and tls|kcp can be used in combination, and the compression is divided into two parts.
Part of it is local (-m) compression transmission, and part is whether the transmission with the upstream (-M) is compressed.
Compression requires both sides to be proxy, and compression also protects (encrypts) data to some extent.
The following two levels, three levels for example:
Secondary instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy sps -t tcp -m -p :7777`
Local secondary execution:
`proxy sps -T tcp -P 2.2.2.2:777 -M -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through compression with the upstream.
Three-level instance
Execute on level 1 vps (ip: 2.2.2.2):
`proxy sps -t tcp -m -p :7777`
Execute on the secondary vps (ip: 3.3.3.3):
`proxy sps -T tcp -P 2.2.2.2:7777 -M -t tcp -m -p :8888`
Local three-level execution:
`proxy sps -T tcp -P 3.3.3.3:8888 -M -t tcp -p :8080`
In this way, when the website is accessed through the local agent 8080, the target website is accessed through compression with the upstream.
### 6.10 Disabling the protocol
By default, SPS supports http(s) and socks5 two proxy protocols. We can disable a protocol by parameter.
For example:
1. Disable the HTTP(S) proxy function to retain only the SOCKS5 proxy function, parameter: `--disable-http`.
`proxy sps -T tcp -P 3.3.3.3:8888 -M -t tcp -p :8080 --disable-http`
1. Disable the SOCKS5 proxy function to retain only the HTTP(S) proxy function, parameter: `--disable-socks`.
`proxy sps -T tcp -P 3.3.3.3:8888 -M -t tcp -p :8080 --disable-socks`
### 6.11 Speed limit
Suppose there is a SOCKS5 upstream:
`proxy socks -p 2.2.2.2:33080 -z password -t tcp`
SPS lower level, speed limit 100K
`proxy sps -S socks -P 2.2.2.2:33080 -T tcp -Z password -l 100K -t tcp -p :33080`
It can be specified by the `-l` parameter, for example: 100K 2000K 1M . 0 means no limit.
### 6.12 Specifying Outgoing IP
The `--bind-listen` parameter can be used to open the client connection with the portal IP, and use the portal IP as the outgoing IP to access the target website. If the ingress IP is an intranet IP, the egress IP does not use the ingress IP.
`proxy sps -S socks -P 2.2.2.2:33080 -T tcp -Z password -l 100K -t tcp --bind-listen -p :33080`
### 6.13 Certificate parameters use base64 data
By default, the -C, -K parameter is the path to the crt certificate and the key file.
If it is the beginning of base64://, then the latter data is considered to be base64 encoded and will be used after decoding.
### 6.14 Independent Service
A sps port can complete the full-featured proxy `http\socks\ss` function.
The following command is to open the http(s)\ss\socks service with one click, and enable the udp of socks5 and the udp of ss at the same time.
`proxy sps -p: 33080 --ssudp --udp --udp-port 0`
### 6.15 Target Redirection
The https(s)\socks5\ss proxy function provided by the sps function, the client connects to the specified "target" through the sps proxy. This "target" is generally a website or an arbitrary tcp address.
The website "target" is generally foo.com: 80, foo.com: 443, sps supports the use of the --rewrite parameter to specify a "target" redirection rule file, redirect the target, the client is non-perceived,
For example, if you redirect to "target": demo.com:80 to 192.168.0.12:80, then the client visits the website demo.com, in fact, the website service provided by 192.168.0.12.
Example of a "target" redirection rule file:
```text
# example
Www.a.com:80 10.0.0.2:8080
**.b.com:80 10.0.0.2:80
192.168.0.11:80 10.0.0.2:8080
```
When sps is an independent service, an additional local socks5 service will be opened to occupy a random port. Now the parameter `--self-port` can be manually specified when needed. The default is 0 to use random.
### 6.16 Fixed UDP PORT
By default, the port number of the UDP function of ss's socks5 is specified by the `rfc1982 draft`. It is randomly specified during the protocol handshake process and does not need to be specified in advance.
However, in some cases, you need to fix the UDP function port. You can fix the port number of the UDP function by the parameter `--udp-port port_number`, for example:
`proxy sps -t tcp -p "0.0.0.0:38080" --udp-port 38081`
It should be noted that the ss function of sps also has UDP function, and the UDP port of ss is the same as the tcp port, so avoid the conflict between the UDP port of socks5 and the UDP port of ss.
To specify a port that is different from the tcp port.
### 6.17 iptables 透明代理
The sps mode supports the iptables transparent forwarding support of the Linux system, which is commonly referred to as the iptables transparent proxy. If a iptables transparent proxy is performed on the gateway device, the device that is connected through the gateway can realize a non-aware proxy.
Example start command:
`proxy sps --redir -p :8888 -P httpws: //1.1.1.1:33080`
Here it is assumed that there is an http superior proxy 1.1.1.1:33080, which uses ws to transmit data.
Then add iptables rules, here are the reference rules:
```shell
#upstream proxy server IP address:
proxy_server_ip = 1.1.1.1
#Router running proxy listening port:
proxy_local_port = 33080
#There is no need to modify the following
#create a new chain named PROXY
iptables -t nat -N PROXY
#Ignore your PROXY server's addresses
#It's very IMPORTANT just be careful。
iptables -t nat -A PROXY -d $proxy_server_ip -j RETURN
#Ignore LANs IP address
iptables -t nat -A PROXY -d 0.0.0.0/8 -j RETURN
iptables -t nat -A PROXY -d 10.0.0.0/8 -j RETURN
iptables -t nat -A PROXY -d 127.0.0.0/8 -j RETURN
iptables -t nat -A PROXY -d 169.254.0.0/16 -j RETURN
iptables -t nat -A PROXY -d 172.16.0.0/12 -j RETURN
iptables -t nat -A PROXY -d 192.168.0.0/16 -j RETURN
iptables -t nat -A PROXY -d 224.0.0.0/4 -j RETURN
iptables -t nat -A PROXY -d 240.0.0.0/4 -j RETURN
#Anything to port 80 443 should be redirected to PROXY's local port
iptables -t nat -A PROXY -p tcp -j REDIRECT --to-ports $proxy_local_port
#Apply the rules to nat client
iptables -t nat -A PREROUTING -p tcp -j PROXY
#Apply the rules to localhost
iptables -t nat -A OUTPUT -p tcp -j PROXY
```
- Clear the entire chain iptables -F chain name such as iptables -t nat -F PROXY
- Delete the specified user-defined chain iptables -X chain name e.g. iptables -t nat -X PROXY
- Delete rule from selected chain iptables -D chain name rule details e.g. iptables -t nat -D PROXY -d 223.223.192.0/255.255.240.0 -j RETURN
### 6.18 Help
`proxy help sps`
## 7.KCP Configuration
### 7.1 Configuration Introduction
Many functions of the proxy support the kcp protocol. Any function that uses the kcp protocol supports the configuration parameters described here.
Therefore, the KCP configuration parameters are introduced here.
### 7.2 Detailed configuration
There are a total of 17 KCP configuration parameters, you can not set them, they have default values, if for the best effect,
You need to configure the parameters according to your own network conditions. Because the kcp configuration is complex, it requires a certain network basics.
If you want to get more detailed configuration and explanation of kcp parameters, please search for yourself. The command line name for each parameter, along with the default values and simple function descriptions are as follows:
```
--kcp-key="secrect" pre-shared secret between client and server
--kcp-method="aes" encrypt/decrypt method, can be: aes, aes-128, aes-192, salsa20, blowfish,
                           Twofish, cast5, 3des, tea, xtea, xor, sm4, none
--kcp-mode="fast" profiles: fast3, fast2, fast, normal, manual
--kcp-mtu=1350 set maximum transmission unit for UDP packets
--kcp-sndwnd=1024 set send window size(num of packets)
--kcp-rcvwnd=1024 set receive window size(num of packets)
--kcp-ds=10 set reed-solomon erasure coding - datashard
--kcp-ps=3 set reed-solomon erasure coding - parityshard
--kcp-dscp=0 set DSCP(6bit)
--kcp-nocomp disable compression
--kcp-acknodelay be carefull! flush ack immediately when a packet is received
--kcp-nodelay=0 be carefull!
--kcp-interval=50 be carefull!
--kcp-resend=0 be carefull!
--kcp-nc=0 be carefull! no congestion
--kcp-sockbuf=4194304 be carefull!
--kcp-keepalive=10 be carefull!
```
Tip:
Parameters: -- four fast3, fast2, fast, normal modes in kcp-mode,
Equivalent to setting the following four parameters:
Normal:`--nodelay=0 --interval=40 --resend=2 --nc=1`
Fast :`--nodelay=0 --interval=30 --resend=2 --nc=1`
Fast2:`--nodelay=1 --interval=20 --resend=2 --nc=1`
Fast3:`--nodelay=1 --interval=10 --resend=2 --nc=1`
## 8. Security DNS
### 8.1 Introduction
DNS is known as the service provided by UDP port 53, but with the development of the network, some well-known DNS servers also support TCP mode dns query, such as Google's 8.8.8.8, the DNS anti-pollution server principle of the proxy is to start a proxy DNS proxy locally. Server, which uses TCP to perform dns query through the upstream agent. If it communicates with the upstream agent, it can perform secure and pollution-free DNS resolution. It also supports independent services, concurrent parsing, and enhanced enhanced hosts file function to support flexible concurrent parsing and forwarding.
Dns resolution order:
1. Use the parameter --hosts to parse.
2. If the domain name to be resolved is not found in 1, it is parsed using the parameter --forward rule.
3. The domain name to be resolved is not found in 1 and 2, and the default --default parsing is used. The default default behavior parameter values are three: proxy, direct, and system.
    The three parameter values are explained as follows:
    Proxy: The domain name is resolved by the dns server specified by the -q parameter.
    Direct: Connect to the dns server specified by the -q parameter to resolve the domain name through the local network.
    System: resolves the domain name through the system dns.
Tip:
The host file format specified by the --hosts parameter is the same as the system hosts file, and the domain name supports wildcards. You can refer to the hosts file.
The parsing forwarding rule file specified by the --forward parameter can be referenced to the resolve.rules file. The domain name supports wildcards. It supports multiple dns servers for each domain name to be parsed concurrently. Whoever resolves the fastest resolution will use the resolution result.
The -q parameter can specify multiple remote dns servers to perform concurrent parsing. Whoever resolves the fastest parsing success, the default is: 1.1.1.1, 8.8.8.8, 9.9.9.9, multiple comma-separated,
           For example, you can also bring ports: 1.1.1.1, 8.8.8.8#53, 9.9.9.9
If you are a standalone service, you don't need a upstream:
Can perform:
`proxy dns --default system -p :5353`
Or
`proxy dns --default direct -p :5353`
### 8.2 Example of use
#### 8.2.1 Normal HTTP(S) upstream agent
Suppose there is a upstream agent: 2.2.2.2:33080
Local execution:
`proxy dns -S http -T tcp -P 2.2.2.2:33080 -p :53`
Then the local UDP port 53 provides DNS resolution.
#### 8.2.2 Ordinary SOCKS5 upstream agent
Suppose there is a upstream agent: 2.2.2.2:33080
Local execution:
`proxy dns -S socks -T tcp -P 2.2.2.2:33080 -p :53`
Then the local UDP port 53 provides DNS resolution.
#### 8.2.3 TLS encrypted HTTP(S) upstream agent
Suppose there is a upstream agent: 2.2.2.2:33080
The commands executed by the upstream agent are:
`proxy http -t tls -C proxy.crt -K proxy.key -p :33080`
Local execution:
`proxy dns -S http -T tls -P 2.2.2.2:33080 -C proxy.crt -K proxy.key -p :53`
Then the local UDP port 53 provides a secure anti-pollution DNS resolution function.
#### 8.2.4 TLS-encrypted SOCKS5 upstream agent
Suppose there is a upstream agent: 2.2.2.2:33080
The commands executed by the upstream agent are:
`proxy socks -t tls -C proxy.crt -K proxy.key -p :33080`
Local execution:
`proxy dns -S socks -T tls -P 2.2.2.2:33080 -C proxy.crt -K proxy.key -p :53`
Then the local UDP port 53 provides a secure anti-pollution DNS resolution function.
#### 8.2.5 KCP encrypted HTTP(S) upstream agent
Suppose there is a upstream agent: 2.2.2.2:33080
The commands executed by the upstream agent are:
`proxy http -t kcp -p :33080`
Local execution:
`proxy dns -S http -T kcp -P 2.2.2.2:33080 -p :53`
Then the local UDP port 53 provides a secure anti-pollution DNS resolution function.
#### 8.2.6 KCP encrypted SOCKS5 upstream agent
Suppose there is a upstream agent: 2.2.2.2:33080
The commands executed by the upstream agent are:
`proxy socks -t kcp -p :33080`
Local execution:
`proxy dns -S socks -T kcp -P 2.2.2.2:33080 -p :53`
Then the local UDP port 53 provides a secure anti-pollution DNS resolution function.
#### 8.2.7 Custom encrypted HTTP(S) upstream agent
Suppose there is a upstream agent: 2.2.2.2:33080
The commands executed by the upstream agent are:
`proxy http -t tcp -p :33080 -z password`
Local execution:
`proxy dns -S http -T tcp -Z password -P 2.2.2.2:33080 -p :53`
Then the local UDP port 53 provides a secure anti-pollution DNS resolution function.
#### 8.2.8 Custom encrypted SOCKS5 upstream agent
 
Suppose there is a upstream agent: 2.2.2.2:33080
The commands executed by the upstream agent are:
`proxy socks -t kcp -p :33080 -z password`
Local execution:
`proxy dns -S socks -T tcp -Z password -P 2.2.2.2:33080 -p :53`
Then the local UDP port 53 provides a secure anti-pollution DNS resolution function.
## 9.API Authentication
The proxy's http(s)/socks5/sps proxy function supports user-to-agent access via the API.
### What can I do through the API?
- User dimension, which controls the single connection rate and controls the maximum number of connections.
- IP dimension, which controls the single connection rate and controls the maximum number of connections.
- Dynamic upstream, can dynamically obtain its upstream from the API according to the user or client IP, and support http(s)/socks5/ss upstream.
- Authenticate every connection, regardless of whether client authentication is required.
- Cache authentication results, time can be set to reduce API pressure.
#### Specific use
The proxy's http(s)/socks5/sps proxy API function is controlled by three parameters: `--auth-url` and `--auth-nouser` and `--auth-cache`.
The parameter `--auth-url` is the HTTP API interface address. When the client connects, the proxy will request the url in GET mode, with the following parameters. If the HTTP status code 204 is returned, the authentication is successful. In other cases, the authentication fails.
An example of a complete request API:
`http://test.com/auth.php?user=a&pass=b&client_addr=127.0.0.1:49892&local_addr=127.0.0.1:8100&target=http%3A%2F%2Fwww.baidu.com&service=http&sps=0`
#### Parameter Description
`user and pass` When the proxy turns on authentication, here is the username and password provided by the client.
`client_addr` The address used by the client to access the proxy, format IP: port.
`local_addr` The proxy address accessed by the client, format IP: port.
`service` Proxy type, divided into: http, socks.
Whether the `sps` proxy is provided by sps, 1: yes, 0: no.
`target` The target to be accessed by the client. If it is an http(s) proxy, the target is the specific url accessed; if it is a socks5 proxy, the target is empty.
#### Example
Suppose --auth-url http://127.0.0.1:333/auth.php points to a php interface address.
The contents of auth.php are as follows:
```php
<?php
#all users and password
$alluser=[
"user1"=>"pass1",
"user2"=>"pass2",
"user3"=>"pass3",
"user4"=>"pass4",
];
$proxy_ip=$_GET['local_addr'];
$user_ip=$_GET['client_addr'];
$service=$_GET['service'];
$is_sps=$_GET['sps']=='1';
$user=$_GET['user'];
$pass=$_GET['pass'];
$target=$_GET['target'];
//business checking
//....
$ok=false;
foreach ($alluser as $dbuser => $dbpass) {
if ($user==$dbuser&&$pass==$dbpass){
$ok=true;
break;
}
}
//set the authentication result
if($ok){
header("userconns:1000");
header("ipconns:2000");
header("userrate:3000");
header("iprate:8000");
header("UPSTREAM:http://127.0.0.1:3500?parent-type=tcp");
header("HTTP/1.1 204 No Content");
}
```
#### Explanation
Userconns: The maximum number of connections for the user, not limited to 0 or not set this header.
Ipcons: The maximum number of connections for the user IP, not limited to 0 or not set this header.
Userrate: User's single TCP connection rate limit, in bytes/second, is not limited to 0 or does not set this header.
Iprate: The single TCP connection rate limit of the user IP, in bytes/second, not limited to 0 or not set this header.
Upstream: The upstream used, not empty, or not set this header.
#### Tips
1. By default, `--auth-url` is required to provide the user name and password. If you do not need the client to provide the username and password, and authenticate, you can add `--auth-nouser`. The visit will still access the authentication address `--auth-url` for authentication. Only the $user authentication username and the $pass authentication password received in the php interface are empty when client didn't send username and password.
2. Connection limit priority: User authentication file limit - "File ip.limit limit -" API user limit - "API IP limit -" command line global connection limit.
3. Rate Limit Priority: User Authentication File Rate Limit - "File ip.limit Rate Limit -" API User Rate Limit - "API IP Rate Limit - "Command Line Global Rate Limit.
3. The upstream obtains the priority: the upstream of the user authentication file - the file ip.limit upstream-"API upstream-" command line specifies the upstream.
4.`--auth-cache` authentication cache, cache the authentication result for a certain period of time, improve performance, reduce the pressure on the authentication interface, --auth-cache unit seconds, default 0, set 0 to close the cache.
#### upstream detailed description
1. When the parameter `sps` is 0.
When the service is http, upstream only supports http(s) proxy, and does not support authentication. If authentication is required, it can be replaced by sps. Format:
  `http://127.0.0.1:3100?argk=argv`
When the service is a socks, the upstream only supports the socks5 proxy. The format is:
  `socks5://127.0.0.1:3100?argk=argv`
Explanation: `http://`,`socks5://` is fixed, `127.0.0.1:3100` is the address of the upstream
2. When `sps` is 1.
Upstream supports socks5, http(s) proxy, support authentication, format: `protocol://a:b@2.2.2.2:33080?argk=argv`, please refer to SPS chapter for details, **multiple upstreams** , the description of the `-P` parameter.
3. Parameters, `?` followed by `argk=argv` are parameters: parameter name = parameter value, multiple parameters are connected with `&`.
  All the supported parameters are as follows, and the meaning of the command line with the same name is the same.
  1. parent-type : upper-level transport type, support tcp, tls, ws, wss
  2. parent-ws-method: The encryption method of the upper-level ws transmission type, the supported value is the same as the value range supported by the command line.
  3. parent-ws-password: The upper-level ws transmission type encryption password, the alphanumeric password
  4. parent-tls-single : Whether the upper-level tls transport type is a one-way tls, which can be: true | false
  5. timeout : timeout for establishing tcp connection, number, in milliseconds
  6. ca : The base64-encoded string of the upper-level tls transport type ca certificate file.
  7. cert : The base64 encoded string of the higher level tls transport type certificate file.
  8. key : The base64 encoded string of the higher-level tls transport type certificate key file.
### Traffic report / Traffic limit / Traffic statistics
The proxy's http (s) / socks5 / sps / tcp / udp proxy function supports traffic reporting. You can set an http interface address through the parameter `--traffic-url`.
The proxy will report the traffic used for this connection to this address.Specifically, the proxy sends an HTTP to GET request to the HTTP URL address set by `--traffic-url`.
There are two reporting modes, which can be specified by the `--traffic-mode` parameter. It can be reported in the normal mode or in the fast mode.
1. Report in `normal` normal mode
When the connection is released, the proxy will report the traffic used for this connection to this `--traffic-url` address.
2. Report in `fast` mode
For each connection that has been established, the proxy will `timely` report the traffic generated by this connection to this` --traffic-url` address.
`Timing` defaults to 5 seconds, and you can modify` Timing` to the appropriate number of seconds via the parameter `--traffic-interval`.
The traffic reporting function combined with the above API authentication function can control the user's traffic usage in real time. The traffic is reported to the interface. The interface writes the traffic data to the database, and then the authentication API queries the database to determine the traffic usage and determine whether the user can be successfully authenticated.
The following is a complete URL request example:
`http://127.0.0.1:33088/user/traffic?bytes=337&client_addr=127.0.0.1%3A51035&id=http&server_addr =127.0.0.1%3A33088&target_addr=myip.ipip.net%3A80&username=a`
Request parameter description:
id: service id flag.
server_addr: proxies's address requested by the client, format: IP: port.
client_addr: client address, format: IP: port.
target_addr: target address, format: "IP: port", when tcp / udp proxy, this is empty.
User name: proxy authentication user name, this is empty when tcp / udp proxy.
bytes: the number of traffic bytes used by the user.
#### Tips
The `--traffic-url` URL must response the HTTP status code` 204`. Only when the traffic is reported will the report be considered successful, and if it response other status codes, it will be considered that the reported traffic failed, and the log will be output.
#### traffic flow
![traffic](https://raw.githubusercontent.com/snail007/goproxy/master/doc/images/traffic.png)
### Disconnect the user's connection
The proxy's http (s) / socks5 / sps proxy function supports a control interface, which can be specified by the parameter --control-url http interface address,
Then the proxy will interval send all the usernames or client IPs currently connected to the proxy to this URL. Specifically, the proxy sends an HTTP to POST request to the HTTP URL address set by --control-url.
`interval` defaults to 30 seconds, this value can be modified via the --control-sleep parameter.
When the user expires, or the user's traffic has been used up, the authentication API can only control the user cannot create a new connection, but the connection with the proxy has been established and the connection cannot be immediately disconnected.
Then this problem can be solved through the control interface. The control interface will return the content through the control interface in the slowest `interval` time, and the end is invalid when the user establishes the connection.
#### Request Description
The proxy sends an HTTP POST request to the control interface URL. There are two fields in the form data: user and ip.
user: the user name currently connected to the proxy, multiple are separated by commas, for example: user1, user2
ip: The IP address of the client currently connected to the proxy, multiple are separated by commas, for example: 1.1.1.1, 2.2.2.2
#### Response Data Description
The data returned by the control interface is invalid user and IP, the format is a json object data, there are two fields user and ip.
For example: {"user": "a, b", "ip": ""}
user: the user name currently connected to the proxy, multiple are separated by commas, not left blank, for example: user1, user2
ip: The ip address of the client currently connected to the proxy. Multiple are separated by commas and not left blank.
The connection between the returned user and ip will be disconnected by proxy.
#### Example
Suppose --control-url `http://127.0.0.1:33088/user/control.php` points to a PHP interface address.
The content of control.php is as follows:
```php
<?php
#revcieve proxy post data
$userArr=explode(",",$_POST['user']);
$ipArr=$_GET['ip'];
//invalid users array
$badUsers=[];
foreach ($userArr as $user) {
//logic business, push invalid user into $badUsers
$badUsers[]=$user;
}
$data=["user"=>implode(","$badUsers),"ip"=>""];
echo json_encode($data);
```
## 10. Authentication
The proxy http(s)/socks5/sps proxy function supports the user to access the proxy pair through the configuration file, and supports the http(s) proxy ``Proxy Basic proxy authentication` and the socks5 proxy authentication.
### start using
The proxy's http(s)/socks5/sps proxy function can pass
`--auth-file`, `--max-conns`, `--ip-limit`, `--rate-limit`, `-a` These five parameters control.
#### Detailed explanation of parameters
##### `--auth-file`
The authenticated user name and password file. This parameter specifies a file, one line per rule, in the format: "username: password: number of connections: rate: upstream".
`Connection number` is the maximum number of connections for the user. The 'rate' is the maximum speed of each tcp connection of the user. The unit is: byte/second. The upper level is the upper level used by the user.
Not only can the authenticated user be set by `--auth-file`, but also the `-a` parameter can be set directly. Multiple users can repeat multiple `-a` parameters.
For example: `proxy http -a a:b:0:0: -a c:d:0:0:`
Example explanation:
For example: `user:pass:100:10240:http://192.168.1.1:3100`
`user` is the authentication username
`pass` is the authentication user password (cannot contain a colon:)
`100` is the maximum number of connections for this user, not limited to write 0
`10240` is the rate limit of this user's single tcp connection, the unit is: byte / sec, no limit write 0
`http://192.168.1.1:3100` is the upstream used by this user, no space is left blank
##### `--max-conns`
Limit the maximum number of global connections for the proxy service, a number, 0 is unrestricted, default is 0.
##### `--ip-limit`
Controls the number of connections and connection rate of the client IP. This parameter specifies a file, one rule per line, and the beginning of # is gaze.
The sample file ip.limit, the rule format is as follows:
`127.0.0.1:100:10240:http://192.168.1.1:3100`
Rule interpretation:
`127.0.0.1` is the IP to be restricted
`100` is the maximum number of connections for this IP, not limited to write 0
`10240` is the rate limit of IP single tcp connection, the unit is: byte / s, no limit write 0
`http://192.168.1.1:3100` is the upstream used by this IP, and it is not left blank.
##### `--rate-limit`
Limit the speed of each tcp connection of the service, for example: 100K 2000K 1M . 0 means unlimited, default 0.
## 11. Cluster
The proxy supports the cluster management. The proxy is installed on each machine node as an agent, with the control panel [`proxyadmin cluster edition`] (https://github.com/snail007/proxy-admin-cluster) Unified management of proxy services on massive machines.
If the proxy is to be run as an agent, assume that the cluster port address of the control panel is: `1.1.1.1: 55333`.
The command example is as follows:
`proxy agent -k xxx -c 1.1.1.1:55333 -i test`
Command explanation:
agent: is a function parameter, which means running agent mode.
-k : The encryption and decryption key for communication with `proxyadmin cluster edition`. This key is set in the configuration file of` proxyadmin cluster edition`.
-c : The cluster port address of `proxyadmin cluster edition`, format: IP:port.
-i The unique identifier of the agent ensures that each agent is different. The "unique identifier" specified here is used when adding a node to the control panel. The IP is filled with this "unique identifier".
If -i is not specified, the default is empty, and the control panel adds the IP field to fill in: the agent's internet IP.
-u: proxy parameter, empty by default. You can specify an agent, and the agent will communicate with the cluster through this agent.
The format is the same as that of `--jumper`. For details, please refer to the `--jumper` part of the manual.
notice:
When the client service is configured in the control panel, all nodes use the same key, which leads to only one client working. To solve this problem,
Client service parameters can use placeholders: `{AGENT_ID}` to refer to the agents id as the clients key, so as to ensure that each client has a unique key.
For example, client service parameters:
`client -T tcp -P 1.1.1.1:30000 --k {AGENT_ID}`
File diff suppressed because one or more lines are too long
+1963
View File
@@ -0,0 +1,1963 @@
## 如何安装
### 1. Linux安装
[点击查看Linux安装教程](https://github.com/snail007/goproxy/blob/master/README_ZH.md#%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85-goproxy)
### 2. 苹果Mac系统安装
[点击查看苹果Mac系统安装教程](https://github.com/snail007/proxy_admin_free/blob/master/README_ZH.md#%E8%A7%86%E9%A2%91%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B)
### 3. Windows安装
为了方便操作,推荐Windows用户使用proxy-admin面板,[点击查看Windows安装教程](https://github.com/snail007/proxy_admin_free/blob/master/README_ZH.md#%E8%A7%86%E9%A2%91%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B)
当然你也可以使用命令行goproxy[点击查看手动安装](https://github.com/snail007/goproxy/blob/master/README_ZH.md#%E6%89%8B%E5%8A%A8%E5%AE%89%E8%A3%85-goproxy)
### 4. 其它平台安装
[点击查看其它安装教程](https://github.com/snail007/goproxy/blob/master/README_ZH.md#%E6%89%8B%E5%8A%A8%E5%AE%89%E8%A3%85-goproxy)
## 免费版、商业版说明
本手册描述功能,`proxyadmin商业版``goproxy商业版`全部包含;认证等高级功能参数免费版和VIP控制面板不包含;
如果您用`goproxy免费版`执行某些命令或者`proxyadmin 免费版``proxyadmin VIP版`服务启动失败的时候遇到,类似如下xxx参数不存在的提示,说明这个参数是商业版的功能,您需要下载并购买商业版授权才能使用.
` err : unknown short flag '-a'`
以下软件都是相互独立使用,没有依赖关系,需要购买的也是分别单独购买使用。
软件名称 | 免费版功能 | 商业版功能 | 购买使用 | 特点 | 传送门
:----------- | :---: | :---: | :---: | :---: | :---:
proxyadmin 免费版 | √ | x | x| Web界面操作,支持LinuxWindows,macOS,免费使用,服务数量有限制,适合个人,小白和白嫖党 | [下载安装](https://github.com/snail007/proxy_admin_free)
proxyadmin VIP版 | √ | x | √| Web界面操作,支持更多平台,功能和免费版一样,服务数量无限制,适合个体户或者小集体 | [下载安装](https://github.com/snail007/proxy-admin-vip)
proxyadmin 商业版 | √ | √ | √|Web界面操作,支持更多平台,无限制,适合集体或公司对外提供服务 | [下载安装](https://github.com/snail007/proxy-admin-commercial)
proxyadmin 集群版| √ | √ | √|Web界面操作,支持LinuxWindowsmacOS,无限制,配合`goproxy 商业版`,可以实现以组为单位,管理海量机器上的proxy服务,适合有大量机器的集体或公司对外提供服务 | [下载安装](https://github.com/snail007/proxy-admin-cluster)
goproxy 免费版 | √ | x | x|命令行操作,全平台支持,免费使用,稳定且灵活,适合一切熟悉命令行的大佬或集体或公司白嫖,自用或者大规模部署对外服务 | [下载安装](https://github.com/snail007/goproxy)
goproxy 商业版| √ | √ | √|命令行操作,全平台支持,稳定且灵活,适合集体或公司大规模部署对外提供服务 | [下载安装](https://github.com/snail007/goproxy)
关于免费版功能和商业版功能对比请看这里,[`免费版`和`商业版`功能对比](https://snail.gitee.io/proxy/page/free_vs_commercial/).
[商业版激活绑定教程](https://snail.gitee.io/proxy/page/free_vs_commercial/)
提示:
**免费和付费软件均没有额外技术支持,不按着手册操作的一切问题请自行解决。付费软件免费享有`手册功能`使用指导和`首次安装配置`指导。**
## FAQ
[别点我](https://snail.gitee.io/proxy/page/faq/goproxy%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E8%A7%A3%E7%AD%94/)
## 首次使用必看,谢谢!!
### 1. 环境
该手册教程,默认系统是linux,程序是proxy;所有操作需要root权限;
如果你的是windows,请使用windows版本的proxy.exe即可。
### 2. 使用配置文件
接下来的教程都是通过命令行参数介绍使用方法,也可以通过读取配置文件获取参数。
具体格式是通过@符号指定配置文件,例如:proxy @configfile.txt
configfile.txt里面的格式是,第一行是子命令名称,第二行开始一行一个参数,
格式:`参数 参数值`,没有参数值的直接写参数,比如:--nolog
比如configfile.txt内容如下:
```shell
http
-t tcp
-p :33080
--forever
```
### 3. 调试输出
默认情况下,日志输出的信息不包含文件行数,某些情况下为了排除程序问题,快速定位问题,
可以使用--debug参数,输出代码行数和毫秒时间。
### 4. 使用日志文件
默认情况下,日志是直接在控制台显示出来的,如果要保存到文件,可以使用--log参数,
比如: --log proxy.log,日志就会输出到proxy.log方便排除问题。
### 5. 生成加密通讯需要的证书文件
http(s)代理、tcp代理、udp代理、socks5代理、内网穿透等功能和上级通讯的时候,为了安全我们采用TLS加密通讯,当然可以选择不加密通信通讯,本教程所有和上级通讯都采用加密,需要证书文件。
***所有端必须使用相同的proxy.crt和proxy.key***
1.通过下面的命令生成自签名的证书和key文件。
`proxy keygen -C proxy`
会在当前程序目录下面生成证书文件proxy.crt和key文件proxy.key。
2.通过下面的命令生,使用自签名证书proxy.crt和key文件proxy.key签发新证书:goproxy.crt和goproxy.key。
`proxy keygen -s -C proxy -c goproxy`
会在当前程序目录下面生成证书文件goproxy.crt和key文件goproxy.key。
3.默认情况下证书的里面的域名是随机的,可以使用`-n test.com`参数指定。
4.更多用法:`proxy keygen --help`。
### 6. 后台运行
默认执行proxy之后,如果要保持proxy运行,不能关闭命令行。
如果想在后台运行proxy,命令行可以关闭,只需要在命令最后加上--daemon参数即可。
比如:
`proxy http -t tcp -p "0.0.0.0:38080" --daemon`
### 7. 守护运行
守护运行参数--forever,比如: `proxy http --forever`
proxy会fork子进程,然后监控子进程,如果子进程异常退出,5秒后重启子进程。
该参数配合后台运行参数--daemon和日志参数--log,可以保障proxy一直在后台执行不会因为意外退出,
而且可以通过日志文件看到proxy的输出日志内容。
比如: `proxy http -p ":9090" --forever --log proxy.log --daemon`
### 8. 安全建议
当VPS在nat设备后面,vps上网卡IP都是内网IP,这个时候可以通过-g参数添加vps的外网ip防止死循环。
假设你的vps外网ip是23.23.23.23,下面命令通过-g参数设置23.23.23.23
`proxy http -g "23.23.23.23"`
### 9. 负载均衡和高可用
HTTP(S)\SOCKS5\SPS\TCP代理支持上级负载均衡和高可用,多个上级重复-P参数即可。
负载均衡策略支持5种,可以通过`--lb-method`参数指定:
roundrobin 轮流使用
leastconn 使用最小连接数的
leasttime 使用连接时间最小的
hash 使用根据客户端地址计算出一个固定上级
weight 根据每个上级的权重和连接数情况,选择出一个上级
提示:
1.负载均衡检查时间间隔可以通过`--lb-retrytime`设置,单位毫秒
2.负载均衡连接超时时间可以通过`--lb-timeout`设置,单位毫秒
3.如果负载均衡策略是权重(weight)-P格式为:2.2.2.2:3880?w=11就是权重,大于0的整数。
4.如果负载均衡策略是hash,默认是根据客户端地址选择上级,可以通过开关`--lb-hashtarget`使用访问的目标地址选择上级。
5.TCP代理没有参数`--lb-hashtarget`.
6.默认是负载均衡+高可用模式,如果使用了参数`--lb-onlyha`就只使用高可用模式,依据负载均衡策略选择一个节点,之后就一直使用这个节点,直到这个节点不再存活,那么会依据负载均衡策略再选择一个节点使用,以此循环.
7.如果检查节点全部不再存活,那么每次连接都会随机选取一个节点使用.
### 10. 代理跳板跳转
http(s)代理,SPS代理,内网穿透,tcp代理都支持通过中间第三方代理连接上级,
参数是:--jumper,所有格式如下:
```text
http://username:password@host:port
http://host:port
https://username:password@host:port
https://host:port
socks5://username:password@host:port
socks5://host:port
socks5s://username:password@host:port
socks5s://host:port
ss://method:password@host:port
```
httpsocks5代表的是普通的http和socks5代理。
httpssocks5s代表的是通过tls保护的http和socks5代理,
也就是http代理 over TLS socks over TLS。
### 11. 域名黑白名单
socks/http(s)/sps代理都支持域名黑白名单。
用--stop参数指定一个域名黑名单列表文件,那么当用户连接文件里面这些域名的时候连接就会被断开。
用--only参数指定一个域名白名单列表文件,那么当用户连接文件里面这些域名之外的域名的时候连接就会被断开。
如果同时设置了--stop和--only,那么只有--only会起作用。
黑白域名名单文件内容格式如下:
```text
**.baidu.com
*.taobao.com
a.com
192.168.1.1
192.168.*.*
?.qq.com
```
说明:
1.一行一个域名,域名写法支持通配符`*`和`?``*`代表任意个字符,`?`代表一个任意字符,
2.`**.baidu.com` 匹配无论是多少级所有后缀是`.baidu.com`的域名。
3.`*.taobao.com` 匹配后缀是`.taobao.com`的三级域名。
4.还可以直接是IP地址。
5.`#`开头的为注释。
### 12. 客户端IP黑白名单
socks/http(s)/sps/tcp/udp/dns/内网穿透bridge/内网穿透tbridge,都支持客户端IP黑白名单。
用--ip-deny参数指定一个客户端IP黑名单列表文件,那么当用户的IP在这个文件里面的时候连接就会被断开。
用--ip-allow参数指定一个客户端IP白名单列表文件,那么当用户的IP不在这个文件里面的时候连接就会被断开。
如果同时设置了--ip-deny和--ip-allow,那么只有--ip-allow会起作用。
客户端IP黑白名单文件内容格式如下:
```text
192.168.1.1
192.168.*.*
192.168.1?.*
```
说明:
1.一行一个域名,域名写法支持通配符`*`和`?``*`代表任意个字符,`?`代表一个任意字符。
2.`#`开头的为注释。
### 13. 协议加载文件
proxy的各种代理功能里面很多地方都有参数设置一个文件,比如:--blocked 指定一个直接走上级的域名列表文件,参数值是文件的路径,
如果参数支持协议加载文件,那么文件路径不仅可以是文件路径,还可以是:
a.“base64://”开头的base64编码的上面说明的文件内容,比如:base64://ajfpoajsdfa=
b.”str://“开头的英文逗号分割的多个,比如:str://xxx,yyy
proxy的blockeddirectstoponlyhostsresolve.rulesrewriter.rulesip.allowip.deny 文件支持协议加载。
### 14. 客户端并发连接数
socks5\sps\http代理,控制客户端并发连接数参数是:`--max-conns-rate`,控制每秒客户端的最大连接数,默认20, 0为不限制.
### 15 监听多个端口
`tcp/http/socks/sps`支持同时监听多个端口以及范围端口。
一般情况下监听一个端口就可以,不过如果需要同时监听多个两个端口,或者范围端口,那么-p参数是支持的,
格式是:`-p 0.0.0.0:80,0.0.0.0:443,0.0.0.0:8000-9000,:5000-6000`,多个绑定用逗号分隔即可。
## 1.HTTP代理
### 1.1.普通一级HTTP代理
![1.1](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/http-1.png)
`proxy http -t tcp -p "0.0.0.0:38080"`
-p参数支持的写法:
```text
-p ":8081" 监听8081
-p ":8081,:8082" 监听8081和8082
-p ":8081,:8082,:9000-9999" 监听8081和8082以及9000,9001至9999,共1002个端口
```
### 1.2.普通二级HTTP代理
![1.2](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/http-2.png)
使用本地端口8090,假设上级HTTP代理是`22.22.22.22:8080`
`proxy http -t tcp -p "0.0.0.0:8090" -T tcp -P "22.22.22.22:8080" `
我们还可以指定网站域名的黑白名单文件,一行一个域名,匹配规则是最右匹配,比如:baidu.com,匹配的是*.*.baidu.com,黑名单的域名直接走上级代理,白名单的域名不走上级代理。
`proxy http -p "0.0.0.0:8090" -T tcp -P "22.22.22.22:8080" -b blocked.txt -d direct.txt`
### 1.3.HTTP二级代理(加密)
> 注意: 后面二级代理使用的`proxy.crt`和`proxy.key`应与一级代理一致
![1.3](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/http-tls-2.png)
一级HTTP代理(VPSIP:22.22.22.22)
`proxy http -t tls -p ":38080" -C proxy.crt -K proxy.key`
二级HTTP代理(本地Linux)
`proxy http -t tcp -p ":8080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
那么访问本地的8080端口就是访问VPS上面的代理端口38080。
二级HTTP代理(本地windows)
`proxy.exe http -t tcp -p ":8080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
然后设置你的windos系统中,需要通过代理上网的程序的代理为http模式,地址为:127.0.0.1,端口为:8080,程序即可通过加密通道通过vps上网。
### 1.4.HTTP三级代理(加密)
![1.3](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/http-tls-3.png)
一级HTTP代理VPS_01IP:22.22.22.22
`proxy http -t tls -p ":38080" -C proxy.crt -K proxy.key`
二级HTTP代理VPS_02IP:33.33.33.33
`proxy http -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
三级HTTP代理(本地)
`proxy http -t tcp -p ":8080" -T tls -P "33.33.33.33:28080" -C proxy.crt -K proxy.key`
那么访问本地的8080端口就是访问一级HTTP代理上面的代理端口38080。
### 1.5.Basic认证,API认证
请参考`9.API认证` 和 `10.本地认证`
### 1.6.HTTP代理流量强制走上级HTTP代理
默认情况下,proxy会智能判断一个网站域名是否无法访问,如果无法访问才走上级HTTP代理.通过--always可以使全部HTTP代理流量强制走上级HTTP代理。
`proxy http --always -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
### 1.7.HTTP(S)通过SSH中转
![1.7](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/http-ssh-1.png)
说明:ssh中转的原理是利用了ssh的转发功能,就是你连接上ssh之后,可以通过ssh代理访问目标地址。
假设有:vps
- IP是2.2.2.2 ssh端口是22 ssh用户名是:user ssh用户密码是:demo
- 用户user的ssh私钥名称是user.key
#### *1.7.1 ssh用户名和密码的方式*
本地HTTP(S)代理28080端口,执行:
`proxy http -T ssh -P "2.2.2.2:22" -u user -D demo -t tcp -p ":28080"`
#### *1.7.2 ssh用户名和密钥的方式*
本地HTTP(S)代理28080端口,执行:
`proxy http -T ssh -P "2.2.2.2:22" -u user -S user.key -t tcp -p ":28080"`
### 1.8.KCP协议传输
![1.8](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/http-kcp.png)
KCP协议需要--kcp-key参数设置一个密码用于加密解密数据
一级HTTP代理(VPSIP:22.22.22.22)
`proxy http -t kcp -p ":38080" --kcp-key mypassword`
二级HTTP代理(本地Linux)
`proxy http -t tcp -p ":8080" -T kcp -P "22.22.22.22:38080" --kcp-key mypassword`
那么访问本地的8080端口就是访问VPS上面的代理端口38080,数据通过kcp协议传输,注意kcp走的是udp协议协议,所以防火墙需放开38080的udp协议。
### 1.9 HTTP(S)反向代理
![1.9](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/fxdl.png)
proxy不仅支持在其他软件里面通过设置代理的方式,为其他软件提供代理服务,而且支持直接把请求的网站域名解析到proxy监听的ip上,然后proxy监听80和443端口,那么proxy就会自动为你代理访问需要访问的HTTP(S)网站。
使用方式:
在"最后一级proxy代理"的机器上,因为proxy要伪装成所有网站,网站默认的端口HTTP是80,HTTPS是443,让proxy监听80和443端口即可.参数-p多个地址用逗号分割。
`proxy http -t tcp -p :80,:443`
这个命令就在机器上启动了一个proxy代理,同时监听80和443端口,既可以当作普通的代理使用,也可以直接把需要代理的域名解析到这个机器的IP上。
如果有上级代理那么参照上面教程设置上级即可,使用方式完全一样。
`proxy http -t tcp -p :80,:443 -T tls -P "2.2.2.2:33080" -C proxy.crt -K proxy.key`
注意:
proxy所在的服务器的DNS解析结果不能受到自定义的解析影响,不然就死循环了,proxy代理最好指定`--dns 8.8.8.8`参数。
### 1.10 HTTP(S)透明代理
该模式需要具有一定的网络基础,相关概念不懂的请自行搜索解决。
假设proxy现在在路由器上运行,启动命令如下:
`proxy http -t tcp -p :33080 -T tls -P "2.2.2.2:33090" -C proxy.crt -K proxy.key`
然后添加iptables规则,下面是参考规则:
```shell
#上级proxy服务端服务器IP地址:
proxy_server_ip=2.2.2.2
#路由器运行proxy监听的端口:
proxy_local_port=33080
#下面的就不用修改了
#create a new chain named PROXY
iptables -t nat -N PROXY
# Ignore your PROXY server's addresses
# It's very IMPORTANT just be careful。
iptables -t nat -A PROXY -d $proxy_server_ip -j RETURN
# Ignore LANs IP address
iptables -t nat -A PROXY -d 0.0.0.0/8 -j RETURN
iptables -t nat -A PROXY -d 10.0.0.0/8 -j RETURN
iptables -t nat -A PROXY -d 127.0.0.0/8 -j RETURN
iptables -t nat -A PROXY -d 169.254.0.0/16 -j RETURN
iptables -t nat -A PROXY -d 172.16.0.0/12 -j RETURN
iptables -t nat -A PROXY -d 192.168.0.0/16 -j RETURN
iptables -t nat -A PROXY -d 224.0.0.0/4 -j RETURN
iptables -t nat -A PROXY -d 240.0.0.0/4 -j RETURN
# Anything to port 80 443 should be redirected to PROXY's local port
iptables -t nat -A PROXY -p tcp --dport 80 -j REDIRECT --to-ports $proxy_local_port
iptables -t nat -A PROXY -p tcp --dport 443 -j REDIRECT --to-ports $proxy_local_port
# Apply the rules to nat client
iptables -t nat -A PREROUTING -p tcp -j PROXY
# Apply the rules to localhost
iptables -t nat -A OUTPUT -p tcp -j PROXY
```
- 清空整个链 iptables -F 链名比如iptables -t nat -F PROXY
- 删除指定的用户自定义链 iptables -X 链名 比如 iptables -t nat -X PROXY
- 从所选链中删除规则 iptables -D 链名 规则详情 比如 iptables -t nat -D PROXY -d 223.223.192.0/255.255.240.0 -j RETURN
### 1.11 自定义DNS
--dns-address和--dns-ttl参数,用于自己指定proxy访问域名的时候使用的dns--dns-address
以及解析结果缓存时间(--dns-ttl)秒数,避免系统dns对proxy的干扰,另外缓存功能还能减少dns解析时间提高访问速度。
比如:
`proxy http -p ":33080" --dns-address "8.8.8.8:53" --dns-ttl 300`
### 1.12 自定义加密
proxy的http(s)代理在tcp之上可以通过tls标准加密以及kcp协议加密tcp数据,除此之外还支持在tls和kcp之后进行自定义
加密,也就是说自定义加密和tls|kcp是可以联合使用的,内部采用AES256加密,使用的时候只需要自己定义一个密码即可,
加密分为两个部分,一部分是本地(-z)是否加密解密,一部分是与上级(-Z)传输是否加密解密。
自定义加密要求两端都是proxy才可以,下面分别用二级,三级为例:
二级实例
一级vps(ip:2.2.2.2)上执行:
`proxy http -t tcp -z demo_password -p :7777`
本地二级执行:
`proxy http -T tcp -P 2.2.2.2:777 -Z demo_password -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级加密传输访问目标网站。
三级实例
一级vps(ip:2.2.2.2)上执行:
`proxy http -t tcp -z demo_password -p :7777`
二级vps(ip:3.3.3.3)上执行:
`proxy http -T tcp -P 2.2.2.2:7777 -Z demo_password -t tcp -z other_password -p :8888`
本地三级执行:
`proxy http -T tcp -P 3.3.3.3:8888 -Z other_password -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级加密传输访问目标网站。
### 1.13 压缩传输
proxy的http(s)代理在tcp之上可以通过tls标准加密以及kcp协议加密tcp数据,在自定义加密之前还可以对数据进行压缩,
也就是说压缩功能和自定义加密和tls|kcp是可以联合使用的,压缩分为两个部分,一部分是本地(-m)是否压缩传输,
一部分是与上级(-M)传输是否压缩。
压缩要求两端都是proxy才可以,压缩也在一定程度上保护了(加密)数据,下面分别用二级,三级为例:
二级实例
一级vps(ip:2.2.2.2)上执行:
`proxy http -t tcp -m -p :7777`
本地二级执行:
`proxy http -T tcp -P 2.2.2.2:777 -M -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级压缩传输访问目标网站。
三级实例
一级vps(ip:2.2.2.2)上执行:
`proxy http -t tcp -m -p :7777`
二级vps(ip:3.3.3.3)上执行:
`proxy http -T tcp -P 2.2.2.2:7777 -M -t tcp -m -p :8888`
本地三级执行:
`proxy http -T tcp -P 3.3.3.3:8888 -M -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级压缩传输访问目标网站。
### 1.14 负载均衡
HTTP(S)代理支持上级负载均衡,多个上级重复-P参数即可。
`proxy http --lb-method=hash -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080`
### 1.14.1 设置重试间隔和超时时间
`proxy http --lb-method=leastconn --lb-retrytime 300 --lb-timeout 300 -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080 -t tcp -p :33080`
### 1.14.2 设置权重
`proxy http --lb-method=weight -T tcp -P 1.1.1.1:33080?w=1 -P 2.1.1.1:33080?w=2 -P 3.1.1.1:33080?w=1 -t tcp -p :33080`
### 1.14.3 使用目标地址选择上级
`proxy http --lb-hashtarget --lb-method=hash -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080 -t tcp -p :33080`
### 1.15 限速
限速100K,通过`-l`参数即可指定,比如:100K 2000K 1M . 0意味着无限制。
`proxy http -t tcp -p 2.2.2.2:33080 -l 100K`
### 1.16 指定出口IP
`--bind-listen`参数,就可以开启客户端用`入口IP`连接过来的,就用`入口IP`作为`出口IP`访问目标网站的功能。如果绑定了不正确的IP会导致代理不能工作。
普通多IP用法:
`proxy http -t tcp -p :33080 --bind-listen`
上面的写法适合本机有大量IP,不想一个一个单独写,比如本机有IP`3.3.3.3`,当客户端使用`3.3.3.3`连接代理,那么`3.3.3.3`就会作为客户端的出口IP
这里的`3.3.3.3`就是`入口IP`和`出口IP`,你会发现`入口IP`和`出口IP`是一样的,`--bind-listen`这种模式人为不能干预`入口IP`和`出口IP`。
单独用法:
本机有IP`5.5.5.5`,开一个代理端口`6666`,凡是通过`5.5.5.5:6666`端口进来的,都使用`5.5.5.5`作为出口IP。
命令如下:
`proxy http -t tcp -p 5.5.5.5:6666 --bind-listen`
#### 自由指定出口IP
上面的`--bind-listen`参数虽然可以指定出口IP,但是`入口IP`和`出口IP`不能人为干预。如果想入口IP和出口IP不一样,
可以使用`--bind-ip`参数,格式:`IP:端口`,比如: `1.1.1.1:8080``[2000:0:0:0:0:0:0:1]:8080`。
多个绑定需求,可以重复`--bind-ip`参数即可。
比如本机有IP`5.5.5.5`,`6.6.6.6`,监听了`8888`和`7777`两个端口,命令如下:
`proxy http -t tcp -p :8888,:7777 --bind-ip 5.5.5.5:7777 --bind-ip 6.6.6.6:8888`
那么客户端访问`7777`端口,出口IP就是`5.5.5.5`,访问`8888`端口,出口IP就是`6.6.6.6`,如果同时设置了`--bind-ip`和`--bind-listen`,`--bind-ip`的优先级更高。
### 1.17 证书参数使用base64数据
默认情况下-C,-K参数是crt证书和key文件的路径,
如果是base64://开头,那么就认为后面的数据是base64编码的,会解码后使用。
### 1.18 智能模式
智能模式设置,可以是intelligent|direct|parent三者之一。
默认是:intelligent。
每个值的含义如下:
`--intelligent=direct`,不在blocked里面的目标都直连。
`--intelligent=parent`,不在direct里面的目标都走上级。
`--intelligent=intelligent`blocked和direct里面都没有的目标,智能判断是否使用上级访问目标。
### 1.19 查看帮助
`proxy help http`
## 2.TCP代理
### 2.1 普通一级TCP代理
![2.1](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/tcp-1.png)
本地执行:
`proxy tcp -p ":33080" -T tcp -P "192.168.22.33:22"`
那么访问本地33080端口就是访问192.168.22.33的22端口。
`-p`参数支持的写法:
```text
-p ":8081" 监听8081
-p ":8081,:8082" 监听8081和8082
-p ":8081,:8082,:9000-9999" 监听8081和8082以及9000,9001至9999,共1002个端口
```
如果本地监听端口数量大于1,那么将会连接与本地端口一致的对应上级端口,忽略`-P`里面的端口。
如果需要所有端口进来的连接,都连接到上级指定端口,可以加上参数`--lock-port`。
比如:
`proxy tcp -p ":33080-33085" -T tcp -P "192.168.22.33:0"`
那么`33080`端口进来的连接,将会连接192.168.22.33的`33080`端口,其它端口以此类推,本地和上级端口一致,此时参数`-P`里面的端口用`0`。
如果想无论是`33080``33081`等端口进来的连接都连接到192.168.22.33的`22`端口,可以加上参数`--lock-port`
`proxy tcp -p ":33080-33085" -T tcp -P "192.168.22.33:22" --lock-port`
### 2.2 普通二级TCP代理
![2.2](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/tcp-2.png)
VPS(IP:22.22.22.33)执行:
`proxy tcp -p ":33080" -T tcp -P "127.0.0.1:8080"`
本地执行:
`proxy tcp -p ":23080" -T tcp -P "22.22.22.33:33080"`
那么访问本地23080端口就是访问22.22.22.33的8080端口。
### 2.3 普通三级TCP代理
![2.3](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/tcp-3.png)
一级TCP代理VPS_01IP:22.22.22.22
`proxy tcp -p ":38080" -T tcp -P "66.66.66.66:8080"`
二级TCP代理VPS_02IP:33.33.33.33
`proxy tcp -p ":28080" -T tcp -P "22.22.22.22:38080"`
三级TCP代理(本地)
`proxy tcp -p ":8080" -T tcp -P "33.33.33.33:28080"`
那么访问本地8080端口就是通过加密TCP隧道访问66.66.66.66的8080端口。
### 2.4 加密二级TCP代理
![2.4](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/tcp-tls-2.png)
VPS(IP:22.22.22.33)执行:
`proxy tcp -t tls -p ":33080" -T tcp -P "127.0.0.1:8080" -C proxy.crt -K proxy.key`
本地执行:
`proxy tcp -p ":23080" -T tls -P "22.22.22.33:33080" -C proxy.crt -K proxy.key`
那么访问本地23080端口就是通过加密TCP隧道访问22.22.22.33的8080端口。
### 2.5 加密三级TCP代理
![2.5](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/tcp-tls-3.png)
一级TCP代理VPS_01IP:22.22.22.22
`proxy tcp -t tls -p ":38080" -T tcp -P "66.66.66.66:8080" -C proxy.crt -K proxy.key`
二级TCP代理VPS_02IP:33.33.33.33
`proxy tcp -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
三级TCP代理(本地)
`proxy tcp -p ":8080" -T tls -P "33.33.33.33:28080" -C proxy.crt -K proxy.key`
那么访问本地8080端口就是通过加密TCP隧道访问66.66.66.66的8080端口。
### 2.6 通过代理连接上级
有时候proxy所在的网络不能直接访问外网,需要通过一个https或者socks5代理才能上网,那么这个时候
-J参数就可以帮助你让proxy的tcp端口映射的时候通过https或者socks5代理去连接上级-P,将外部端口映射到本地。
-J参数格式如下:
https代理写法:
代理需要认证,用户名:username 密码:password
https://username:password@host:port
代理不需要认证
https://host:port
socks5代理写法:
代理需要认证,用户名:username 密码:password
socks5://username:password@host:port
代理不需要认证
socks5://host:port
host:代理的IP或者域名
port:代理的端口
### 2.7 指定出口IP
当TCP代理当上级类型(参数:-T)是tcp当时候,支持指定`出口IP`。`--bind-listen`参数,就可以开启客户端用`入口IP`连接过来的,就用`入口IP`作为`出口IP`访问目标网站的功能。如果绑定了不正确的IP会导致代理不能工作。
普通多IP用法:
`proxy tcp -t tcp -p :33080 --bind-listen -T tcp -P 2.2.2.2:3322`
上面的写法适合本机有大量IP,不想一个一个单独写,比如本机有IP`3.3.3.3`,当客户端使用`3.3.3.3`连接代理,那么`3.3.3.3`就会作为客户端的出口IP
这里的`3.3.3.3`就是`入口IP`和`出口IP`,你会发现`入口IP`和`出口IP`是一样的,`--bind-listen`这种模式人为不能干预`入口IP`和`出口IP`。
单独用法:
本机有IP`5.5.5.5`,开一个代理端口`6666`,凡是通过`5.5.5.5:6666`端口进来的,都使用`5.5.5.5`作为出口IP。
命令如下:
`proxy tcp -t tcp -p 5.5.5.5:6666 --bind-listen -T tcp -P 2.2.2.2:3322`
#### 自由指定出口IP
上面的`--bind-listen`参数虽然可以指定出口IP,但是`入口IP`和`出口IP`不能人为干预。如果想入口IP和出口IP不一样,
可以使用`--bind-ip`参数,格式:`IP:端口`,比如: `1.1.1.1:8080``[2000:0:0:0:0:0:0:1]:8080`。
多个绑定需求,可以重复`--bind-ip`参数即可。
比如本机有IP`5.5.5.5`,`6.6.6.6`,监听了`8888`和`7777`两个端口,命令如下:
`proxy tcp -t tcp -p :8888,:7777 --bind-ip 5.5.5.5:7777 --bind-ip 6.6.6.6:8888 -T tcp -P 2.2.2.2:3322`
那么客户端访问`7777`端口,出口IP就是`5.5.5.5`,访问`8888`端口,出口IP就是`6.6.6.6`,如果同时设置了`--bind-ip`和`--bind-listen`,`--bind-ip`的优先级更高。
### 2.8 限速,限制连接数
参数`--max-conns`可以限制每个端口的最大连接数。
比如限制每个端口最多1000个连接数:
`proxy tcp -p ":33080" -T tcp -P "192.168.22.33:22" --max-conns 1000`
参数`--rate-limit`可以限制每个tcp连接的速率。
比如限制每个tcp连接速率为100k/s:
`proxy tcp -p ":33080" -T tcp -P "192.168.22.33:22" --rate-limit 100k`
### 2.9 压缩传输
`--c`控制本地和客户端之间是否压缩传输,默认false;`--C`控制本地和上级之间是否压缩传输,默认false。
示例:
VPS(IP:22.22.22.33)执行:
`proxy tcp -t tcp --c -p ":33080" -T tcp -P "127.0.0.1:8080"`
本地执行:
`proxy tcp -t tcp -p ":23080" -T tcp -P "22.22.22.33:33080" --C`
### 2.10 查看帮助
`proxy help tcp`
## 3.UDP代理
### 3.1.普通一级UDP代理
![3.1](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/udp-1.png)
本地执行:
`proxy udp -p ":5353" -T udp -P "8.8.8.8:53"`
那么访问本地UDP:5353端口就是访问8.8.8.8的UDP:53端口。
`-p`参数支持的写法:
```text
-p ":8081" 监听8081
-p ":8081,:8082" 监听8081和8082
-p ":8081,:8082,:9000-9999" 监听8081和8082以及9000,9001至9999,共1002个端口
```
如果本地监听端口数量大于1,那么将会连接与本地端口一致的对应上级端口,忽略`-P`里面的端口。
如果需要所有端口进来的连接,都连接到上级指定端口,可以加上参数`--lock-port`。
比如:
`proxy udp -p ":33080-33085" -T udp -P "192.168.22.33:0"`
那么`33080`端口进来的连接,将会连接192.168.22.33的`33080`端口,其它端口以此类推,本地和上级端口一致,此时参数`-P`里面的端口用`0`。
如果想无论是`33080``33081`等端口进来的连接都连接到192.168.22.33的`2222`端口,可以加上参数`--lock-port`
`proxy udp -p ":33080-33085" -T udp -P "192.168.22.33:2222" --lock-port`
### 3.2.普通二级UDP代理
![3.2](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/udp-2.png)
VPS(IP:22.22.22.33)执行:
`proxy tcp -p ":33080" -T udp -P "8.8.8.8:53"`
本地执行:
`proxy udp -p ":5353" -T tcp -P "22.22.22.33:33080"`
那么访问本地UDP:5353端口就是通过TCP隧道,通过VPS访问8.8.8.8的UDP:53端口。
### 3.3.普通三级UDP代理
![3.3](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/udp-3.png)
一级TCP代理VPS_01IP:22.22.22.22
`proxy tcp -p ":38080" -T udp -P "8.8.8.8:53"`
二级TCP代理VPS_02IP:33.33.33.33
`proxy tcp -p ":28080" -T tcp -P "22.22.22.22:38080"`
三级TCP代理(本地)
`proxy udp -p ":5353" -T tcp -P "33.33.33.33:28080"`
那么访问本地5353端口就是通过TCP隧道,通过VPS访问8.8.8.8的53端口。
### 3.4.加密二级UDP代理
![3.4](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/udp-tls-2.png)
VPS(IP:22.22.22.33)执行:
`proxy tcp -t tls -p ":33080" -T udp -P "8.8.8.8:53" -C proxy.crt -K proxy.key`
本地执行:
`proxy udp -p ":5353" -T tls -P "22.22.22.33:33080" -C proxy.crt -K proxy.key`
那么访问本地UDP:5353端口就是通过加密TCP隧道,通过VPS访问8.8.8.8的UDP:53端口。
### 3.5.加密三级UDP代理
![3.5](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/udp-tls-3.png)
一级TCP代理VPS_01IP:22.22.22.22
`proxy tcp -t tls -p ":38080" -T udp -P "8.8.8.8:53" -C proxy.crt -K proxy.key`
二级TCP代理VPS_02IP:33.33.33.33
`proxy tcp -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key`
三级TCP代理(本地)
`proxy udp -p ":5353" -T tls -P "33.33.33.33:28080" -C proxy.crt -K proxy.key`
那么访问本地5353端口就是通过加密TCP隧道,通过VPS_01访问8.8.8.8的53端口。
### 3.6 指定出口IP
当UDP代理当上级类型(参数:-T)是udp当时候,支持指定`出口IP`。使用`--bind-listen`参数,就可以开启客户端用`入口IP`连接过来的,就用`入口IP`作为`出口IP`访问目标的功能。如果绑定了不正确的IP会导致代理不能工作。
`proxy udp -p ":33080" -T udp -P "192.168.22.33:2222" -B`
### 3.7 查看帮助
`proxy help udp`
## 4.内网穿透
### 4.1、原理说明
内网穿透,分为两个版本,“多链接版本”和“多路复用版本”,一般像web服务这种不是长时间连接的服务建议用“多链接版本”,如果是要保持长时间连接建议使用“多路复用版本”。
1. 多链接版本,对应的子命令是tservertclienttbridge。
1. 多路复用版本,对应的子命令是serverclientbridge。
1. 多链接版本和多路复用版本的参数和使用方式完全一样。
1. 多路复用版本的server,client可以开启压缩传输,参数是--c。
1. server,client要么都开启压缩,要么都不开启,不能只开一个。
下面的教程以“多路复用版本”为例子,说明使用方法。
内网穿透由三部分组成:client端,server端,bridge端;client和server主动连接bridge端进行桥接。
### 4.2、TCP普通用法
背景:
- 公司机器A提供了web服务80端口
- 有VPS一个,公网IP:22.22.22.22
需求:
在家里能够通过访问VPS的28080端口访问到公司机器A的80端口
步骤:
1. 在vps上执行
`proxy bridge -p ":33080" -C proxy.crt -K proxy.key`
`proxy server -r ":28080@:80" -P "127.0.0.1:33080" -C proxy.crt -K proxy.key`
1. 在公司机器A上面执行
`proxy client -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
1. 完成
### 4.3、微信接口本地开发
背景:
- 自己的笔记本提供了nginx服务80端口
- 有VPS一个,公网IP:22.22.22.22
需求:
在微信的开发帐号的网页回调接口配置里面填写地址:http://22.22.22.22/calback.php
然后就可以访问到笔记本的80端口下面的calback.php,如果需要绑定域名,可以用自己的域名
比如:wx-dev.xxx.com解析到22.22.22.22,然后在自己笔记本的nginx里
配置域名wx-dev.xxx.com到具体的目录即可。
步骤:
1. 在vps上执行,确保vps的80端口没被其它程序占用。
`proxy bridge -p ":33080" -C proxy.crt -K proxy.key`
`proxy server -r ":80@:80" -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
1. 在自己笔记本上面执行
`proxy client -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
1. 完成
### 4.4、UDP普通用法
背景:
- 公司机器A提供了DNS解析服务,UDP:53端口
- 有VPS一个,公网IP:22.22.22.22
需求:
在家里能够通过设置本地dns为22.22.22.22,使用公司机器A进行域名解析服务。
步骤:
1. 在vps上执行
`proxy bridge -p ":33080" -C proxy.crt -K proxy.key`
`proxy server --udp -r ":53@:53" -P "127.0.0.1:33080" -C proxy.crt -K proxy.key`
1. 在公司机器A上面执行
`proxy client -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
1. 完成
### 4.5、高级用法一
背景:
- 公司机器A提供了web服务80端口
- 有VPS一个,公网IP:22.22.22.22
需求:
为了安全,不想在VPS上能够访问到公司机器A,在家里能够通过访问本机的28080端口,
通过加密隧道访问到公司机器A的80端口。
步骤:
1. 在vps上执行
`proxy bridge -p ":33080" -C proxy.crt -K proxy.key`
1. 在公司机器A上面执行
`proxy client -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
1. 在家里电脑上执行
`proxy server -r ":28080@:80" -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
1. 完成
### 4.6、高级用法二
提示:
如果同时有多个client连接到同一个bridge,需要指定不同的key,可以通过--k参数设定,--k可以是任意唯一字符串,
只要在同一个bridge上唯一即可。
server连接到bridge的时候,如果同时有多个client连接到同一个bridge,需要使用--k参数选择client。
暴露多个端口重复-r参数即可.-r格式是:"本地IP:本地端口@clientHOST:client端口"。
背景:
- 公司机器A提供了web服务80端口,ftp服务21端口
- 有VPS一个,公网IP:22.22.22.22
需求:
在家里能够通过访问VPS的28080端口访问到公司机器A的80端口
在家里能够通过访问VPS的29090端口访问到公司机器A的21端口
步骤:
1. 在vps上执行
`proxy bridge -p ":33080" -C proxy.crt -K proxy.key`
`proxy server -r ":28080@:80" -r ":29090@:21" --k test -P "127.0.0.1:33080" -C proxy.crt -K proxy.key`
1. 在公司机器A上面执行
`proxy client --k test -P "22.22.22.22:33080" -C proxy.crt -K proxy.key`
1. 完成
### 4.7.server的-r参数
-r完整格式是:`PROTOCOL://LOCAL_IP:LOCAL_PORT@[CLIENT_KEY]CLIENT_LOCAL_HOST:CLIENT_LOCAL_PORT`
4.7.1.协议PROTOCOL:tcp、udp、ptcp、pudp。
比如: `-r "udp://:10053@:53" -r "tcp://:10800@:1080" -r ":8080@:80"`
如果指定了--udp参数,PROTOCOL默认为udp,那么:`-r ":8080@:80"`默认为udp;
如果没有指定--udp参数,PROTOCOL默认为tcp,那么:`-r ":8080@:80"`默认为tcp;
4.7.2.CLIENT_KEY:默认是default。
比如: -r "udp://:10053@[test1]:53" -r "tcp://:10800@[test2]:1080" -r ":8080@:80"
如果指定了--k参数,比如--k test,那么:`-r ":8080@:80"`CLIENT_KEY默认为test;
如果没有指定--k参数,那么:`-r ":8080@:80"`CLIENT_KEY默认为default;
4.7.3.LOCAL_IP为空默认是:`0.0.0.0`CLIENT_LOCAL_HOST为空默认是:`127.0.0.1`;
### 4.8.server和client通过代理连接bridge
有时候server或者client所在的网络不能直接访问外网,需要通过一个https或者socks5代理才能上网,那么这个时候
-J参数就可以帮助你让server或者client通过https或者socks5代理去连接bridge。
-J参数格式如下:
https代理写法:
代理需要认证,用户名:username 密码:password
https://username:password@host:port
代理不需要认证
https://host:port
socks5代理写法:
代理需要认证,用户名:username 密码:password
socks5://username:password@host:port
代理不需要认证
socks5://host:port
host:代理的IP或者域名
port:代理的端口
### 4.9.内网穿透HTTP服务
通常HTTP请求客户端会使用server的ip和端口去设置HOST字段,但是与期望的后端实际HOST不一样,这样就造成了tcp是通的, 但后端依赖HOST字段定位虚拟主机就不能工作.现在用`--http-host`参数强制设置http头部的HOST字段值为后端实际的域名和端口即可轻松解决,另外使用了`--http-host`参数之后,会在每个HTTP请求的头部增加两个头部 `X-Forwarded-For` 和 `X-Real-IP` 值是客户端IP, 这样后端http服务就能方便的获取用户端真实IP地址。
`server`的--http-host参数格式如下:
`--http-host www.test.com:80@2200`,如果server监听多个端口,只需要重复`--http-host`参数设置每个端口的HOST即可。
实例:
比如client本地nginx127.0.0.1:80提供了web服务,其中绑定了一个域名`local.com`。
那么server的启动参数可以如下:
`proxy server -P :30000 -r :2500@127.0.0.1:80 --http-host local.com@2500`
解释:
`-r :2500@127.0.0.1:80` 和 `--http-host local.com:80@2500` 里面的2500端口是server本地监听的端口
当使用http协议请求server的ip:2500端口的时候,http的头部HOST字段就会被设置为`local.com`。
另外只有设置了`--http-host`参数
### 4.10 关于流量统计
如果单独启动一个server对接上级是proxy-admin控制面板,需要在上级控制面板里面新建一个映射,获得个映射规则的ID,
然后启动server的时候加上参数 --server-id=映射规则的ID 才能统计到流量。
### 4.11 关于p2p
内网穿透支持在server和client网络情况满足的情况下,server和client之间通过p2p直接连接,开启方法是:
在启动bridgeserverclient到时候都加上`--p2p`参数即可。server的-r参数可以针对端口是否启用p2p(ptcp和pudp)。
如果server和client之间p2p打洞失败,那么会自动切换使用bridge中转传输数据。
### 4.12 客户端key白名单
内网穿透bridge可以设置客户端key白名单,参数是--client-keys,格式可以是:
a.文件名,文件内容一行一个客户端key只能包含数字字母下划线,也就是客户端启动参数--k的值,只有客户端key在此白名单的客户端才能连接。# 开头的行,为注释。
b.“base64://”开头的base64编码的上面a说明的文件内容,比如:base64://ajfpoajsdfa=
c.”str://“开头的英文逗号分割的多个key,比如:str://default,company,school
默认是空,允许所有key。
### 4.13 网络NAT类型判断
nat类型判断,方便查看网络是否支持p2p,可以执行:`proxy tools -a nattype`
### 4.14 查看帮助
`proxy help bridge`
`proxy help server`
`proxy help client`
## 5.SOCKS5代理
提示:
SOCKS5代理,支持CONNECTUDP协议,不支持BIND,支持用户名密码认证。
***如果你的VPS是阿里云,腾讯云这种VPS,就是ifconfig看不见你的公网IP,只能看见内网IP,***
***那么需要加上`-g VPS公网IP`参数,SOCKS5代理的UDP功能才能正常工作。***
***socks5的udp功能默认关闭,可以通过--udp开启,默认是握手随机端口,可以通过固定一个端口提高性能,
通过参数--udp-port 0设置,0代表随机选择一个空闲端口,也可以手动指定一个具体端口。***
### 5.1 普通SOCKS5代理
`proxy socks -t tcp -p "0.0.0.0:38080" --udp-port 0 --udp`
-p参数支持的写法:
```text
-p ":8081" 监听8081
-p ":8081,:8082" 监听8081和8082
-p ":8081,:8082,:9000-9999" 监听8081和8082以及9000,9001至9999,共1002个端口
```
### 5.2.普通二级SOCKS5代理
![5.2](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/socks-2.png)
使用本地端口8090,假设上级SOCKS5代理是`22.22.22.22:8080`
`proxy socks -t tcp -p "0.0.0.0:8090" -T tcp -P "22.22.22.22:8080" --udp-port 0 --udp`
我们还可以指定网站域名的黑白名单文件,一行一个域名,匹配规则是最右匹配,比如:baidu.com,匹配的是*.*.baidu.com,黑名单的域名域名直接走上级代理,白名单的域名不走上级代理;如果域名即在黑名单又在白名单中,那么黑名单起作用。
`proxy socks -p "0.0.0.0:8090" -T tcp -P "22.22.22.22:8080" -b blocked.txt -d direct.txt --udp-port 0 --udp`
### 5.3.SOCKS二级代理(加密)
![5.3](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/socks-tls-2.png)
一级SOCKS代理(VPSIP:22.22.22.22)
`proxy socks -t tls -p ":38080" -C proxy.crt -K proxy.key --udp-port 0 --udp`
二级SOCKS代理(本地Linux)
`proxy socks -t tcp -p ":8080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key --udp-port 0 --udp`
那么访问本地的8080端口就是访问VPS上面的代理端口38080。
二级SOCKS代理(本地windows)
`proxy.exe socks -t tcp -p ":8080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key --udp-port 0 --udp`
然后设置你的windos系统中,需要通过代理上网的程序的代理为socks5模式,地址为:127.0.0.1,端口为:8080,程序即可通过加密通道通过vps上网。
### 5.4.SOCKS三级代理(加密)
![5.4](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/socks-tls-3.png)
一级SOCKS代理VPS_01IP:22.22.22.22
`proxy socks -t tls -p ":38080" -C proxy.crt -K proxy.key --udp-port 0 --udp`
二级SOCKS代理VPS_02IP:33.33.33.33
`proxy socks -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key --udp-port 0 --udp`
三级SOCKS代理(本地)
`proxy socks -t tcp -p ":8080" -T tls -P "33.33.33.33:28080" -C proxy.crt -K proxy.key --udp-port 0 --udp`
那么访问本地的8080端口就是访问一级SOCKS代理上面的代理端口38080。
### 5.5.SOCKS代理流量强制走上级SOCKS代理
默认情况下,proxy会智能判断一个网站域名是否无法访问,如果无法访问才走上级SOCKS代理.通过--always可以使全部SOCKS代理流量强制走上级SOCKS代理。
`proxy socks --always -t tls -p ":28080" -T tls -P "22.22.22.22:38080" -C proxy.crt -K proxy.key --udp-port 0 --udp`
### 5.6.SOCKS通过SSH中转
![5.6](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/socks-ssh.png)
说明:ssh中转的原理是利用了ssh的转发功能,就是你连接上ssh之后,可以通过ssh代理访问目标地址。
假设有:vps
- IP是2.2.2.2 ssh端口是22 ssh用户名是:user ssh用户密码是:demo
- 用户user的ssh私钥名称是user.key
#### *5.6.1 ssh用户名和密码的方式*
本地SOCKS5代理28080端口,执行:
`proxy socks -T ssh -P "2.2.2.2:22" -u user -D demo -t tcp -p ":28080" --udp-port 0 --udp`
#### *5.6.2 ssh用户名和密钥的方式*
本地SOCKS5代理28080端口,执行:
`proxy socks -T ssh -P "2.2.2.2:22" -u user -S user.key -t tcp -p ":28080" --udp-port 0 --udp`
那么访问本地的28080端口就是通过VPS访问目标地址。
### 5.7.认证
对于socks5代理协议我们可以进行用户名密码认证,认证的用户名和密码可以在命令行指定
`proxy socks -t tcp -p ":33080" -a "user1:pass1" -a "user2:pass2"`
多个用户,重复-a参数即可。
也可以放在文件中,格式是一行一个"用户名:密码",然后用-F指定。
`proxy socks -t tcp -p ":33080" -F auth-file.txt`
### 5.8.KCP协议传输
KCP协议需要--kcp-key参数设置一个密码用于加密解密数据
一级HTTP代理(VPSIP:22.22.22.22)
`proxy socks -t kcp -p ":38080" --kcp-key mypassword -g 22.22.22.22`
二级HTTP代理(本地Linux)
`proxy socks -t tcp -p ":8080" -T kcp -P "22.22.22.22:38080" --kcp-key mypassword`
那么访问本地的8080端口就是访问VPS上面的代理端口38080,数据通过kcp协议传输。
提示:
当本地使用kcp协议时,需要用-g指定vps公网IP,socks5的UDP功能才能正常使用.这时-g是返回给客户端的UDP地址中的IP地址.
### 5.9.自定义DNS
--dns-address和--dns-ttl参数,用于自己指定proxy访问域名的时候使用的dns--dns-address
以及解析结果缓存时间(--dns-ttl)秒数,避免系统dns对proxy的干扰,另外缓存功能还能减少dns解析时间提高访问速度。
比如:
`proxy socks -p ":33080" --dns-address "8.8.8.8:53" --dns-ttl 300`
### 5.10 自定义加密
proxy的socks代理在tcp之上可以通过tls标准加密以及kcp协议加密tcp数据,除此之外还支持在tls和kcp之后进行自定义加密,也就是说自定义加密和tls|kcp是可以联合使用的,内部采用AES256加密,使用的时候只需要自己定义一个密码即可,
加密分为两个部分,一部分是本地(-z)是否加密解密,一部分是与上级(-Z)传输是否加密解密。
自定义加密要求两端都是proxy才可以。
下面分别用二级,三级为例:
二级实例
一级vps(ip:2.2.2.2)上执行:
`proxy socks -t tcp -z demo_password -p :7777`
本地二级执行:
`proxy socks -T tcp -P 2.2.2.2:777 -Z demo_password -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级加密传输访问目标网站。
三级实例
一级vps(ip:2.2.2.2)上执行:
`proxy socks -t tcp -z demo_password -p :7777`
二级vps(ip:3.3.3.3)上执行:
`proxy socks -T tcp -P 2.2.2.2:7777 -Z demo_password -t tcp -z other_password -p :8888`
本地三级执行:
`proxy socks -T tcp -P 3.3.3.3:8888 -Z other_password -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级加密传输访问目标网站。
### 5.11 压缩传输
proxy的socks代理在tcp之上可以通过自定义加密和tls标准加密以及kcp协议加密tcp数据,在自定义加密之前还可以
对数据进行压缩,也就是说压缩功能和自定义加密和tls|kcp是可以联合使用的,压缩分为两个部分,
一部分是本地(-m)是否压缩传输,一部分是与上级(-M)传输是否压缩。
压缩要求两端都是proxy才可以,压缩也在一定程度上保护了(加密)数据。
下面分别用二级,三级为例:
二级实例
一级vps(ip:2.2.2.2)上执行:
`proxy socks -t tcp -m -p :7777`
本地二级执行:
`proxy socks -T tcp -P 2.2.2.2:777 -M -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级压缩传输访问目标网站。
三级实例
一级vps(ip:2.2.2.2)上执行:
`proxy socks -t tcp -m -p :7777`
二级vps(ip:3.3.3.3)上执行:
`proxy socks -T tcp -P 2.2.2.2:7777 -M -t tcp -m -p :8888`
本地三级执行:
`proxy socks -T tcp -P 3.3.3.3:8888 -M -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级压缩传输访问目标网站。
### 5.12 负载均衡
SOCKS代理支持上级负载均衡,多个上级重复-P参数即可。
`proxy socks --lb-method=hash -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080 -p :33080 -t tcp`
### 5.12.1 设置重试间隔和超时时间
`proxy socks --lb-method=leastconn --lb-retrytime 300 --lb-timeout 300 -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080 -p :33080 -t tcp`
### 5.12.2 设置权重
`proxy socks --lb-method=weight -T tcp -P 1.1.1.1:33080?w=1 -P 2.1.1.1:33080?w=2 -P 3.1.1.1:33080?w=1 -p :33080 -t tcp`
### 5.12.3 使用目标地址选择上级
`proxy socks --lb-hashtarget --lb-method=hash -T tcp -P 1.1.1.1:33080 -P 2.1.1.1:33080 -P 3.1.1.1:33080 -p :33080 -t tcp`
### 5.13 限速
限速100K,通过`-l`参数即可指定,比如:100K 2000K 1M . 0意味着无限制。
`proxy socks -t tcp -p 2.2.2.2:33080 -l 100K`
### 5.14 指定出口IP
`--bind-listen`参数,就可以开启客户端用`入口IP`连接过来的,就用`入口IP`作为`出口IP`访问目标网站的功能。如果绑定了不正确的IP会导致代理不能工作。
普通多IP用法:
`proxy socks -t tcp -p :33080 --bind-listen`
上面的写法适合本机有大量IP,不想一个一个单独写,比如本机有IP`3.3.3.3`,当客户端使用`3.3.3.3`连接代理,那么`3.3.3.3`就会作为客户端的出口IP
这里的`3.3.3.3`就是`入口IP`和`出口IP`,你会发现`入口IP`和`出口IP`是一样的,`--bind-listen`这种模式人为不能干预`入口IP`和`出口IP`。
单独用法:
本机有IP`5.5.5.5`,开一个代理端口`6666`,凡是通过`5.5.5.5:6666`端口进来的,都使用`5.5.5.5`作为出口IP。
命令如下:
`proxy socks -t tcp -p 5.5.5.5:6666 --bind-listen`
#### 自由指定出口IP
上面的`--bind-listen`参数虽然可以指定出口IP,但是`入口IP`和`出口IP`不能人为干预。如果想入口IP和出口IP不一样,
可以使用`--bind-ip`参数,格式:`IP:端口`,比如: `1.1.1.1:8080``[2000:0:0:0:0:0:0:1]:8080`。
多个绑定需求,可以重复`--bind-ip`参数即可。
比如本机有IP`5.5.5.5`,`6.6.6.6`,监听了`8888`和`7777`两个端口,命令如下:
`proxy socks -t tcp -p :8888,:7777 --bind-ip 5.5.5.5:7777 --bind-ip 6.6.6.6:8888`
那么客户端访问`7777`端口,出口IP就是`5.5.5.5`,访问`8888`端口,出口IP就是`6.6.6.6`,如果同时设置了`--bind-ip`和`--bind-listen`,`--bind-ip`的优先级更高。
### 5.15 级联认证
SOCKS5支持级联认证,-A可以设置上级认证信息。
上级:
`proxy socks -t tcp -p 2.2.2.2:33080 -a user:pass`
本地:
`proxy socks -T tcp -P 2.2.2.2:33080 -A user:pass -t tcp -p :33080`
请更多认证细节,请参考`9.API认证` 和 `10.本地认证`
### 5.16 证书参数使用base64数据
默认情况下-C,-K参数是crt证书和key文件的路径,
如果是base64://开头,那么就认为后面的数据是base64编码的,会解码后使用。
### 5.17 智能模式
智能模式设置,可以是intelligent|direct|parent三者之一。
默认是:intelligent。
每个值的含义如下:
`--intelligent=direct`,不在blocked里面的目标都直连。
`--intelligent=parent`,不在direct里面的目标都走上级。
`--intelligent=intelligent`blocked和direct里面都没有的目标,智能判断是否使用上级访问目标。
### 5.18 固定UDP功能端口
默认情况下socks5的UDP功能的端口号,proxy是按着`rfc1982草案`要求,使用协议握手过程中随机指定,不需要提前指定。
但是某些情况下,需要固定UDP功能端口,可以通过参数`--udp-port 端口号`用来固定UDP功能的端口号,比如:
`proxy socks -t tcp -p "0.0.0.0:38080" --udp-port 38080`
### 5.19 查看帮助
`proxy help socks`
## 6.SPS协议转换
### 6.1 功能介绍
代理协议转换使用的是sps子命令,sps可以把已经存在的http(s)代理或者socks5代理或ss代理转换为一个端口同时支持http(s)和socks5和ss的代理,而且http(s)代理支持正向代理和反向代理(SNI),当上级是SOCKS5时,转换后的SOCKS5或者SS代理仍然支持UDP功能;另外对于已经存在的http(s)代理或者socks5代理,支持tls、tcp、kcp三种模式,支持链式连接,也就是可以多个sps结点层级连接构建加密通道。
`ss`功能支持的加密方法为:aes-128-cfb aes-128-ctr aes-128-gcm aes-192-cfb aes-192-ctr aes-192-gcm aes-256-cfb aes-256-ctr aes-256-gcm bf-cfb cast5-cfb chacha20 chacha20-ietf chacha20-ietf-poly1305 des-cfb rc4-md5 rc4-md5-6 salsa20 xchacha20
本地监听端口-p参数支持的写法:
```text
-p ":8081" 监听8081
-p ":8081,:8082" 监听8081和8082
-p ":8081,:8082,:9000-9999" 监听8081和8082以及9000,9001至9999,共1002个端口
```
提示:
当本地使用kcp协议时,需要用-g指定vps公网IP,socks5的UDP功能才能正常使用.这时-g是返回给客户端的UDP地址中的IP地址.
ss的udp功能默认关闭,可以通过--ssudp开启。socks5的udp功能默认关闭,可以通过--udp开启,默认是握手随机端口,可以通过固定一个端口提高性能,
通过参数--udp-port 0设置,0代表随机选择一个空闲端口,也可以手动指定一个具体端口。
### 6.2 HTTP(S)转HTTP(S)+SOCKS5+SS
转换后的SOCKS5或者SS代理不具备UDP功能。
假设已经存在一个普通的http(s)代理:127.0.0.1:8080,现在我们把它转为同时支持http(s)和socks5和ss的普通代理,转换后的本地端口为18080,ss加密方式:aes-192-cfbss密码:pass。
命令如下:
`proxy sps -S http -T tcp -P 127.0.0.1:8080 -t tcp -p :18080 -h aes-192-cfb -j pass`
假设已经存在一个tls的http(s)代理:127.0.0.1:8080,现在我们把它转为同时支持http(s)和socks5和ss的普通代理,转换后的本地端口为18080,tls需要证书文件,ss加密方式:aes-192-cfbss密码:pass。
命令如下:
`proxy sps -S http -T tls -P 127.0.0.1:8080 -t tcp -p :18080 -C proxy.crt -K proxy.key -h aes-192-cfb -j pass`
假设已经存在一个kcp的http(s)代理(密码是:demo123):127.0.0.1:8080,现在我们把它转为同时支持http(s)和socks5和ss的普通代理,转换后的本地端口为18080,ss加密方式:aes-192-cfbss密码:pass。
命令如下:
`proxy sps -S http -T kcp -P 127.0.0.1:8080 -t tcp -p :18080 --kcp-key demo123 -h aes-192-cfb -j pass`
### 6.3 SOCKS5转HTTP(S)+SOCKS5+SS
如果上级是SOCKS5而且支持UDP功能,那么转换后的SOCKS5或者SS代理仍然支持UDP功能。
假设已经存在一个普通的socks5代理:127.0.0.1:8080,现在我们把它转为同时支持http(s)和socks5和ss的普通代理,转换后的本地端口为18080,ss加密方式:aes-192-cfbss密码:pass。
命令如下:
`proxy sps -S socks -T tcp -P 127.0.0.1:8080 -t tcp -p :18080 -h aes-192-cfb -j pass`
假设已经存在一个tls的socks5代理:127.0.0.1:8080,现在我们把它转为同时支持http(s)和socks5和ss的普通代理,转换后的本地端口为18080,tls需要证书文件,ss加密方式:aes-192-cfbss密码:pass。
命令如下:
`proxy sps -S socks -T tls -P 127.0.0.1:8080 -t tcp -p :18080 -C proxy.crt -K proxy.key -h aes-192-cfb -j pass`
假设已经存在一个kcp的socks5代理(密码是:demo123):127.0.0.1:8080,现在我们把它转为同时支持http(s)和socks5和ss的普通代理,转换后的本地端口为18080,ss加密方式:aes-192-cfbss密码:pass。
命令如下:
`proxy sps -S socks -T kcp -P 127.0.0.1:8080 -t tcp -p :18080 --kcp-key demo123 -h aes-192-cfb -j pass`
### 6.4 SS转HTTP(S)+SOCKS5+SS
SPS上级和本地支持ss协议,上级可以是SPS或者标准的ss服务,转换后的SOCKS5或者SS代理不具备UDP功能。
假设已经存在一个普通的SS或者SPS代理(开启了ss,加密方式:aes-256-cfb,密码:demo)127.0.0.1:8080,现在我们把它转为同时支持http(s)和socks5和ss的普通代理,转换后的本地端口为18080,转换后的ss加密方式:aes-192-cfbss密码:pass。
命令如下:
`proxy sps -S ss -H aes-256-cfb -J pass -T tcp -P 127.0.0.1:8080 -t tcp -p :18080 -h aes-192-cfb -j pass`。
### 6.5 链式连接
![6.4](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/sps-tls.png)
上面提过多个sps结点可以层级连接构建加密通道,假设有如下vps和家里的pc电脑。
vps012.2.2.2
vps023.3.3.3
现在我们想利用pc和vps01和vps02构建一个加密通道,本例子用tls加密也可以用kcp,在pc上访问本地18080端口就是访问vps01的本地8080端口。
首先在vps01(2.2.2.2)上我们运行一个只有本地可以访问的http(s)代理,执行:
`proxy http -t tcp -p 127.0.0.1:8080`
然后在vps01(2.2.2.2)上运行一个sps结点,执行:
`proxy sps -S http -T tcp -P 127.0.0.1:8080 -t tls -p :8081 -C proxy.crt -K proxy.key`
然后在vps02(3.3.3.3)上运行一个sps结点,执行:
`proxy sps -S http -T tls -P 2.2.2.2:8081 -t tls -p :8082 -C proxy.crt -K proxy.key`
然后在pc上运行一个sps结点,执行:
`proxy sps -S http -T tls -P 3.3.3.3:8082 -t tcp -p :18080 -C proxy.crt -K proxy.key`
完成。
### 6.6 认证功能
sps支持http(s)\socks5代理认证,可以级联认证,有四个重要的信息:
1:用户发送认证信息`user-auth`。
2:设置的本地认证信息`local-auth`。
3:设置的连接上级使用的认证信息`parent-auth`。
4:最终发送给上级的认证信息`auth-info-to-parent`。
他们的情况关系如下:
| user-auth | local-auth | parent-auth | auth-info-to-paren
| ------ | ------ | ------ | ------
| 有/没有 | 有 | 有 | 来自parent-auth
| 有/没有 | 没有 | 有 | 来自parent-auth
| 有/没有 | 有 | 没有 | 无
| 没有 | 没有 | 没有 | 无
| 有 | 没有 | 没有 | 来自user-auth
对于sps代理我们可以进行用户名密码认证,认证的用户名和密码可以在命令行指定
`proxy sps -S http -T tcp -P 127.0.0.1:8080 -t tcp -p ":33080" -a "user1:pass1:0:0:" -a "user2:pass2:0:0:"`
多个用户,重复-a参数即可。
也可以放在文件中,格式是一行一个`用户名:密码:连接数:速率:上级`,然后用-F指定。
`proxy sps -S http -T tcp -P 127.0.0.1:8080 -t tcp -p ":33080" -F auth-file.txt`
如果上级有认证,下级可以通过-A参数设置认证信息,比如:
上级:`proxy sps -S http -T tcp -P 127.0.0.1:8080 -t tcp -p ":33080" -a "user1:pass1:0:0:" -a "user2:pass2:0:0:"`
下级:`proxy sps -S http -T tcp -P 127.0.0.1:8080 -A "user1:pass1" -t tcp -p ":33080" `
请更多认证细节,请参考`9.API认证` 和 `10.本地认证`
### 6.7 多个上级
如果存在多个上级,可以通过多个-P指定。
比如:
`proxy sps -P http://127.0.0.1:3100 -P socks5://127.0.0.1:3200`
`-P`完整格式如下:
`protocol://a:b@2.2.2.2:33080#1`
下面对每部分进行解释:
`protocol://` 是协议类型,可能的类型以及含有如下:
```text
http 等价于 -S http -T tcp
https 等价于 -S http -T tls --parent-tls-single 也就是http(s)代理 over TLS
https2 等价于 -S http -T tls
socks5 等价于 -S socks -T tcp
socks5s 等价于 -S socks -T tls --parent-tls-single 也就是socks over TLS
socks5s2 等价于 -S socks -T tls
ss 等价于 -S ss -T tcp
httpws 等价于 -S http -T ws
httpwss 等价于 -S http -T wss
socks5ws 等价于 -S socks -T ws
socks5wss 等价于 -S socks -T wss
```
`a:b`是代理认证的用户名密码,如果是ss,`a`是加密方法,`b`是密码,没有用户名密码可以留空比如:`http://2.2.2.2:33080`,如果用户名和密码保护特殊符号可以使用urlencode进行编码。
`2.2.2.2:33080`是上级地址,格式是:`IP(或域名):端口`,如果底层是ws/wss协议还可以带上路径,比如:`2.2.2.2:33080/ws`;
还能通过附加查询参数`m`和`k`设置`ws\wss`的`加密方法`和`密码`,比如:`2.2.2.2:33080/ws?m=aes-192-cfb&k=password`
`#1`多个上级的负载均衡是权重策略时候,设置的权重,很少用到。
### 6.8 自定义加密
proxy的sps代理在tcp之上可以通过tls标准加密以及kcp协议加密tcp数据,除此之外还支持在tls和kcp之后进行
自定义加密,也就是说自定义加密和tls|kcp是可以联合使用的,内部采用AES256加密,使用的时候只需要自己定义
一个密码即可,加密分为两个部分,一部分是本地(-z)是否加密解密,一部分是与上级(-Z)传输是否加密解密。
自定义加密要求两端都是proxy才可以。
下面分别用二级,三级为例:
假设已经存在一个http(s)代理:`6.6.6.6:6666`
二级实例
一级vps(ip:2.2.2.2)上执行:
`proxy sps -S http -T tcp -P 6.6.6.6:6666 -t tcp -z demo_password -p :7777`
本地二级执行:
`proxy sps -T tcp -P 2.2.2.2:777 -Z demo_password -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级加密传输访问目标网站。
三级实例
一级vps(ip:2.2.2.2)上执行:
`proxy sps -S http -T tcp -P 6.6.6.6:6666 -t tcp -z demo_password -p :7777`
二级vps(ip:3.3.3.3)上执行:
`proxy sps -T tcp -P 2.2.2.2:7777 -Z demo_password -t tcp -z other_password -p :8888`
本地三级执行:
`proxy sps -T tcp -P 3.3.3.3:8888 -Z other_password -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级加密传输访问目标网站。
### 6.9 压缩传输
proxy的sps代理在tcp之上可以通过自定义加密和tls标准加密以及kcp协议加密tcp数据,在自定义加密之前还可以
对数据进行压缩,也就是说压缩功能和自定义加密和tls|kcp是可以联合使用的,压缩分为两个部分,
一部分是本地(-m)是否压缩传输,一部分是与上级(-M)传输是否压缩。
压缩要求两端都是proxy才可以,压缩也在一定程度上保护了(加密)数据。
下面分别用二级,三级为例:
二级实例
一级vps(ip:2.2.2.2)上执行:
`proxy sps -t tcp -m -p :7777`
本地二级执行:
`proxy sps -T tcp -P 2.2.2.2:777 -M -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级压缩传输访问目标网站。
三级实例
一级vps(ip:2.2.2.2)上执行:
`proxy sps -t tcp -m -p :7777`
二级vps(ip:3.3.3.3)上执行:
`proxy sps -T tcp -P 2.2.2.2:7777 -M -t tcp -m -p :8888`
本地三级执行:
`proxy sps -T tcp -P 3.3.3.3:8888 -M -t tcp -p :8080`
这样通过本地代理8080访问网站的时候就是通过与上级压缩传输访问目标网站。
### 6.10 禁用协议
SPS默认情况下一个端口支持http(s)和socks5两种代理协议,我们可以通过参数禁用某个协议
比如:
1.禁用HTTP(S)代理功能只保留SOCKS5代理功能,参数:`--disable-http`。
`proxy sps -T tcp -P 3.3.3.3:8888 -M -t tcp -p :8080 --disable-http`
1.禁用SOCKS5代理功能只保留HTTP(S)代理功能,参数:`--disable-socks`。
`proxy sps -T tcp -P 3.3.3.3:8888 -M -t tcp -p :8080 --disable-socks`
### 6.11 限速
假设存在SOCKS5上级:
`proxy socks -p 2.2.2.2:33080 -z password -t tcp`
sps下级,限速100K
`proxy sps -S socks -P 2.2.2.2:33080 -T tcp -Z password -l 100K -t tcp -p :33080`
通过`-l`参数即可指定,比如:100K 2000K 1M . 0意味着无限制。
### 6.12 指定出口IP
`--bind-listen`参数,就可以开启客户端用`入口IP`连接过来的,就用`入口IP`作为`出口IP`访问目标网站的功能。如果绑定了不正确的IP会导致代理不能工作。
普通多IP用法:
`proxy sps -t tcp -p :33080 --bind-listen`
上面的写法适合本机有大量IP,不想一个一个单独写,比如本机有IP`3.3.3.3`,当客户端使用`3.3.3.3`连接代理,那么`3.3.3.3`就会作为客户端的出口IP
这里的`3.3.3.3`就是`入口IP`和`出口IP`,你会发现`入口IP`和`出口IP`是一样的,`--bind-listen`这种模式人为不能干预`入口IP`和`出口IP`。
单独用法:
本机有IP`5.5.5.5`,开一个代理端口`6666`,凡是通过`5.5.5.5:6666`端口进来的,都使用`5.5.5.5`作为出口IP。
命令如下:
`proxy sps -t tcp -p 5.5.5.5:6666 --bind-listen`
#### 自由指定出口IP
上面的`--bind-listen`参数虽然可以指定出口IP,但是`入口IP`和`出口IP`不能人为干预。如果想入口IP和出口IP不一样,
可以使用`--bind-ip`参数,格式:`IP:端口`,比如: `1.1.1.1:8080``[2000:0:0:0:0:0:0:1]:8080`。
多个绑定需求,可以重复`--bind-ip`参数即可。
比如本机有IP`5.5.5.5`,`6.6.6.6`,监听了`8888`和`7777`两个端口,命令如下:
`proxy sps -t tcp -p :8888,:7777 --bind-ip 5.5.5.5:7777 --bind-ip 6.6.6.6:8888`
那么客户端访问`7777`端口,出口IP就是`5.5.5.5`,访问`8888`端口,出口IP就是`6.6.6.6`,如果同时设置了`--bind-ip`和`--bind-listen`,`--bind-ip`的优先级更高。
### 6.13 证书参数使用base64数据
默认情况下-C,-K参数是crt证书和key文件的路径,
如果是base64://开头,那么就认为后面的数据是base64编码的,会解码后使用。
### 6.14 独立服务
sps一个端口可完成完整功能的代理`http(s)\socks\ss`功能。
下面这个命令,就是一键开启http(s)\ss\socks服务,同时开启socks5的udp和ss的udp功能。
`proxy sps -p :33080 --ssudp --udp --udp-port 0`
### 6.15 目标重定向
sps功能提供的http(s)\socks5\ss代理功能,客户端通过sps代理去连接指定的“目标”,这个“目标”一般是网站也可能是任意的tcp地址,
网站”目标“一般是foo.com:80,foo.com:443sps支持使用--rewrite参数指定一个“目标”重定向规则文件,对目标进行重定向,客户端是无感知的,
比如你对“目标”:demo.com:80重定向到192.168.0.12:80,那么客户端访问网站demo.com,其实访问的是192.168.0.12提供的网站服务。
“目标”重定向规则文件示例:
```text
# example
www.a.com:80 10.0.0.2:8080
**.b.com:80 10.0.0.2:80
192.168.0.11:80 10.0.0.2:8080
```
### 6.16 固定UDP功能端口
默认情况下sps的socks5的UDP功能的端口号是按着`rfc1982草案`要求,使用协议握手过程中随机指定,不需要提前指定。
但是某些情况下,需要固定UDP功能端口,可以通过参数`--udp-port 端口号`用来固定UDP功能的端口号,比如:
`proxy sps -t tcp -p "0.0.0.0:38080" --udp-port 38081`
需要注意的是,sps的ss功能也有UDP功能,而且ss的UDP端口和tcp端口是一样的,所以要避免socks5的UDP端口和ss的UDP端口冲突,
要指定和tcp端口不一样的端口。
### 6.17 iptables 透明代理
sps模式支持Linux系统的iptables转发支持,也就是通常所说的iptables透明代理,如果在网关设备上进行iptables透明代理,那么对通过网关联网的设备就能实现无感知的代理。
启动命令实例:
`proxy sps --redir -p :8888 -P httpws://1.1.1.1:33080`
这里假设存在一个http的上级代理1.1.1.1:33080,使用ws传输数据。
然后添加iptables规则,下面是参考规则:
```shell
#上级proxy服务端服务器IP地址:
proxy_server_ip=1.1.1.1
#路由器运行proxy监听的端口:
proxy_local_port=33080
#下面的就不用修改了
#create a new chain named PROXY
iptables -t nat -N PROXY
# Ignore your PROXY server's addresses
# It's very IMPORTANT just be careful。
iptables -t nat -A PROXY -d $proxy_server_ip -j RETURN
# Ignore LANs IP address
iptables -t nat -A PROXY -d 0.0.0.0/8 -j RETURN
iptables -t nat -A PROXY -d 10.0.0.0/8 -j RETURN
iptables -t nat -A PROXY -d 127.0.0.0/8 -j RETURN
iptables -t nat -A PROXY -d 169.254.0.0/16 -j RETURN
iptables -t nat -A PROXY -d 172.16.0.0/12 -j RETURN
iptables -t nat -A PROXY -d 192.168.0.0/16 -j RETURN
iptables -t nat -A PROXY -d 224.0.0.0/4 -j RETURN
iptables -t nat -A PROXY -d 240.0.0.0/4 -j RETURN
# Anything to port 80 443 should be redirected to PROXY's local port
iptables -t nat -A PROXY -p tcp -j REDIRECT --to-ports $proxy_local_port
# Apply the rules to nat client
iptables -t nat -A PREROUTING -p tcp -j PROXY
# Apply the rules to localhost
iptables -t nat -A OUTPUT -p tcp -j PROXY
```
- 清空整个链 iptables -F 链名比如iptables -t nat -F PROXY
- 删除指定的用户自定义链 iptables -X 链名 比如 iptables -t nat -X PROXY
- 从所选链中删除规则 iptables -D 链名 规则详情 比如 iptables -t nat -D PROXY -d 223.223.192.0/255.255.240.0 -j RETURN
### 6.18 查看帮助
`proxy help sps`
## 7.KCP配置
### 7.1 配置介绍
proxy的很多功能都支持kcp协议,凡是使用了kcp协议的功能都支持这里介绍的配置参数。
所以这里统一对KCP配置参数进行介绍。
### 7.2 详细配置
所有的KCP配置参数共有17个,你可以都不用设置,他们都有默认值,如果为了或者最好的效果,
就需要自己根据自己根据网络情况对参数进行配置。由于kcp配置很复杂需要一定的网络基础知识,
如果想获得kcp参数更详细的配置和解说,请自行搜索。每个参数的命令行名称以及默认值和简单的功能说明如下:
```
--kcp-key="secrect" pre-shared secret between client and server
--kcp-method="aes" encrypt/decrypt method can be: aes aes-128 aes-192 salsa20 blowfish
twofish cast5 3des tea xtea xor sm4 none
--kcp-mode="fast" profiles: fast3 fast2 fast normal manual
--kcp-mtu=1350 set maximum transmission unit for UDP packets
--kcp-sndwnd=1024 set send window size(num of packets)
--kcp-rcvwnd=1024 set receive window size(num of packets)
--kcp-ds=10 set reed-solomon erasure coding - datashard
--kcp-ps=3 set reed-solomon erasure coding - parityshard
--kcp-dscp=0 set DSCP(6bit)
--kcp-nocomp disable compression
--kcp-acknodelay be carefull! flush ack immediately when a packet is received
--kcp-nodelay=0 be carefull!
--kcp-interval=50 be carefull!
--kcp-resend=0 be carefull!
--kcp-nc=0 be carefull! no congestion
--kcp-sockbuf=4194304 be carefull!
--kcp-keepalive=10 be carefull!
```
提示:
参数:--kcp-mode中的四种fast3 fast2 fast normal模式,
相当于设置了下面四个参数:
normal`--nodelay=0 --interval=40 --resend=2 --nc=1`
fast `--nodelay=0 --interval=30 --resend=2 --nc=1`
fast2`--nodelay=1 --interval=20 --resend=2 --nc=1`
fast3`--nodelay=1 --interval=10 --resend=2 --nc=1`
## 8.安全DNS
### 8.1 介绍
众所周知DNS是UDP端口53提供的服务,但是随着网络的发展一些知名DNS服务器也支持TCP方式dns查询,比如谷歌的8.8.8.8,proxy的DNS防污染服务器原理就是在本地启动一个proxy的DNS代理服务器,它用TCP的方式通过上级代理进行dns查询。如果它和上级代理通讯采用加密的方式,那么就可以进行安全无污染的DNS解析,还支持独立服务,并发解析,支持增强的hosts文件功能支持灵活的并发解析转发。
dns解析顺序:
1.使用参数--hosts解析。
2.要解析的域名在1中没有找到,就使用参数--forward规则解析。
3.要解析的域名在1和2中都没有找到,就使用默认--default解析,--default默认行为参数值有三种:proxydirectsystem。
三种参数值解释如下:
proxy:通过上级去连接-q参数指定的dns服务器去解析域名。
direct:通过本地网络去连接-q参数指定的dns服务器去解析域名。
system:通过系统dns去解析域名。
提示:
--hosts 参数指定的host文件格式和系统hosts文件一致,而且域名支持通配符,可以参考hosts文件。
--forward 参数指定的解析转发规则文件,格式可以参考resolve.rules文件,域名支持通配符,支持为每个域名指定多个dns服务器并发解析,谁最快解析成功就用谁的解析结果。
-q 参数可以指定多个远程dns服务器,执行并发解析谁最快解析成功就用谁的解析结果,默认是:1.1.1.18.8.8.89.9.9.9,多个用逗号分割,
比如还可以带端口:1.1.1.18.8.8.8#539.9.9.9
如果独立服务,不需要上级:
可以执行:
`proxy dns --default system -p :5353`
or
`proxy dns --default direct -p :5353`
### 8.2 使用示例
#### 8.2.1 普通HTTP(S)上级代理
假设有一个上级代理:2.2.2.2:33080
本地执行:
`proxy dns -S http -T tcp -P 2.2.2.2:33080 -p :53`
那么本地的UDP端口53就提供了DNS解析功能。
#### 8.2.2 普通SOCKS5上级代理
假设有一个上级代理:2.2.2.2:33080
本地执行:
`proxy dns -S socks -T tcp -P 2.2.2.2:33080 -p :53`
那么本地的UDP端口53就提供了DNS解析功能。
#### 8.2.3 TLS加密的HTTP(S)上级代理
假设有一个上级代理:2.2.2.2:33080
上级代理执行的命令是:
`proxy http -t tls -C proxy.crt -K proxy.key -p :33080`
本地执行:
`proxy dns -S http -T tls -P 2.2.2.2:33080 -C proxy.crt -K proxy.key -p :53`
那么本地的UDP端口53就提供了安全防污染DNS解析功能。
#### 8.2.4 TLS加密的SOCKS5上级代理
假设有一个上级代理:2.2.2.2:33080
上级代理执行的命令是:
`proxy socks -t tls -C proxy.crt -K proxy.key -p :33080`
本地执行:
`proxy dns -S socks -T tls -P 2.2.2.2:33080 -C proxy.crt -K proxy.key -p :53`
那么本地的UDP端口53就提供了安全防污染DNS解析功能。
#### 8.2.5 KCP加密的HTTP(S)上级代理
假设有一个上级代理:2.2.2.2:33080
上级代理执行的命令是:
`proxy http -t kcp -p :33080`
本地执行:
`proxy dns -S http -T kcp -P 2.2.2.2:33080 -p :53`
那么本地的UDP端口53就提供了安全防污染DNS解析功能。
#### 8.2.6 KCP加密的SOCKS5上级代理
假设有一个上级代理:2.2.2.2:33080
上级代理执行的命令是:
`proxy socks -t kcp -p :33080`
本地执行:
`proxy dns -S socks -T kcp -P 2.2.2.2:33080 -p :53`
那么本地的UDP端口53就提供了安全防污染DNS解析功能。
#### 8.2.7 自定义加密的HTTP(S)上级代理
假设有一个上级代理:2.2.2.2:33080
上级代理执行的命令是:
`proxy http -t tcp -p :33080 -z password`
本地执行:
`proxy dns -S http -T tcp -Z password -P 2.2.2.2:33080 -p :53`
那么本地的UDP端口53就提供了安全防污染DNS解析功能。
#### 8.2.8 自定义加密的SOCKS5上级代理
假设有一个上级代理:2.2.2.2:33080
上级代理执行的命令是:
`proxy socks -t kcp -p :33080 -z password`
本地执行:
`proxy dns -S socks -T tcp -Z password -P 2.2.2.2:33080 -p :53`
那么本地的UDP端口53就提供了安全防污染DNS解析功能。
## 9.API认证,限速,控制连接数,限流量
proxy的http(s)/socks5/sps代理功能,支持通过API控制用户对代理对访问。
### 通过API可以干什么?
- 用户维度,控制单个连接速率,控制最大连接数。
- IP维度,控制单个连接速率,控制最大连接数。
- 动态上级,可以根据用户或者客户端IP,动态的从API获取其上级,支持http(s)/socks5/ss上级。
- 认证每一个连接,无论是否要求客户端认证。
- 缓存认证结果,时间可以设置,减轻API压力。
#### 具体使用
proxy的http(s)/socks5/sps代理API功能,通过`--auth-url`和`--auth-nouser`和`--auth-cache`三个参数控制。
参数`--auth-url`是HTTP API接口地址,客户端连接的时候,proxy会GET方式请求这url,带上下面参数,如果返回HTTP状态码204,代表认证成功,其它情况认为认证失败。
一个完整的请求API的示例:
`http://test.com/auth.php?user=a&pass=b&client_addr=127.0.0.1:49892&local_addr=127.0.0.1:8100&target=http%3A%2F%2Fwww.baidu.com&service=http&sps=0`
#### 参数说明
`user和pass` 当代理开启了认证功能,这里就是客户端提供的用户名和密码。
`client_addr` 客户端访问代理时的用的地址,格式IP:端口。
`local_addr` 客户端访问的代理地址,格式IP:端口。
`service` 代理类型,分为:http、socks。
`sps` 代理是否是sps提供的,1:是,0:否。
`target` 客户端要访问的目标,如果是http(s)代理,target是访问的具体url;如果是socks5代理,target是空。
#### 示例
假设--auth-url http://127.0.0.1:333/auth.php 指向了一个php接口地址.
auth.php内容如下:
```php
<?php
#设置所有的用户名密码,前面是用户名,后面是对应密码
$alluser=[
"user1"=>"pass1",
"user2"=>"pass2",
"user3"=>"pass3",
"user4"=>"pass4",
];
$proxy_ip=$_GET['local_addr'];
$user_ip=$_GET['client_addr'];
$service=$_GET['service'];
$is_sps=$_GET['sps']=='1';
$user=$_GET['user'];
$pass=$_GET['pass'];
$target=$_GET['target'];
//业务逻辑判断
//....
$ok=false;
foreach ($alluser as $dbuser => $dbpass) {
if ($user==$dbuser&&$pass==$dbpass){
$ok=true;
break;
}
}
//设置认证结果
if($ok){
header("userconns:1000");
header("ipconns:2000");
header("userrate:3000");
header("iprate:8000");
header("UPSTREAM:http://127.0.0.1:3500?parent-type=tcp");
header("HTTP/1.1 204 No Content");
}
```
#### 解释
userconns:用户的最大连接数,不限制为0或者不设置这个头部。
ipconns:用户IP的最大连接数,不限制为0或者不设置这个头部。
userrate:用户的单个TCP连接速率限制,单位:字节/秒,不限制为0或者不设置这个头部。
iprate:用户IP的单个TCP连接速率限制,单位:字节/秒,不限制为0或者不设置这个头部。
upstream:使用的上级,没有为空,或者不设置这个头部。
#### 提示
1.默认情况下,设置了`--auth-url`是强制要求客户端提供用户名和密码的;如果不需要强制要求客户端提供用户名密码,并认证,可以加上`--auth-nouser`,每次访问仍然会访问认证地址`--auth-url`进行认证,当客户端没有发生认证信息当时候,php接口里面接收的$user认证用户名和$pass认证密码都为空。
2.连接数限制优先级:用户认证文件连接数限制-》文件ip.limit连接数限制-》API用户连接数限制-》API的IP连接数限制-》命令行全局连接数限制。
3.速率限制优先级:用户认证文件速率限制-》文件ip.limit速率限制-》API用户速率限制-》API的IP速率限制-》命令行全局速率限制。
3.上级获取优先级:用户认证文件的upstream-》文件ip.limit的upstream-》API的upstream-》命令行指定的上级。
4.`--auth-cache`认证缓存,对认证结果缓存一定时间,提升性能,降低认证接口压力,--auth-cache 单位秒,默认0, 设置0是关闭缓存。
#### upstream详细说明
1.当参数`sps`是0的时候。
service是http时,upstream只支持http(s)代理,不支持认证,如需要认证可以用sps代替,格式:
`http://127.0.0.1:3100?argk=argv`
service是socks时,upstream只支持socks5代理,格式:
`socks5://127.0.0.1:3100?argk=argv`
解释:`http://``socks5://` 是固定的,`127.0.0.1:3100`是上级的地址
2.当`sps`是1的时候。
upstream支持socks5、http(s)代理,支持认证,格式:`protocol://a:b@2.2.2.2:33080?argk=argv`,具体介绍请参考SPS章节的,**多个上级**,`-P`参数的说明。
3.参数,`?`后面`argk=argv`是参数:参数名称=参数值,多个参数用`&`连接。
支持的所有参数如下,和命令行同名参数意义一致。
1. parent-type : 上级底层传输类型,支持 tcp,tls,ws,wss。
2. parent-ws-method : 上级底层ws传输类型的加密方法,支持的值和命令行支持的值范围一样。
3. parent-ws-password : 上级底层ws传输类型的加密密码,数字字母组成的密码。
4. parent-tls-single : 上级底层tls传输类型是否是单向tls,可以是:true | false。
5. timeout : 建立tcp连接的超时时间,数字,单位毫秒。
6. ca : 上级底层tls传输类型的ca证书文件经过base64编码后的字符串。
7. cert : 上级底层tls传输类型的证书文件经过base64编码后的字符串。
8. key : 上级底层tls传输类型的证书密钥文件经过base64编码后的字符串。
### 流量上报/流量统计/流量限制
proxy的http(s)/socks5/sps/tcp/udp代理功能支持流量上报,可以通过参数`--traffic-url`设置一个http接口地址。
proxy会把连接使用的流量上报到这个地址,具体情况是,proxy发送一个HTTP到GET请求到`--traffic-url`设置的HTTP URL地址.
上报模式有两种,可以通过`--traffic-mode`参数指定,可以是`normal`普通模式上报,也可以是`fast`快速模式上报。
1. `normal`普通模式上报
当连接释放时,proxy会把此次连接使用的流量上报到这个`--traffic-url`地址.
2. `fast`快速模式上报
对已经建立的每个连接,proxy会`定时`把这个连接产生的流量上报到这个这个`--traffic-url`地址.
`定时`默认是5秒,可以通过参数`--traffic-interval`修改`定时`为合适的秒数。
流量上报功能结合上面的API认证功能可以实现实时控制用户的流量使用,流量统计,流量限制;流量上报到接口,接口把流量数据写入数据库,然后认证API查询数据库判断用户或者IP流量使用情况,用来确定用户是否可以认证成功.
下面是一个完整的URL请求实例:
`http://127.0.0.1:33088/user/traffic?bytes=337&client_addr=127.0.0.1%3A51035&id=http&server_addr=127.0.0.1%3A33088&target_addr=myip.ipip.net%3A80&username=a`
请求参数说明:
id: 服务id标志.
server_addr: 客户端请求的代理地址,格式: `IP:端口`.
client_addr: 客户端地址,格式: `IP:端口`.
target_addr: 目标地址,格式: `IP:端口`,tcp/udp代理时,这个是空.
username: 代理认证用户名,tcp/udp代理时,这个是空.
bytes: 此次使用的流量字节数.
#### 提示
访问的`--traffic-url`地址接口必须返回HTTP状态码`204`,流量上报才认为上报成功,返回其它状态码将认为上报流量失败,会输出相关日志。
#### 流量上报原理
![traffic](https://cdn.jsdelivr.net/gh/snail007/goproxy@masterhttps://gitee.com/snail/proxy/raw/master/doc/images/traffic.png)
### 主动断开用户连接
proxy的http(s)/socks5/sps代理功能支持`控制接口`,可以通过参数`--control-url`指定的http接口地址,
那么proxy就会`定期`的把当前连接到proxy的全部用户名或客户端IP发送到此URL,具体情况是,proxy发送一个HTTP的POST请求到`--control-url`设置的HTTP URL地址.`定期`默认是30秒,可以通过`--control-sleep`参数修改此值。
当用户过期,或者用户流量已经用完,通过认证API只能控制用户不能新建连接,但是已经和proxy建立当连接没法立刻断开,
那么通过控制接口可以解决这个问题,控制接口会在最慢`定期`时间内通过控制接口返回的内容,结束已经无效的用户建立的连接。
#### 控制接口请求说明
proxy会向控制接口URL发送一个HTTP POST请求,表单数据中有两个字段:user和ip。
user:当前连接到proxy的用户名,多个使用英文逗号分割,比如:user1,user2
ip:当前连接到proxy的客户端ip地址,多个使用英文逗号分割,比如:1.1.1.1,2.2.2.2
#### 控制接口返回数据说明
控制接口返回的数据是无效的用户和IP,格式是一个json对象数据,有两个字段user和ip。
比如:{"user":"a,b","ip":""}
user:当前连接到proxy的用户名,多个使用英文逗号分割,没有留空,比如:user1,user2
ip:当前连接到proxy的客户端ip地址,多个使用英文逗号分割,没有留空,比如:1.1.1.1,2.2.2.2
返回的用户和ip已经建立的连接会被proxy断开。
#### 示例
假设--control-url `http://127.0.0.1:33088/user/control.php` 指向了一个php接口地址.
control.php内容如下:
```php
<?php
#接收proxy post过来的数据
$userArr=explode(",",$_POST['user']);
$ipArr=$_GET['ip'];
//无效用户列表
$badUsers=[];
foreach ($userArr as $user) {
//逻辑判断用户$user是否无效,如果无效就放入$badUsers
$badUsers[]=$user;
}
$data=["user"=>implode(","$badUsers),"ip"=>""];
echo json_encode($data);
```
### 使用代理
http(s)/socks5/sps认证API(`--auth-url`)、控制API(`--control-url`)、流量上报API(`--traffic-url`)三个地址的访问,支持通过代理访问,参数是:`--auth-proxy`,格式和`--jumper`格式一致,详细详细请参考`--jumper`。
## 10.本地认证,限速,控制连接数
proxy的http(s)/socks5/sps代理功能,支持通过配置文件控制用户对代理对访问,支持开启http(s)代理``Proxy Basic 代理认证`,socks5代理认证。
### 开始使用
proxy的http(s)/socks5/sps代理功能可以通过
`--auth-file``--max-conns``--ip-limit``--rate-limit``-a`这五个参数控制。
#### 参数详细解释
##### `--auth-file`
认证的用户名和密码文件,该参数指定一个文件,一行一条规则,格式是:"用户名:密码:连接数:速率:上级"。
`连接数`是用户最大连接数,`速率`是用户每个tcp连接最大速度,单位是:字节/秒,`上级`是用户使用的上级。
不仅可以通过`--auth-file`设置认证用户,也可以直接用`-a`参数设置,多个用户就重复多个`-a`参数即可。
比如:`proxy http -a a:b:0:0: -a c:d:0:0:`
实例解释:
比如:`user:pass:100:10240:http://192.168.1.1:3100`
`user`是认证用户名
`pass`是认证用户密码(不能包含冒号:
`100`是这个用户的最大连接数,不限制写0
`10240`是这个用户单个tcp连接的速率限制,单位是:字节/秒,不限制写0
`http://192.168.1.1:3100`是这个用户使用的上级,没有就留空
##### `--max-conns`
限制代理服务的全局最大连接数,一个数字,0为不限制,默认0。
##### `--ip-limit`
控制客户端IP的连接数和连接速率,该参数指定一个文件,一行一条规则,#开头的是注视
示例文件ip.limit,规则格式如下:
`127.0.0.1:100:10240:http://192.168.1.1:3100`
规则解释:
`127.0.0.1`是要限制的IP
`100`是这个IP的最大连接数,不限制写0
`10240`是IP单个tcp连接的速率限制,单位是:字节/s,不限制写0
`http://192.168.1.1:3100`是这个IP使用的上级,没有就留空
##### `--rate-limit`
限制服务的每一个tcp连接的速度,比如:100K 2000K 1M . 0意味着无限制,默认0。
## 11.集群管理
proxy支持集群管理功能,此时proxy安装在每个机器节点上作为agent,配合控制面板[`proxyadmin集群版`](https://github.com/snail007/proxy-admin-cluster),就能够实现统一管理海量机器上的proxy服务。
proxy如果要作为agent运行,假设控制面板的集群端口地址是:`1.1.1.1:55333`.
命令示例如下:
`proxy agent -k xxx -c 1.1.1.1:55333 -i test`
命令解释:
agent : 是功能参数,表示运行agent模式。
-k :和`proxyadmin集群版`通讯加密解密的密钥,这个密钥是在`proxyadmin集群版`的配置文件里面设置的。
-c `proxyadmin集群版`的集群端口地址,格式:IP:端口。
-i agent唯一标识,保证每个agent的都不一样,此处指定的`唯一标识`,在控制面板添加节点的时候用到,IP一栏填写这个`唯一标识`
如果-i不指定,默认是空,控制面板添加节点的时候IP一栏填写:agent的出口IP。
-u: 代理参数,默认是空。可以指定一个代理,agent会通过这个代理与cluster通讯。
格式和`--jumper`格式一致,详细情况请参考手册中`--jumper`部分。
提示:
1.当控制面板里面配置了client服务,那么所有节点都使用相同都key那么就导致,只有一个client可以工作,为了解决这个问题,
client服务参数里面可以通过使用占位符:`{AGENT_ID}`引用agent的id当作client的key,这样就可以保证每个客户端都有唯一的key。
比如client服务参数:
`client -T tcp -P 1.1.1.1:30000 --k {AGENT_ID}`
2.如果使用了代理参数`-u`,务必设置唯一标示参数`-i`,不然cluster无法区分不同的agentagent将不能正常工作。