Ubuntu配置ADSL + Squid + Iptables代理服务器

一台双网卡服务器,安装Ubuntu Server 12.04,网卡 eth0 空置,eth1连接局域网,IP 192.168.1.1/24,先连接了宽带路由器。

二、Squid3

尝试源码安装当前最新的Squid3.3,遇到很多问题,懒得弄了,用Ubuntu源里的3.1.19吧。
$sudo apt-get install squid3

配置文件在 /etc/squid3/squid.conf,这个配置文件包含详细的说明,总共5700多行,备份一份出来仔细研究吧,再从百度、Bing、谷歌里搜一搜,最后出来这么个配置文件:
acl alldst dst all
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localnet src 192.168.1.0/16      # 修改后的
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443        # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210        # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280        # http-mgmt
acl Safe_ports port 488        # gss-http
acl Safe_ports port 591        # filemaker
acl Safe_ports port 777        # multiling http
acl CONNECT method CONNECT

forwarded_for delete       # 修改后的,否则在远程服务器上会收到包含内网IP的 HTTP头数据(X_Forwarded_for)
acl_uses_indirect_client on
delay_pool_uses_indirect_client on

http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet  # 修改后的
http_port 192.168.1.1:3128    # 修改后的

cache_mem 1024 MB             #自己看情况设定。
maximum_object_size_in_memory 2048 KB   #内存缓存的最大对象。
cache_dir ufs /opt/cache 200000 16 256    #/opt 是个独立分区 240G,分配约200G做cache。
coredump_dir /var/spool/squid3

logformat custcommon %>a [%tl] %3>Hs %8<st %Ss:%Sh %rm "%ru" %mt
access_log /var/log/squid3/access.log custcommon

#  logformat logformat squid %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %un %Sh/%<A %mt
#  access_log /var/log/squid3/access.log squid
# 这里修改了一下默认的日志格式,更方便阅读。
# 原格式 1361289819.737    21 192.168.1.100 TCP_DENIED/403 4295 GET - NONE/- text/html
# 新格式 192.168.1.100 [21/Feb/2013:13:29:45 +0800] 200    13813 TCP_MISS:DIRECT GET "http://common.cnblogs.com/editor/tiny_mce/plugins/insertCode/images/insertCode.gif" image/gif
#

# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp:          1440    20%    10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0    0%      0
refresh_pattern (Release|Packages(.gz)*)$      0      20%    2880
# example lin deb packages
#refresh_pattern (\.deb|\.udeb)$  129600 100% 129600
refresh_pattern .              0      20%    4320

内网Firefox设置代理 192.168.1.1:3128 上网正常!

三、PPPOE

1、安装、设置
$ sudo apt-get install pppoe

撤掉宽带路由器,宽带猫直接连到eth0。
$ sudo pppoeconf
进入向导安装模式,基本都是回答yes,尤其是开机自动连接,再填上宽带用户名和密码,ADSL连接就设好了。手动管理ADSL指令如下:           

$ ifconfig ppp0                  #查看ADSL连接状态
$ sudo pon dsl-provider    #手动连接ADSL  
$ sudo poff        #手动断开ADSL
$ sudo plog        #查看ADSL连接日志,仅显示最后一次连接。

2、DNS
DNS设置在 pppoeconf向导中可以设置为从ISP获得,如果喜欢设置自己的DNS,则
$ sudo vi /etc/resolv.conf
nameserver 8.8.8.8

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8edd3548d1f1b0e622d44a8066c7f616.html