howtoe.html 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. <ul>
  2. <li>3APA3A 3proxy tiny proxy server HowTo
  3. <br>Under construction, very incomplete
  4. <ul>
  5. <li><A HREF="#COMPILE">Compilation</A>
  6. <ul>
  7. <li><A HREF="#MSVC">How to compile 3proxy with Visual C++</A>
  8. <li><A HREF="#INTL">How to compile 3proxy with Intel C Compiler under Windows</A>
  9. <li><A HREF="#GCCWIN">How to compile 3proxy with GCC under Windows</A>
  10. <li><A HREF="#GCCUNIX">How to compile 3proxy with GCC under Unix/Linux</A>
  11. <li><A HREF="#CCCUNIX">How to compile 3proxy with Compaq C Compiler under Unix/Linux</A>
  12. </ul>
  13. <li><A HREF="#INSTALL">Proxy server installation and removal</A>
  14. <ul>
  15. <li><A HREF="#INSTNT">How to install/remove 3proxy under Windows NT/2000/XP</A>
  16. <li><A HREF="#INST95">How to install/remove 3proxy under Windows 95/98/ME</A>
  17. <li><A HREF="#INSTUNIX">How to install/remove 3proxy under Unix/Linux</A>
  18. </ul>
  19. <li><A HREF="#SERVER">Server configuration</A>
  20. <ul>
  21. <li><A HREF="#SAMPLE">Where to find configuration example</A>
  22. <li><A HREF="#LOGGING">How to set up logging</A>
  23. <li><A HREF="#LOGFORMAT">How to setup logging format</A>
  24. <li><A HREF="#LOGANALIZERS">How to use log analizers with 3proxy</A>
  25. <li><A HREF="#LAUNCH">How to start any of proxy services (HTTP, SOCKS etc)</A>
  26. <li><A HREF="#BIND">How to bind service to specific interface and port?</A>
  27. <li><A HREF="#AUTH">How to limit service access</A>
  28. <li><A HREF="#USERS">How to create user list</A>
  29. <li><A HREF="#ACL">How to limit user access to resources</A>
  30. <li><A HREF="#REDIR">How to manage redirections</A>
  31. <li><A HREF="#ROUNDROBIN">How to balance traffic between few external channgels?</A>
  32. <li><A HREF="#CHAIN">How to manage proxy chains</A>
  33. <li><A HREF="#BANDLIM">How to limit bandwidth</A>
  34. <li><A HREF="#TRAFLIM">How to limit traffic amount</A>
  35. <li><A HREF="#NETLIST">How to build network lists</A>
  36. <li><a href="#NSCACHING">How to configure name resolution and DNS caching</a>
  37. <li><a href="#IPV6">How to use IPv6</a>
  38. <li><a href="#CONNBACK">How to use connect back</a>
  39. </ul>
  40. <li><A HREF="#CLIENT">Client configuration</A>
  41. <li><A HREF="#ADMIN">Administering and information analisys</A>
  42. <ul>
  43. <li><A HREF="#NEWVERSION">How to obtain latest 3proxy version</A>
  44. <li><A HREF="#NTSERVICE">How to control 3proxy service under Windows NT/2000/XP</A>
  45. <li><A HREF="#ERRORS">Log error codes reference</A>
  46. </ul>
  47. <li><A HREF="#QUEST">How To ask quiestion not in How To?</A>
  48. </ul>
  49. <br>
  50. <ul>
  51. <hr>
  52. <li><A NAME="COMPILE">Compilation</A>
  53. <p>
  54. <ul>
  55. <li><A NAME="MSVC">How to compile 3proxy with Visual C++</A>
  56. <p>
  57. Extract source code files from 3proxy.tgz (with WinZip or another utility).
  58. Use nmake /f Makefile.msvc command
  59. </p>
  60. <li><A NAME="INTL">How to compile 3proxy with Intel C Compiler under Windows</A>
  61. <p>
  62. See <A HREF="#MSVC">How to compile 3proxy with Visual C++</A>
  63. Use Makefile.intl instead of Makefile.msvc
  64. </p>
  65. <li><A NAME="GCCWIN">How to compile 3proxy with GCC under Windows</A></li>
  66. <p>
  67. Extract source files from 3proxy.tgz (for example with tar -xzf 3proxy.tgz command if you have tar installed)
  68. Use make -f Makefile.win command.
  69. If you want to use POSIX emulation Cygwin library (normally you shouldn't) - use make -f Makefile.unix instead.
  70. Windows specific things (like installing as service) will not be available if compiled with Cygwin emulation.
  71. </p>
  72. <li><A NAME="GCCUNIX">How to compile 3proxy with GCC under Unix/Linux</A></li>
  73. <p>
  74. Use
  75. <pre>
  76. make -f Makefile.Linux
  77. </pre>
  78. for Linux or Cygwin, Makefile.Solaris* (depending on compiler version) for Solaris
  79. and Makefile.unix for different Unix-like OS. On BSD derivered systems make
  80. sure to use GNU make, sometimes it's called gmake instead of make.
  81. <br>Compilation is tested under FreeBSD/i386, NetBSD/i386, OpenBSD/i386,
  82. RH Linux/Alpha, Debian/i386, Gentoo/i386, Gentoo/PPC, Solaris/x86 but you
  83. shouldn't have problems under different Solaris, BSD or linux compatible systems.
  84. For different systems you may be required to patch Makefile or even source codes.
  85. If you want to use ODBC support, make sure to install ODBC for unix, remove -DNOODBC
  86. option from makefile compiler options and add ODBC library to linker variable.
  87. </p>
  88. </ul>
  89. <hr>
  90. <li><A NAME="CCCUNIX">How to compile 3proxy with Compaq C Compiler under Unix/Linux</A></li>
  91. <p>
  92. See <A HREF="#GCCUNIX">How to compile 3proxy with GCC under Unix/Linux</A>, use Makefile.ccc instead of Makefile.unix.
  93. </p>
  94. </ul>
  95. <hr>
  96. <li><A NAME="INSTALL">Proxy server installation and removal</A>
  97. <p>
  98. <ul>
  99. <li><A NAME="INSTNT">How to install/remove 3proxy under Windows NT/2000/XP</A>
  100. <p>
  101. Unpack 3proxy.zip to any directory, for example
  102. c:\Program Files\3proxy. If needed, create directory for storing log files,
  103. ODBC sources, etc. Create 3proxy.cfg in the 3proxy installation directory (See <A HREF="#SERVER">Server configuration</A>).
  104. If you use 3proxy before 0.6 Add
  105. <pre>
  106. service
  107. </pre>
  108. string into 3proxy.cfg. Now, start command prompt (cmd.exe).
  109. Change directory to 3proxy installation and run 3proxy.exe --install:
  110. <pre>
  111. D:\>C:
  112. C:\>cd C:\Program Files\3proxy
  113. C:\Program Files\3proxy>3proxy.exe --install
  114. </pre>
  115. Now, you should have 3proxy service installed and running. If service is not
  116. started, remove "service" string from 3proxy.cfg, run 3proxy.exe manually
  117. and correct all errors.
  118. </p><p>
  119. To remove 3proxy run 3proxy --remove:
  120. <pre>
  121. D:\>C:
  122. C:\>cd C:\Program Files\3proxy
  123. C:\Program Files\3proxy>net stop 3proxy
  124. C:\Program Files\3proxy>3proxy.exe --remove
  125. </pre>
  126. Now you can simply remove 3proxy installation directory.
  127. </p>
  128. <li><A NAME="INST95">How to install/remove 3proxy under Windows 95/98/ME</A>
  129. <p>
  130. Unpack 3proxy.zip to any directory, for example
  131. c:\Program Files\3proxy. If needed, create directory for storing log files,
  132. ODBC sources, etc. Create 3proxy.cfg in the 3proxy installation directory (See <A HREF="#SERVER">Server configuration</A>).
  133. Remove string
  134. <pre>
  135. service
  136. </pre>
  137. from 3proxy.cfg and add
  138. <pre>
  139. daemon
  140. </pre>
  141. if you want 3proxy to run in background.
  142. Create shortcut for 3proxy.exe and place it in autostart or add
  143. to registry with regedit.exe:
  144. <br>HKLM\Software\Microsoft\Windows\CurrentVersion\Run</br>
  145. Type: String
  146. <br>3proxy = "c:\Program Files\3proxy.exe" "C:\Program Files\3proxy.cfg"<br>
  147. You must use quotes if path contains space. If neccessary, restart Windows.
  148. If service is not started, check log. Remove "daemon" command from 3proxy.cfg,
  149. start 3proxy.exe manually and correct all errors.
  150. </p>
  151. <li><A NAME="INSTUNIX">How to install/remove 3proxy under Unix/Linux</A>
  152. <p>
  153. Complie 3proxy (see <A HREF="#COMPILE">Compilation</A>). Copy
  154. executables to any appropriate location (for example /usr/local/3proxy/sbin
  155. for servers and /usr/local/3proxy/bin for utilities).
  156. Create /usr/local/etc/3proxy.cfg.
  157. (see <A HREF="#SERVER">Server configuration</A>).
  158. You can change default configuration file location by specifing configuration file
  159. in 3proxy command line.
  160. Add 3proxy to system startup scripts.
  161. </p>
  162. </ul>
  163. <hr>
  164. <li><A NAME="SERVER">Server configuration</A>
  165. <p>
  166. <ul>
  167. <li><A NAME="SAMPLE">Where to find configuration example</A>
  168. <p>
  169. Server configuration example 3proxy.cfg.sample is in any 3proxy distribution.
  170. </p>
  171. <li><A NAME="LOGGING">How to set up logging</A>
  172. <p>
  173. 3proxy can log to stdout, file, ODBC datasource and
  174. syslog (Unix/Linux/Cygwin only). For using ODBC under Unix/Linux you must
  175. compile 3proxy with Unix ODBC libraries, see <A HREF="#COMPILE">Compilation</A>.
  176. You can control logging from 3proxy.cfg for all services or you can control
  177. logging of individual service, for example
  178. /usr/local/sbin/socks -l/var/log/socks.log starts SOCKS proxy with logging to file.
  179. For universal proxy (3proxy) log file rotation and archiving is supported.
  180. Log type is defined with "log" configuration file command or with
  181. -l switch on individual service invokation. log or -l is stdout logging.
  182. <pre>
  183. log filename
  184. </pre>
  185. and
  186. <pre>
  187. -lfilename
  188. </pre>
  189. specify filename for logging
  190. <pre>
  191. log @ident
  192. </pre>
  193. and
  194. <pre>
  195. -l@ident
  196. </pre>
  197. specify ident for syslog logging. If filename within "log" command contains
  198. '%' characters, it's processes as format specificator (see "logformat"). E.g.
  199. log c:\3proxy\logs\%y%m%d.log D creates file like c:\3proxy\logs\060729.log,
  200. date is generated based on local time.
  201. <pre>
  202. log &connstring
  203. </pre>
  204. specifies ODBC connection string, connstring is in format
  205. datasource,username,password (2 last are optional of
  206. datasource does not require or already has authentication information).
  207. Also, you must specify logformat to build SQL query, to insert recod into
  208. log, see <A HREF="#LOGFORMAT">How to setup logging format</A>
  209. </p>
  210. <p>
  211. Rotation and archiving may be set up with log, rotate ¨ archiver commands
  212. <pre>
  213. log filename LOGTYPE
  214. </pre>
  215. sets rotation type. LOGTYPE may be:
  216. <ul>
  217. <li>M, monthely
  218. <li>W, weekly
  219. <li>D, daily
  220. <li>H, hourly
  221. <li>C, minutely
  222. </ul>
  223. <pre>
  224. rotate NUMBER
  225. </pre>
  226. specifies number of files in rotation (that is how many files to keep).
  227. <pre>
  228. archiver EXT COMMAND PARAMETERS
  229. </pre>
  230. Sets external archiver. EXT is extention of archived files
  231. (for example zip, gz, Z, rar etc) COMMAND and PARAMETERS are command
  232. to execute and command line PARAMETERS. Originale file is not deleted by
  233. 3proxy, this work is left for archiver.
  234. You can pass original filename to archiver with %F macro and archive filename with %A.
  235. Examples are located in
  236. 3proxy.cfg.sample
  237. </p>
  238. <li><A NAME="LOGFORMAT">How to setup logging format</A>
  239. <p>
  240. Since 0.3 version log format may be set with "logformat" command.
  241. First symbol of log format specifies format of date and time and
  242. should be L (LOCAL) or G (GMT - Grinwitch Meridian Time). Format
  243. string may contains some macro substitutions:
  244. <ul>
  245. <li> %y - Year (2 digits)
  246. <li> %Y - Year (4 digits)
  247. <li> %m - Month (2 digits)
  248. <li> %o - mOnth (3 letter abbriviation)
  249. <li> %d - Day (2 digits)
  250. <li> %H - Hour (2 digits)
  251. <li> %M - Minute (2 digits)
  252. <li> %S - Second (2 digits)
  253. <li> %t - Timestamp (seconds since January, 1 1970 00:00:00 GMT)
  254. <li> %. - Milliseconds
  255. <li> %z - Timezone in mail format (from GMT, '+' east, '-' west HHMM), For example Moscow winter time is +0300.
  256. <li> %U - Username ('-' if unknown).
  257. <li> %N - Service name (PROXY, SOCKS, POP3P, etc)
  258. <li> %p - Service port
  259. <li> %E - Error code (see. <A HREF="#ERRORS">Log error codes reference</A>)
  260. <li> %C - client IP
  261. <li> %c - client port
  262. <li> %R - target IP
  263. <li> %r - target port
  264. <li> %e - external IP address used to establish connection
  265. <li> %Q - requested IP
  266. <li> %q - requested port
  267. <li> %I - bytes received from target
  268. <li> %O - bytes sent to target
  269. <li> %n - host name from request
  270. <li> %h - hops before target (if redirection or chaning is used).
  271. see <A HREF="#CHAIN">How to use chains and parent proxies</A>)
  272. <li> %T - service specific text (for example URL requested). %X-YT
  273. where X and Y are positive numbers, only displays fields
  274. (space delimited) X to Y of the text. An example is %1-2T.
  275. </ul>
  276. Example:
  277. <pre>
  278. logformat "L%t.%. %N.%p %E %U %C:%c %R:%r %O %I %h %T"
  279. </pre>
  280. generates something like
  281. <p><font face="courier">
  282. 1042454727.0296 SOCK4.1080 000 3APA3A 127.0.0.1:4739 195.122.226.28:4739 505 18735 1 GET http://3proxy.org/ HTTP/1.1
  283. </font>
  284. <br>(no line breaks)
  285. </p>
  286. <p>
  287. If ODBC used, logformat should specify SQL command,
  288. to insert record into log, for example
  289. <p><pre>
  290. logformat "-\'+_GINSERT INTO proxystat VALUES (%t, '%c', '%U', %I)"</pre>
  291. <br>(no line breaks)
  292. <br>-\'+_ instructs to replace characters \ and ' with _
  293. </p>
  294. <li><A NAME="LOGANALIZERS">How to use log analizers with 3proxy</A>
  295. <p>
  296. Just make format of 3proxy logs compatible with format supported by your
  297. favourite log analizer. Examples of compatible logformats are:
  298. <br>
  299. For Squid access.log:
  300. <p><font face="courier">
  301. &quot;- +_G%t.%. %D %C TCP_MISS/200 %I %1-1T %2-2T %U DIRECT/%R application/unknown&quot;
  302. </p>
  303. or, more compatible format without %D
  304. <pre>
  305. &quot;- +_G%t.%. 1 %C TCP_MISS/200 %I %1-1T %2-2T %U
  306. DIRECT/%R application/unknown&quot;
  307. </pre>
  308. ISA 2000 proxy WEBEXTD.LOG (fields are TAB-delimited):
  309. <pre>
  310. &quot;- + L%C %U Unknown Y %Y-%m-%d %H:%M:%S
  311. w3proxy 3PROXY - %n %R %r %D
  312. %O %I http TCP %1-1T %2-2T - -
  313. %E - - -&quot;
  314. </pre>
  315. ISA 2004 proxy WEB.w3c (fields are TAB-delimited):
  316. <pre>
  317. &quot;- + L%C %U Unknown %Y-%m-%d %H:%M:%S
  318. 3PROXY - %n %R %r %D %O
  319. %I http %1-1T %2-2T - %E -
  320. - Internal External 0x0 Allowed&quot;
  321. </pre>
  322. ISA 2000/2004 firewall FWSEXTD.log (fields are TAB-delimited):
  323. <pre>
  324. &quot;- + L%C %U unnknown:0:0.0 N %Y-%m-%d
  325. %H:%M:%S fwsrv 3PROXY - %n %R %r
  326. %D %O %I %r TCP Connect - -
  327. - %E - - - - -&quot;
  328. </pre>
  329. HTTPD standard log (Apache and others):
  330. <p><font face="courier">
  331. &quot;-&quot;&quot;+_L%C - %U [%d/%o/%Y:%H:%M:%S %z] &quot;&quot;%T&quot;&quot; %E %I&quot;
  332. </p>
  333. or more compatible without error code
  334. <p><font face="courier">
  335. &quot;-&quot;&quot;+_L%C - %U [%d/%o/%Y:%H:%M:%S %z] &quot;&quot;%T&quot;&quot; 200 %I&quot;
  336. </p>
  337. <li><A NAME="LAUNCH">How to start any of proxy services (HTTP, SOCKS etc)</A>
  338. <p>
  339. 3proxy is distributed in 2 variants: as a set of standalone modules (proxy,
  340. socks, pop3p, tcppm, udppm) and as universal proxy server. These services are
  341. absolutely independant, and if you use 3proxy you needn't any of standalone
  342. modules.
  343. <br>Standalone modules are only configurable via command line interface while
  344. 3proxy uses configuration file. Many functions, such as ODBC logging, log
  345. rotation, access control, etc are only available in 3proxy, not in standalone
  346. proxies.
  347. Standalone module may be started from command line, for example:
  348. <pre>
  349. $/sbin/socks -l/var/log/socks.log -i127.0.0.1
  350. </pre>
  351. Starts SOCKS server binded to localhost ip, port 1080 with logging to
  352. /var/log/socks.log.
  353. You can get help for any standalone service with -? command line option.
  354. </p><p>
  355. If 3proxy is used you should start all services in 3proxy.cfg file. 3proxy.cfg
  356. is executed by 3proxy as a batch file. Example of 3proxy.cfg and command syntaxys
  357. can be found in
  358. 3proxy.cfg.sample.
  359. <pre>
  360. log /var/log/3proxy.log D
  361. rotate 30
  362. internal 127.0.0.1
  363. external 192.168.1.1
  364. proxy
  365. socks -p3129
  366. pop3p
  367. </pre>
  368. Starts 3 services: HTTP PROXY, SOCKS and POP3 PROXY. Each listens localhost
  369. interface with default port (3128 for HTTP, 1080 for SOCKS and 110 for POP3P)
  370. except socks started with port 3129.
  371. All logs are in file /var/log/3proxy.log (with daily date modification and
  372. rotation). 30 last files are stored.
  373. </p>
  374. <li><A NAME="BIND">How to bind service to specific interface and port?</A>
  375. <p>
  376. -i options specifies internal interface, -p - listening port. No space are
  377. allowed. To bind 'proxy' service to port 8080 on interfaces 192.168.1.1
  378. and 192.168.2.1 use
  379. <pre>
  380. proxy -p8080 -i192.168.1.1
  381. proxy -p8080 -i192.168.2.1
  382. </pre>
  383. </p>
  384. <li><A NAME="AUTH">How to limit service access</A>
  385. <p>
  386. First, always specify internal interface to accept incoming connection with
  387. 'internal' configuration command or '-i' service command. (See
  388. <A HREF="#LAUNCH">How to start any of proxy services (HTTP, SOCKS etc)</A>). If
  389. no internal interface is specified your proxy will act as open one.
  390. <p>It's also important to specify external interface to prevent access to
  391. internal network with 'external' or -e.
  392. <p>3proxy with configuration files allows to use authentication and
  393. authorization for user's access. Authentication is possible by
  394. username/password or user's NetBIOS name. Authentication type is specified by
  395. 'auth' command.
  396. <pre>
  397. auth none
  398. </pre>
  399. Disables both authentication and authorization. You can not use ACLs.
  400. <pre>
  401. auth iponly
  402. </pre>
  403. Specifies no authentication, ACLs authorization is used.
  404. <pre>
  405. auth nbname
  406. </pre>
  407. Authentication by NetBIOS name + ACLs. NetBIOS name of 'messenger' service
  408. is obrained before ACL validation. If no name is obtained it's assumed to be
  409. empty. Messenger is started by default in Windows NT/2000/XP. For Win9x
  410. WinPopUP need to be launched. This type of authentication may be spoofed
  411. by privileged local user.
  412. <pre>
  413. auth strong
  414. </pre>
  415. Authentication by username/password. If user is not registered his
  416. access is denied regardless of ACLs.
  417. <p>
  418. Different services can have different authentication levels.
  419. <pre>
  420. auth none
  421. pop3p
  422. auth iponly
  423. proxy
  424. auth strong
  425. socks
  426. </pre>
  427. It's possible to authorize access by client IP address, IP address or requested resource,
  428. target port, time, etc after authentication.
  429. (See <A HREF="#ACL">How to limit resource access</A>).
  430. </p><p>Since 0.6 version double authentication is possible, e.g.
  431. <pre>
  432. auth iponly strong
  433. allow * * 192.168.0.0/16
  434. allow user1,user2
  435. proxy
  436. </pre>
  437. strong authentication will only be used if ACL requires username to deside if
  438. access must be granted. That is, in example, strong username authentication
  439. is not required to access 192.168.0.0/16
  440. </p><p>0.6 version introduces authentication (username) caching to increase
  441. productivity. It's recommended to use authentication caching with resource
  442. or time consuming authentication types, such as nbname or external plugins
  443. (WindowsAuthentication).
  444. Caching can be set with 'authcache' command with 2 parameters: caching type
  445. and caching time (in seconds). Caching type defines the type of cached access:
  446. 'ip' - after successful authentication all connections during caching time
  447. from same IP are assigned to the same user, username is not requested.
  448. "ip,user" - username is requested and all connections from the same IP are
  449. assigned to the same user without actual authentication. "user" - same as above,
  450. but IP is not checked. "user,password" - username and password are checked
  451. against cached ones. For authentication special authentication type 'cache'
  452. must be used.
  453. Example:
  454. <pre>
  455. authcache ip 60
  456. auth cache strong windows
  457. proxy -n
  458. </pre>
  459. </p>
  460. Please note, that caching affects security. Never use caching for access to
  461. critical resources, such as web administration.
  462. <p>authcache can be used to bind user's sessions to ip with 'limit' option, with
  463. <pre>
  464. autchcache ip,user,pass,limit 120
  465. auth cache strong</pre>
  466. user will not be able to use more than a single IP during cache time (120 sec).
  467. </p>
  468. <li><A NAME="USERS">How to create user list</A>
  469. <p>
  470. Userslist is created with 'users' command.
  471. <pre>
  472. users USERDESC ...
  473. </pre>
  474. With a single command it's possible to define few users, or you
  475. can use few 'users' commands. USERDESC is user description. Description
  476. consists of three semicolon delimited parts - login, password type and
  477. <pre>
  478. users admin:CL:bigsecret test:CL:password test1:CL:password1
  479. users "test2:CR:$1$lFDGlder$pLRb4cU2D7GAT58YQvY49."
  480. users test3:NT:BD7DFBF29A93F93C63CB84790DA00E63
  481. </pre>
  482. Please note the usage of quotation sign: it's required to comment out $ sign
  483. overwise used as a file inclusion macro.
  484. Next password types are available:
  485. <ul>
  486. <li>No password type: use system authentication.
  487. <li>CL - cleartext password
  488. <li>CR - crypt password, only MD5 crypt passwords are supported
  489. <li>NT - NT-hashed (MD4) passwords in hex, as used in pwdump or SAMBA
  490. </ul>
  491. NT and crypt passwords can be used to import accounts from Windows/SAMBA or
  492. Unix. For Windows you can use pwdump family of utilities.
  493. It's convenient to store accounts apart and include account file with $ macro.
  494. Because for included files newlines are treated as a space, it's possible to
  495. use atandard passwd file format:
  496. <pre>
  497. users $/etc/.3proxypasswd
  498. </pre>
  499. or
  500. <pre>
  501. users $"c:\Program Files\3proxy\passwords"
  502. </pre>
  503. It's possible to create NT and crypt passwords with mycrypt utility included
  504. in distribution.
  505. <br>Userlist is system-wide. To manage user access to specific service use ACLs.
  506. </p>
  507. <li><A NAME="ACL">How to limit user access to resources</A>
  508. <p>
  509. Commands allow, deny and flush are used to manage ACLs:
  510. <p><font face="courier">
  511. allow &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt; &lt;weekdaylist&gt; &lt;timeperiodlist&gt;
  512. <br>deny &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;weekdaylist&gt; &lt;timeperiodlist&gt;
  513. <br>flush
  514. </font>
  515. </p>
  516. 'flush' command is used to finish with existing ACL and to start new one.
  517. It's required to have different ACLs for different services.
  518. 'allow' is used to allow connection and 'deny' to deny connection. 'allow'
  519. command can be extended by 'parent' command to manage redirections (see <A NAME="REDIR">How to manage redirections</A>)). If ACL
  520. is empty it allow everything. If ACL is not empty, first matching ACL entry
  521. is searched for user request and ACL action (allow or deny) performed. If
  522. no matching record found, connection is denied and user will be asked to
  523. re-authenticate (requested for username/password). To prevent this request
  524. add 'deny *' to the end of list.
  525. <ul>
  526. <li>&lt;userlist&gt; - comma delimited list of users
  527. <li>&lt;sourcelist&gt; - comma delimited list of source (client) networks.
  528. Networks can be defined as single IP address or in CIDR form
  529. xxx.yyy.zzz.mmm/l, where l - is the length of network mask
  530. (a number of non-zero bits). 192.168.1.0/24
  531. means network with 255.255.255.0 mask.
  532. <li>&lt;targetlist&gt; - comma delimited list of target (server) networks.
  533. In 3proxy 0.6 and above it's allowed to use hostnames with wildmasks
  534. in targetlist. Wildmask may only present in the begginning or at the
  535. end of the hostname, e.g.
  536. 192.168.0.0/16,www.example.com,*wrongsite.com,*wrongcontent*.
  537. <li>&lt;targetportlist&gt; - comma delimited list of ports. I
  538. It's possible to define port ranges with -, e.g. 80,1024-65535
  539. means port 80 and all unprivileged ports.
  540. <li>&lt;commandlist&gt; - the list of allowed actions
  541. <br> CONNECT - establish outgoing TCP connection. e.g. POP3 or SOCKSv5
  542. <br> BIND - allow incoming TCP connection (SOCKSv5)
  543. <br> UDPASSOC - create UDP association (SOCKSv5)
  544. <br> ICMPASSOC - create ICMP association (not implemented)
  545. <br> HTTP_GET - HTTP GET request (HTTP proxy)
  546. <br> HTTP_PUT - HTTP PUT request (HTTP proxy)
  547. <br> HTTP_POST - HTTP POST request (HTTP proxy)
  548. <br> HTTP_HEAD - HTTP HEAD request (HTTP proxy)
  549. <br> HTTP_CONNECT - HTTP CONNECT, aka HTTPS request (HTTP proxy)
  550. <br> HTTP_OTHER - another HTTP request (HTTP proxy)
  551. <br> HTTP - any HTTP request except HTTP_CONNECT (HTTP proxy)
  552. <br> HTTPS - alias to HTTP_CONNECT (HTTP proxy)
  553. <br> FTP_GET - FTP get request (http, ftp proxy)
  554. <br> FTP_PUT - FTP put request (ftp proxy)
  555. <br> FTP_LIST - FTP list request (http, ftp proxy)
  556. <br> FTP - any FTP request
  557. <br> ADMIN - administration interface access
  558. <p>
  559. <li>&lt;weeksdays&gt; - week days numbers or periods (0 or 7 means Sunday, 1 is Monday, 1-5 means Monday through Friday).
  560. <li>&lt;timeperiodlists&gt; - a list of time periods in HH:MM:SS-HH:MM:SS format. For example,
  561. 00:00:00-08:00:00,17:00:00-24:00:00 lists non-working hours.
  562. </ul>
  563. * in ACL means &quot;any&quot;.
  564. Usage examples could be found in 3proxy.cfg.sample.
  565. </p>
  566. <li><A NAME="REDIR">How to manage redirections</A>
  567. <p>
  568. Redirections are usefull to e.g. forward requests from specific clients
  569. to different servers or proxy server. Additionally, redirections are usefull
  570. to convert proxy interface from ont format to another, e.g. requests from
  571. SOCKS proxy can be redirected to parent HTTP proxy, or SOCKSv5 client can be
  572. redirected to SOCKSv4 proxy.
  573. <br>Because 3proxy understand "transparent" web request, it can be used as an
  574. intermediate software between HTTP proxy and NAT server for transparent HTTP
  575. forwarding, because it can convert "Web server" request issued by client to
  576. "proxy request" required by proxy server. A simplest redirection is:
  577. <pre>
  578. auth iponly
  579. allow *
  580. parent 1000 http 192.168.1.1 3128
  581. proxy
  582. </pre>
  583. All trafiic of HTTP proxy is redirected to parent proxy 192.168.1.1 port 3128.
  584. <br>If port number is '0', IP address from 'parent' is used as external address
  585. for this connection (that is like -eIP, but only for connections matching
  586. 'allow').
  587. <br>Special case of redirection are local redirections. In this case both IP is
  588. 0.0.0.0 and port is 0. It's only usseful with SOCKS service. In this case no
  589. new connection is established, but request is parsed by corresponding local
  590. service. E.g.:
  591. <pre>
  592. auth iponly
  593. allow * * * 80
  594. parent 1000 http 0.0.0.0 0
  595. allow * * * 21
  596. parent 1000 ftp 0.0.0.0 0
  597. allow * * * 110
  598. parent 1000 pop3 0.0.0.0 0
  599. socks
  600. </pre>
  601. In this case all SOCKS traffic with destination port 80 is forwarded to local
  602. 'proxy' service, destination port 21 to 'ftppr' and 110 to 'pop3pr'. There is
  603. no need to run these services expicitly. Local redirections are usefull if
  604. you want to see and control via ACLs protocol specific parameters, e.g.
  605. filenames requests thorugh FTP while clients are using SOCKS.
  606. </p>
  607. <li><A NAME="ROUNDROBIN">How to balance traffic between few external channgels?</A>
  608. <p>
  609. Proxy itself doesn't manage network level routing. The only way to control
  610. outgoing channel is to select external interface. It's possible to make
  611. external interface (what is usually selected with 'external' command or
  612. '-e' option) random by using local redirection with external port 0.
  613. <pre>
  614. auth iponly
  615. allow *
  616. parent 500 http 10.1.1.101 0
  617. parent 500 http 10.2.1.102 0
  618. </pre>
  619. Now external interface is randomly selected with 0.5 probability between
  620. 10.1.1.101 and 10.2.1.102. To work as expected, different default routes
  621. must between 2 interfaces.
  622. used
  623. <p>
  624. If both interface addresses are in same network, e.g. 10.1.1.101 and 10.1.1.102
  625. and you want to select random gateway between 10.1.1.1 and 10.1.1.2, you must
  626. control it by using routing table, in case there is no default gateway route
  627. for Windows:
  628. <pre>
  629. route add -p 10.1.1.1 10.1.1.101
  630. route add -p 10.1.1.2 10.1.1.102
  631. route add -p 0.0.0.0 mask 0.0.0.0 192.168.1.1
  632. route add -p 0.0.0.0 mask 0.0.0.0 192.168.1.2
  633. </pre>
  634. If you have no second address yet, just add it. Under Linux/Unix it's better
  635. to use source routing.
  636. </p>
  637. <li><A NAME="CHAIN">How to manage proxy chains</A>
  638. <p>
  639. parent command may also be used to build a proxy chains. In this case
  640. few 'parent' commands are used for single 'allow' rule with different
  641. weights (first argument of parent command). Chain may contain any number
  642. of proxy servers, but it should be noted that every hope significantly
  643. reduces productivity. It's possible to mix different types of proxy within
  644. single chain: HTTPS (HTTP connect), SOCKS4, SOCKS5. Weight different from
  645. 1000 is used to build random chains. if weight W is below 1000, this proxy
  646. will be used as a next chain hop with probability of W/1000. That is, if
  647. the weight is 250 probability this proxy will be used for the next hope is
  648. 25%. 'parent' records with common weight of 1000 establish a group, one of
  649. these record will be used for the hop with probability according to weight.
  650. Warning: each group must have a weight even of 1000. As follows, common
  651. weight of all 'parent' records must also be even of 1000. If common weight
  652. of 'parent' records in te chain is 3000, chain has 3 hops and must be formed
  653. of 3 groups. Example:
  654. <pre>
  655. allow *
  656. parent 500 socks5 192.168.1.1 1080
  657. parent 500 connect 192.168.10.1 3128
  658. </pre>
  659. In this case we have 1 parent proxy (1 hop) which is randomely choosen between
  660. 2 hosts: 192.168.1.1 and 192.168.10.1. 2 records form a single group.
  661. <pre>
  662. allow * * * 80
  663. parent 1000 socks5 192.168.10.1 1080
  664. parent 1000 connect 192.168.20.1 3128
  665. parent 300 socks4 192.168.30.1 1080
  666. parent 700 socks5 192.168.40.1 1080
  667. </pre>
  668. In this case we have 3 groups (3 hops in the chain). First hop is 192.168.10.1,
  669. second hop is 192.168.20.1 and 3rd one is either 192.168.30.1 with probability
  670. of 30% or 192.168.40.1 with probability of 70%.
  671. </p>
  672. <li><A NAME="BANDLIM">How to limit bandwidth</A>
  673. <p>
  674. 3proxy supports bandwidth filters. To manage filters bandlimin/bandlimout and
  675. nobandlimin/nobandlimout. 'in' means incoming and 'out' - outgoing traffic.
  676. <p><font face="courier">
  677. bandlimin &lt;bitrate&gt; &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  678. <br>nobandlimin &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  679. </font>
  680. </p>
  681. Commands are applied to all services. Imagine bandwidth filters as a series of
  682. pipes. Bitrate is a pipe's width and ACLs controls the flow thorugh this pipe.
  683. <pre>
  684. bandlimin 57600 * 192.168.10.16
  685. bandlimin 57600 * 192.168.10.17
  686. bandlimin 57600 * 192.168.10.18
  687. bandlimin 57600 * 192.168.10.19
  688. </pre>
  689. Create 4 separete pipes for 4 client with emulation of modem connection.
  690. <pre>
  691. bandlimin 57600 * 192.168.10.16/30
  692. </pre>
  693. Create single pipe for all 4 clients. That is 4 clients share modem connection.
  694. In this example:
  695. <pre>
  696. nobandlimin * * * 110
  697. bandlimin 57600 * 192.168.10.16/32
  698. </pre>
  699. mail traffic from POP3 servers bypasses the pipe and has no bandwidth
  700. limitation.
  701. </p>
  702. <li><A NAME="TRAFLIM">How to limit traffic amount</A>
  703. <p>
  704. <p><font face="courier">
  705. counter &lt;filename&gt; &lt;type&gt; &lt;reportpath&gt;
  706. <br>countin &lt;number&gt; &lt;type&gt; &lt;amount&gt; &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  707. <br>nocountin &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  708. <br>countout &lt;number&gt; &lt;type&gt; &lt;amount&gt; &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  709. <br>nocountout &lt;userlist&gt; &lt;sourcelist&gt; &lt;targetlist&gt; &lt;targetportlist&gt; &lt;commandlist&gt;
  710. </font>
  711. </p>
  712. <p>
  713. You can set traffic limit per day (D), week (W), month (M), year (Y) or
  714. absolute ('N'), as specified by 'type' argument of counterin command.
  715. Traffic information is stored in binary file specified by 'filename' argument.
  716. countersutil utility can be used to manage this file.
  717. reportpath specifies location of text reports, type parameter of 'counter'
  718. command controls how often text reports are created. amount is amount of
  719. allowed traffic in Megabytes (MB). nocountin allows you to set exclusions.
  720. </p>
  721. <li><A NAME="NETLIST">How to build network lists</A>
  722. <p>Networks or users lists are often very huge. 3proxy doesn't currently
  723. supports user groups, but ones can be created by the means of include files.
  724. You can store comma-delimited lists of networks or users in the separate
  725. file and use $ macro to insert this list into 3proxy.cfg.
  726. 3proxy comes with 'dighosts'
  727. utility. This utility helps to grab the list of the network from HTTP page.
  728. It may be usefull to e.g. obtain a regullary updated list of local networks
  729. from ISP's server. A network list can be either in form of NETWORK MASK,
  730. e.g. 192.168.1.0 255.255.255.0 or NETWORK/LENGTH, e.g. 192.168.1.0/24. You can
  731. launch dighosts from 3proxy.cfg to be executed on every 3proxy startup or
  732. configuration reload:
  733. <pre>
  734. system "dighosts http://provider/network.html local.networks"
  735. allow * * $local.networks
  736. allow *
  737. parent 1000 proxy.provider 3128 *
  738. proxy
  739. flush
  740. </pre>
  741. In this example we obtain list of local networks from provider's page to
  742. local.networks file, allow direct access to these networks and redirect all
  743. connection to external networks to provider's proxy.
  744. </p>
  745. <li><a name="NSCACHING"><i>How to configure name resolution and DNS caching</i></a>
  746. <p>
  747. For name resolution and caching use commands nserver, nscache / nscache6 and nsrecord.
  748. <pre>
  749. nserver 192.168.1.2
  750. nserver 192.168.1.3:5353/tcp</pre>
  751. sets DNS resolvers. 192.168.1.3 will be used via TCP/5353 (instead of default UDP/53)
  752. only if 192.168.1.2 fails. Up to 5 nservers may be specified.
  753. If no nserver is configured, default system name resolution functions are used.
  754. <pre>
  755. nscache 65535
  756. nscache6 65535</pre>
  757. sets name cache size for IPv4 and IPv6. Name cache must be large enouth, if presents.
  758. name cache is only used if nserver is configured.
  759. <pre>
  760. nsrecord server.mycompany.example.com 192.168.1.1
  761. nsrecord www.porno.com 127.0.0.2
  762. ...
  763. deny * * 127.0.0.2</pre>
  764. adds static nsrecords. Also, static nsrecords are used for dnspr, unless -s option is specified.
  765. Since 0.8 version, parent proxy may be configured for dnspr.
  766. </p>
  767. <li><a name="IPV6"><i>How to use IPv6</i></a>
  768. <p>
  769. IPv6 is supported since 0.8. Please note, some proxy protolos, e.g. SOCKSv4,
  770. do not support IPv6. SOCKSv5 supports IPv6 with special request type (must be
  771. implemented by client).
  772. <br>
  773. 3proxy supports proxying from IPv4 and IPv6 networks to IPv4,
  774. IPv6 and mixed networks. IPv6 address may be used in
  775. internal, external, parent commands, ACLs, -i and -e options,etc.
  776. external command and -e options may be given twice for each service - once with IPv4
  777. and once with IPv6 address. internal can be given only once, to bind to all IPv4 and
  778. IPv6 addresses use [0:0:0:0:0:0:0:0] or [::].
  779. <br>
  780. Any service may be configured with -4, -46, -64, -6 options to specify decied
  781. priority for name to IPv4/IPv6 address resolution (IPv4 only, IPv4 priority,
  782. IPv6 priority, IPv6 only).
  783. </p>
  784. <li><a name="CONNBACK"><i>How to use connect back</i></a>
  785. <p>
  786. In example, users needs access from external network to proxy server located
  787. on the host 192.168.1.2. This host can not be accessed from external network,
  788. but it has access to external network with with external address 1.1.1.1.
  789. Also, user has access to the host 2.2.2.2 (IP address may be dynamic) with
  790. hostname host.dyndns.example.org via external network. User needs 2 instances
  791. of 3proxy, first one on the host 192.168.1.2 with config
  792. <pre>
  793. users user:CL:password
  794. auth strong
  795. allow user
  796. proxy -rhost.dyndns.example.org:1234</pre>
  797. second one on the host.dyndns.example.org (2.2.2.2) with config
  798. <pre>
  799. auth iponly
  800. allow * * 1.1.1.1
  801. tcppm -R0.0.0.0:1234 3128 1.1.1.1 3128</pre>
  802. For browser settings proxy is host.dyndns.example.org:3128.
  803. </p>
  804. </ul>
  805. <hr>
  806. <li><A NAME="CLIENT">Client configuration</A>
  807. <p>
  808. <hr>
  809. <li><A NAME="ADMIN">Administering and information analisys</A>
  810. <p>
  811. <ul>
  812. <li><A NAME="NEWVERSION">How to obtain latest 3proxy version</A>
  813. <p>
  814. Latest version of 3proxy may be obtained
  815. <A HREF="http://3proxy.org/">here</A>.
  816. New version may have changes and incompatibilities with previous one in files
  817. format or commands. Please, read CHANGELOG file and another documentation
  818. before installing new version.
  819. </p>
  820. <li><A NAME="NTSERVICE">How to control 3proxy service under Windows NT/2000/XP</A>
  821. <p>
  822. If installed as system service, 3proxy understands Windows service commands
  823. for START, STOP, PAUSE and RESUME. If service is PAUSEd, no new connections
  824. are accepted while older connections are processed. Currently there is no
  825. support for dynamic configuration change, so, you have to restart service
  826. completely if you have changed any configuration.
  827. You can control 3proxy service via "Services" administration ot via "net" command:
  828. <pre>
  829. net start 3proxy
  830. net stop 3proxy
  831. net pause 3proxy
  832. net continue 3proxy
  833. </pre>
  834. </p>
  835. <li><A NAME="ERRORS">Log error codes reference</A>
  836. <p>
  837. <ul>
  838. <li>0 - Operation successfully complited (connection
  839. was closed by one of peers)
  840. <li>1-9 - AUTHENTICATION ERRORS
  841. <li>1 - Access denied by ACL (deny)
  842. <li>2 - Redirection (should not appear)
  843. <li>3 - No ACL found, denied by default
  844. <li>4 - auth=strong and no username in request
  845. <li>5 - auth=strong and no matching username in configuration
  846. <li>6 - User found, wrong password (cleartext)
  847. <li>7 - User found, wrong password (crypt)
  848. <li>8 - User found, wrong password (NT)
  849. <li>9 - Redirection data not found (should not appear)
  850. <li>10 - Traffic limit exceeded
  851. <li>11-19 - CONNECTION ERRORS
  852. <li>11 - failed to create socket()
  853. <li>12 - failed to bind()
  854. <li>13 - failed to connect()
  855. <li>14 - failed to getpeername()
  856. <li>20-29 - COMMON ERRORS
  857. <li>21 - memory allocation failed
  858. <li>30-39 - CONNECT PROXY REDIRECTION ERRORS
  859. <li>31 - failed to request HTTP CONNECT proxy
  860. <li>32 - CONNECT proxy connection timed out or wrong reply
  861. <li>33 - CONNECT proxy fails to establish connection
  862. <li>34 - CONNECT proxy timed out or closed connection
  863. <li>40-49 - SOCKS4 PROXY REDIRECTION ERRORS
  864. <li>50-69 - SOCKS5 PROXY REDIRECTION ERRORS
  865. <li>70-79 PARENT PROXY CONNECTION ERRORS (identical to 1x)
  866. <li>90-99 - established connection errors
  867. <li>since 0.9
  868. <li>90 - unexpected system error (should not happen)
  869. <li>91 - unexpected poll error (should not happen)
  870. <li>92 - connection terminated by timeout (see timeouts)
  871. <li>93 - connection terminated by ratelimit-related timeout
  872. <li>94 - connection termination by server or client with unsent data
  873. <li>95 - dirty connection termination by client (or networking issue)
  874. <li>96 - dirty connection termination by server (or networking issue)
  875. <li>97 - dirty connection termination by both client and server (probably networking issue)
  876. <li>prior to 0.9:
  877. <li>90 - socket error or connection broken
  878. <li>91 - TCP/IP common failure
  879. <li>92 - connection timed out
  880. <li>93 - error on reading data from server
  881. <li>94 - error on reading data from client
  882. <li>95 - timeout from bandlimin/bandlimout limitations
  883. <li>96 - error on sending data to client
  884. <li>97 - error on sending data to server
  885. <li>98 - server data limit (should not appear)
  886. <li>99 - client data limit (should not appear)
  887. <li>100 - HOST NOT FOUND
  888. <li>200-299 - UDP portmapper specific bugs
  889. <li>300-399 - TCP portmapper specific bugs
  890. <li>400-499 - SOCKS proxy specific bugs
  891. <li>500-599 - HTTP proxy specific bugs
  892. <li>600-699 - POP3 proxy specific bugs
  893. <li>999 - NOT IMPLEMENTED
  894. </ul>
  895. </p>
  896. </ul>
  897. <hr>
  898. <li><A NAME="QUEST">How To ask quiestion not in How To?</A>
  899. <p>
  900. Ask it in <A HREF="https://github.com/z3APA3A/3proxy/issues">Github</A>.
  901. Don't try to ask something before reading this document.
  902. </ul>
  903. </ul>