howtoe.html 35 KB

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