Linux下安装配置Cntlm代理

有些公司,上网有限制,却没有统一配置网关和路由,只是提供了上外网的代理。IT设施的不完善,只能让员工自己想办法。当然,也有些情况是特殊的网络策略与权限管理所致。
Cntlm是一个HTTP二级代理软件。它主要的作用,是在能代理上网的前提下,给这个代理再做一个代理,提供给更多的下级用户。下级用户不需要、也不可能知道代理的账户密码,这样既保障了安全、又实现了方便。
安装
以Debian系的安装为例:

sudo apt install cntlm

非Debian系的安装,也是类似的形式。Cntlm是一个很老的软件,在各大Linux发行版都有发布。甚至,连Windows下也有发布,可以通过choco安装。

choco install cntlm

下面的介绍以Linux为例。Windows下的配置,和Linux大同小异,只是文件位置不同。
配置
Cntlm安装后,在/etc/cntlm.conf就有一份默认配置。如果需要在线查看配置,可以参考cntlm.conf。
修改cntlm.conf
以下配置,几乎是/etc/cntlm.conf的最简配置。

Username    USERNAME
Domain      COMPANY_DOMAIN
Password    ********

Proxy       proxy.company.com:8080
Proxy       proxy2.company.com:8080

NoProxy     localhost, 127.0.0.*, 10.*, 192.168.*, .company.com

Listen      3128

注意:其中USERNAME、proxy.company.com:8080等,应该换成自己的场景适用的值。此外,如果使用下一节【获取Auth】的手段,Password配置可省略。
这个配置,仅能让本机访问。如果要允许localhost以外的机器访问,则需要再添加Gateway yes。

Gateway	yes

如果需要限制外部访问,可以设置黑(Deny)白(Allow)名单。

Allow		127.0.0.1
Deny		0/0

获取Auth
以上配置修改完成后,需要重载或重启cntlm。具体方法见重载或重启。

$ sudo cntlm -vc /etc/cntlm.conf -M http://baidu.com
section: global, Username = 'USERNAME'
section: global, Domain = 'COMPANY_DOMAIN'
section: global, Proxy = 'proxy.company.com:8080'
section: global, Proxy = 'proxy2.company.com:8080'
section: global, NoProxy = 'localhost, 127.0.0.*, 10.*, 192.168.*, .company.com'
section: global, Listen = '3128'
...
HEAD: HTTP/1.1 200 OK
OK (HTTP code: 200)
----------------------------[ Profile  1 ]------
Auth            NTLM
PassNT          7FA051B4B85F0E7EEBB24D3CD73E52B0
PassLM          23A1E1A7276E84EA4846D4C9FF957C35
------------------------------------------------
cntlm: Terminating with 0 active threads

添加Auth到配置
添加以下内容到刚才修改过的/etc/cntlm.conf:

Auth            NTLM
PassNT          7FA051B4B85F0E7EEBB24D3CD73E52B9
PassLM          23A1E1A7276E84EA4846D4C9FF957C31

重载或重启
在使用包管理器安装的情况下,Cntlm默认由systemd来守护,开机自启。
修改配置后,重载即可生效:

sudo systemctl reload cntlm

若仍未生效,可以尝试重启:

sudo systemctl restart cntlm
About Cntlm proxy Cntlm (user-friendly wiki / technical manual) is an NTLM / NTLM Session Response / NTLMv2 authenticating HTTP proxy intended to help you break free from the chains of Microsoft proprietary world. You can use a free OS and honor our noble idea, but you can't hide. Once you're behind those cold steel bars of a corporate proxy server requiring NTLM authentication, you're done with. The same even applies to 3rd party Windows applications, which don't support NTLM natively. Here comes Cntlm. It stands between your applications and the corporate proxy, adding NTLM authentication on-the-fly. You can specify several "parent" proxies and Cntlm will try one after another until one works. All auth'd connections are cached and reused to achieve high efficiency. Just point your apps proxy settings at Cntlm, fill in cntlm.conf (cntlm.ini) and you're ready to do. This is useful on Windows, but essential for non-Microsoft OS's. Cntlm integrates TCP/IP port forwarding (HTTP tunneling), SOCKS5 proxy mode, standalone proxy allowing you to browse intranet as well as Internet and to access corporate web servers with NTLM protection. There are many advanced features like NTLMv2 support, password protection, password hashing, completely mutliplatform code (running on just about every architecture and OS out there) and so much more. Cntlm eats up so little resources it can be used on embedded platforms as well - it's written in plain C without any external dependencies. Cntlm has been tested against various ISA servers, WinGate, NetCache, Squid and Tinyproxy with and without NTLM auth. Memory management audits and profiling are inherent part of the development process. Each change in the code is audited using Valgrind, which acts as a virtual CPU and checks behaviour of each instruction of the application being profiled. Using this marvelous tool, you can uncloak any imbalance in malloc/free calls (double free's or leaks), operations with uninitialized memory, access outside of properly allocated memory and oh so much more.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值