iT邦幫忙

0

Linux proxy squid 開放目的地80030 port!!

請問各位高手 小弟我剛接手的Linux CentOS-5.3 有用proxy 限制上網鎖80 和其他port.
, 但公司新系統需要傳簡訊驗證需要在走30080 port出去(http://60.251.6.233:30080/sms/default/),請問我 squid.conf 需要如何設定60.251.6.233:30080 出的去.
以下是公司的 proxy 設定 ,
設定檔內容:
acl all src 0.0.0.0/0.0.0.0
acl all_pass_ip src "/etc/squid/setting/all_pass_ip"
acl callcenter_leader_ip src "/etc/squid/setting/squid.superallow.hosts"
acl basic_user_ip src "/etc/squid/setting/squid.allow.hosts"
acl yushun_ip src "/etc/squid/setting/yushun_user_ip"

acl denytimes time "/etc/squid/squid.deny.times"
acl morning time 9:30-12:00
acl afternoon time 14:00-18:00

acl allurl dstdomain "/etc/squid/squid.allurl"
acl whilefile urlpath_regex -i "/etc/squid/squid.allow.whilefile"
acl whileurl dstdomain "/etc/squid/squid.allow.whileurl"
acl blockfile urlpath_regex -i "/etc/squid/squid.deny.blockfile"
acl superblockurl dstdomain "/etc/squid/squid.superdeny.blockurl"
acl blockurl dstdomain "/etc/squid/squid.deny.blockurl"
acl yushunurl dstdomain "/etc/squid/setting/squid.yushundeny.blockurl"
acl lanurl dstdomain "/etc/squid/setting/lanurl
acl localhost src 127.0.0.1/255.255.255.255

acl Safe_ports port 80 # http
acl SSL_ports port 443
#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

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

6
逮丸逮丸
iT邦大師 1 級 ‧ 2010-10-04 17:58:35
最佳解答

只有一個地方需要改:

f7112345提到:
acl callcenter_leader_ip src "/etc/squid/setting/squid.superallow.hosts"

改成:
acl callcenter_leader_ip dst "/etc/squid/setting/squid.superallow.hosts"

src是允許什麼IP可以用您這proxy的來源控制。
而你要設的應是
dst允許連到哪些IP為目的。
所以只要把該行的 src 改為 dst就可以,
並且 squid.superallow.hosts 這檔的內容會是像:
60.251.6.233/32 的字樣,
就可設定成功。
以下是從我proxy連過去的記錄檔例子,
所以連port 30080沒問題,
您也要確認公司的防火牆沒擋從squid連到該IP的port 30080:

<pre class="c" name="code">1286185363.071     42 1.2.3.4 TCP_MISS/200 925 GET http://60.251.6.233:30080/sms/default/ - DIRECT/60.251.6.233 text/html
1286185363.271     83 1.2.3.4 TCP_MISS/200 1008 GET http://60.251.6.233:30080/sms/default/bottomx.php - DIRECT/60.251.6.233 text/html
1286185363.318    113 1.2.3.4 TCP_MISS/200 6190 GET http://60.251.6.233:30080/sms/default/favicon.ico - DIRECT/60.251.6.233 image/vnd.microsoft.icon
1286185363.370    200 1.2.3.4 TCP_MISS/200 19060 GET http://60.251.6.233:30080/sms/default/page_index.php - DIRECT/60.251.6.233 text/html
1286185363.373     43 1.2.3.4 TCP_MISS/404 587 GET http://60.251.6.233:30080/sms/default/web.css - DIRECT/60.251.6.233 text/html
1286185363.400     57 1.2.3.4 TCP_MISS/200 837 GET http://60.251.6.233:30080/sms/default/images/yoyo8-top_03.gif - DIRECT/60.251.6.233 image/gif
1286185363.426    138 1.2.3.4 TCP_MISS/200 8932 GET http://60.251.6.233:30080/sms/default/images/style.css - DIRECT/60.251.6.233 text/css
看更多先前的回應...收起先前的回應...
<pre class="c" name="code">telnet 60.251.6.233 30080
Trying 60.251.6.233...
Connected to 60.251.6.233.
Escape character is '^]'.
GET /
Connection closed by foreign host.

上面只有 GET / 這一行是要自己輸入!

f7112345 iT邦新手 5 級 ‧ 2010-10-05 10:00:38 檢舉

高手 我按照你的方法,還是無法開網頁. 我執行了 60.251.6.233:30080 再打 GET / 出現了.Connection closed by foreign host. 這樣不是不通嗎? 目前我發現一個怪問題,公司電腦基本上 我只有上班時間,鎖上網.中午2個小時跟下班都能上網. 但能上網時 其他80網頁開得出來 (60.251.6.233:30080)卻開不出來.我確定我最外層的fortigate防火牆沒有檔,我電腦沒有透過proxy出去所以都開得出來. 所以還是linux的問題,會是linux防火牆的問題嗎? 那我之前那個問題,有上網查然後打這個指令 (iptables -A OUTPUT -o eth0 -d 210.68.77.234 -j ACCEPT)但我也不知道有沒有用. 會是類似的問題嗎? 麻煩以你的經驗,給我指導.感謝你.

f7112345提到:
再打 GET / 出現了.Connection closed by foreign host. 這樣不是不通嗎?

是通的,因為 / 網頁內容是空的,但回應的 header 的指令是導到另個網頁位置。
所以問題是在 squid 的問題。

試試把這一行:
http_access allow callcenter_leader_ip
往上面幾行放放看,
例如放在:
http_access allow all_pass_ip
這一行的下一行試試。
allow, deny 的順序不一樣,結果就會不一樣。

f7112345 iT邦新手 5 級 ‧ 2010-10-05 16:16:21 檢舉

高手 還是不行 但我發現 那組ip 已經能開了,只是沒加30080 port 開不出東西.
開的出來

加port開不出來

所以我上網找方法 看我有開看些port.
[root@localhost usr]# nmap 192.168.1.42

Starting nmap V. 2.54BETA25 ( www.insecure.org/nmap/ )
Interesting ports on (192.168.1.42):
(The 1538 ports scanned but not shown below are in state: closed)
Port State Service
22/tcp open ssh
53/tcp open domain
80/tcp open http
111/tcp open sunrpc
720/tcp open unknown
3128/tcp open squid-http

我只有開了這些 port.
那我需要 把 30080 加進去嗎? 我該如何加進去? 謝謝.

f7112345 iT邦新手 5 級 ‧ 2010-10-05 16:28:57 檢舉

慘了 我剛 又在執行 nmap 192.168.1.42
Starting nmap V. 2.54BETA25 ( www.insecure.org/nmap/ )
Interesting ports on (192.168.1.24):
(The 1538 ports scanned but not shown below are in state: closed)
Port State Service
135/tcp open loc-srv
139/tcp open netbios-ssn
445/tcp open microsoft-ds
1030/tcp open iad1
1433/tcp open ms-sql-s
3389/tcp open msrdp

port怎麼變得跟原來的都不一樣了. 想說是http_access allow callcenter_leader_ip
往上面放的關係. 但在改回來. 還是出現一樣的結果.
高手救救我.

f7112345 iT邦新手 5 級 ‧ 2010-10-05 16:43:42 檢舉

原來是 我太緊張 ip打錯42.打成24. 嚇自己一跳.
沒事了. 差點哭出來 哈哈哈.

f7112345提到:
60.251.6.233

這IP的+http://60.251.6.233/+全世界連上來就是那+Forbidden+的字樣。
您可在+linux+squid+那一台上執行:

<pre class="c" name="code">$+curl+http://60.251.6.233
<!DOCTYPE+HTML+PUBLIC+"-//IETF//DTD+HTML+2.0//EN">

<title>403+Forbidden</title>

<h1>Forbidden</h1>
<p>You+don't+have+permission+to+access+/
on+this+server.</p>

所以是正常的。

再用:

<pre class="c" name="code">$+curl+-I+http://60.251.6.233:30080/
HTTP/1.1+302+Found
Date:+Tue,+05+Oct+2010+11:14:03+GMT
Server:+Apache/2.2.15+(Win32)+mod_ssl/2.2.15+OpenSSL/0.9.8m+PHP/5.2.13
X-Powered-By:+PHP/5.2.5
Location:+./sms/default/
Content-Type:+text/html

如果會出現上述的樣子,
就表示linux到+60.251.6.233+port+30080是通的。

如果內部的瀏覽器即然設了+192.168.1.42+這linux為proxy,
其實到+60.251.6.233+port+30080應都是從
192.168.1.42:3128+傳回給內部的browser。

還有一個方式您可用「ssh+當proxy測試」:
在您從windows+連到linux時,
putty+-D+3128+user@192.168.1.42
然後在你的IE設proxy,
只要在+Socks+上設+127.0.0.1+連接埠+3128
其他http、secure、ftp都空著,
這樣應是可以透過那linux本身連到任何地方,
看有無問題。
如果這樣可以的話,
再看squid的設定。

你可以再做另一個 squid 的設定檔,
開另外的port執行,
當然要定義另外的 cache、logs 的目錄,
然後先限定只有內部的IP能連全世界,
然後慢慢地加限制規則來逐條測試,
就較能了解規則怎麼設才會有效,
不然現有的一堆規則一定搞不清為何無效。

f7112345 iT邦新手 5 級 ‧ 2010-10-07 10:04:31 檢舉

高手 我照你的指令打 出現一樣的訊息.
所以你的意思是說 linux到+60.251.6.233+port+30080是通的.
那到底是哪裡擋住了呢?
ssh+當proxy測試 這個方法 你寫得很清楚 但我資淺看的模糊.

我研究了一下 有人說加 acl SSL_ports port 30080 就可以了.但我加也不行.
還有 加了 http_access allow all . 全公司隨時都能開80 上網了,
但唯獨 60.251.6.233:30080 .就是開不出來.
你是否還能想起其他地方,我需要開得. 謝謝你.

f7112345提到:
但唯獨 60.251.6.233:30080 .就是開不出來

看看 squid 的 log 有無此項被 deny 的記錄?

f7112345 iT邦新手 5 級 ‧ 2010-10-08 18:29:53 檢舉

2010/10/08 17:36:11| FD 13 Closing HTTP connection
2010/10/08 17:36:42| Shutting down...
2010/10/08 17:36:42| FD 14 Closing ICP connection
2010/10/08 17:36:42| WARNING: Closing client 192.168.1.133 connection due to lifetime timeout
2010/10/08 17:36:42| http://gate.yoyo8.com.tw:30080/sms/SMSQuery.php
2010/10/08 17:36:42| Closing unlinkd pipe on FD 11
2010/10/08 17:36:42| storeDirWriteCleanLogs: Starting...
2010/10/08 17:36:42| Finished. Wrote 2085 entries.
2010/10/08 17:36:42| Took 0.0 seconds (2524213.1 entries/sec).
CPU Usage: 0.307 seconds = 0.031 user + 0.276 sys

請問是這個log嗎?

高手 我看書 查到 squid直接連線的語法 為
acl direct-net dstdomain .acore.com.tw

always_direct allow direct-net

那如果acore.com.tw要外加 2222 port
有加port 的直接連線語法嗎?

f7112345提到:
請問是這個log嗎?

不是,應是看 squid.conf 裡的 cache_access_log 這標籤後面所寫的檔案所在,
通常類似 access.log 的檔名。

f7112345 iT邦新手 5 級 ‧ 2010-10-11 14:10:13 檢舉
<pre class="c" name="code">1286768659.844    428 192.168.1.133 TCP_MISS/503 1473 GET http://www.yoyo8.com.tw:30080/ - DIRECT/- text/html
1286768659.953    102 192.168.1.133 TCP_MISS/503 1495 GET http://www.yoyo8.com.tw:30080/favicon.ico - DIRECT/- text/html
1286768660.503    592 192.168.1.133 TCP_MISS/200 7227 CONNECT urs.microsoft.com:443 - DIRECT/202.89.225.189 -
1286768660.520    593 192.168.1.133 TCP_MISS/200 7227 CONNECT urs.microsoft.com:443 - DIRECT/202.89.225.189 -
1286768661.018    498 192.168.1.133 TCP_MISS/204 391 GET http://g.microsoft.com/_0sfdata/1? - DIRECT/207.46.216.54 -
1286768665.376    956 192.168.1.133 TCP_MISS/200 963 GET http://www.yoyo8.com.tw/default/ - DIRECT/60.251.6.233 text/html
1286768665.724    348 192.168.1.133 TCP_MISS/200 19008 GET http://www.yoyo8.com.tw/default/page_index.php - DIRECT/60.251.6.233 text/html

高手這樣是有檔嗎? 謝謝你.

f7112345 iT邦新手 5 級 ‧ 2010-10-11 14:11:29 檢舉

高手我用acl direct-net dstdomain .www.yoyo8.com.tw
always_direct allow direct-net

這樣www.yoyo8.com.tw網頁已經能開了.但同事說從程式要送簡訊出去時 還是要www.yoyo8.com.tw:30080.才送出的去.
acl Safe_ports port 1025-65535 # 這樣30080不是也包涵在裡面了嗎?
所以我應該已經沒有擋了.為何我30080還是開不出來?
我還能從哪個方向去查. 謝謝你.

我要發表回答

立即登入回答