PDA

查看完整版本 : 在自己的linux主機該如何ban IP?


哈啦
2004-11-05, 10:59 PM
我發現有不明IP大量存取某一個架在自己的linux fedora主機的網站,該如何ban掉它呢?

謝謝先。

dx2
2004-11-05, 11:02 PM
iptable
apf
都可以用

哈啦
2004-11-05, 11:05 PM
iptable
apf
都可以用


能否詳述一下怎麼用?在哪裡?

~rusure

哈啦
2004-11-06, 01:08 AM
有沒有人知道?謝謝。

Matt
2004-11-06, 02:39 AM
http://phorum.vbird.org/viewtopic.php?t=14692&highlight=ban+ip

這個如果是appserv的話可以用

如果針對主機的話
iptable

該站上的討論超多
可惜我看不懂

Matt
2004-11-06, 02:40 AM
之前蒐集的文章 關於appache的設定

Includes=允許SSI
另外,可用 Options All 取代 Options Indexes FollowSymLinks ExecCGI Includes Options None 即不使用上述的選項
AllowOverride None
AllowOverride 即是 .htaccess 可否取代在此設定的目錄設定,可用 All (全部可取代) , None (不能取代) , AuthConfig (允許驗證的使用) , FileInfo (允許控制文件型態) , Indexes (允許控制目錄索引) , Limit (允許控制存取) , Options (允許控制特定目錄特色)
Order allow,deny
Allow from all
Allow from all 即全部人可存取.
如:Order deny,allow
Deny from all
Allow from abcde.com
即只有網域於 abcde.com 方可存取

dx2
2004-11-06, 07:20 AM
裝apf吧。

1.用root登入 SSHt.

2. cd /usr/src

3. wget http://rfxnetworks.com/downloads/apf-current.tar.gz

4. tar -xvzf apf-current.tar.gz

5. rm -f apf-current.tar.gz

6. ls -la
看apf-xx是裝到哪裡0.9版的話應該是在目錄apf-0.9

7. cd apf-0.9

8. sh ./install.sh

9. cd /etc/apf

10.pico -w conf.apf

In order for this firewall to work properly you have to edit/add/delete ports.
These ports will allow services such as mail, ftp, and ssh to come in and out of the server.
If you have changed any ports, please modify them below and add/remove as needed.

# Common ingress (inbound) TCP ports
IG_TCP_CPORTS="20,21,22,25,53,80,110,143,443,465,
993,995,2082,2083,2086,2087,2095,2096,3306,
10000,35000_35999"
Please note that ports 2082 to port 2095 is mostly used by cpanel, and port 19638 is only use in ensim.

# Common ingress (inbound) UDP ports
IG_UDP_CPORTS="20,21,53,1040"

10.CTRL-X後輸入 Y存檔

11. 啟動apf使用 ./apf --start
或者service apf start

12. 確認正常,而且你沒被鎖在門外,繼續修改conf.apf
輸入 pico -w conf.apf

13. 設定 DEVM 參數為 0
DEVM="0"

14. CTRL-X離開,選 Y 存檔

15. 重新啟動apf
service apf restart


1. To allow connections from xx.xx.xx.xx/24
Type: pico -w /etc/apf/allow_hosts.rules

2. At the very end of the file add this line
xx.xx.xx.xx/24 Of course replace the xx.xx.xx.xx with the IP address provided to you

哈啦
2004-11-06, 09:46 AM
謝謝各位。
我有試了一下iptables的指令(從google上找來的),iptables -I INPUT -s 61.175.128.31 -j DROP,但好像這個ip依然能大量存取我的網站?
後來又找到另一個指令,/sbin/route add -host 61.175.128.31 reject,似乎也沒啥效果?

flashblue
2004-11-06, 04:07 PM
使用linux內建的工具來ban ip,至少有兩種,一個是 IPTable,一個是 xinetd(舊版linux通常使用 inetd)。
iptable 屬於核心層級的,無所不能卻難以掌控,一般而言,不是一兩條指令就可以周延。
xinted 比較像屬於應用程式階級的,比較好駕馭。

在設定檔中,有一條指令 no_access 可以把不想要的IP BAN掉。

使用google 搜尋一下,或是這一篇可以參考
http://www.iselong.com/5/915.htm
(修改)
不過對於以 standalone 方式啟動的 daemon xinetd 就沒輒,只能個別在 standalone 啟動的daemon 設定檔中設定,不像 iptable 可以通殺!

ismile
2004-11-06, 04:11 PM
哈拉大的主機有裝 iptables 嗎? --> lsmod | grep ip_tables

然後用 iptables -L -n | grep 61.175.128.31

看看有沒有出現類似,

DROP all -- 61.175.128.31 0.0.0.0/0
DROP all -- 61.175.128.31 [主機 IP]

哈啦
2004-11-06, 04:32 PM
哈拉大的主機有裝 iptables 嗎? --> lsmod | grep ip_tables

然後用 iptables -L -n | grep 61.175.128.31

看看有沒有出現類似,

DROP all -- 61.175.128.31 0.0.0.0/0
DROP all -- 61.175.128.31 [主機 IP]

應該是有。而執行iptables -L -n | grep 61.175.128.31之後出現如下:
DROP all -- 61.175.128.31 0.0.0.0/0

就這一行。

dx2
2004-11-06, 04:34 PM
裝上bfd吧,裝之前先裝好apf
1. Login to your server via SSH as Root.

2. Type: wget http://www.rfxnetworks.com/downloads/bfd-current.tar.gz

3. Type: tar -xvzf bfd-current.tar.gz

4. Type: cd bfd*

5. Now let's install BFD onto the server.
Type: ./install.sh

:: You Should See ::
.: BFD installed
Install path: /usr/local/bfd
Config path: /usr/local/bfd/conf.bfd
Executable path: /usr/local/sbin/bfd

6. Now we need to edit the configuration file, and set some options.
Don't worry the BFD Configuration isn't hard to edit or understand!
Type: pico -w /usr/local/bfd/conf.bfd

7. Now we need to find the line to edit:
Press: CTRL-W
Type: ALERT_USR
Change ALERT_USR="0" TO ALERT_USR="1"
Right below that we need to change the email:
Change EMAIL_USR="root" TO EMAIL_USR="you@yoursite.com"

8. That wasn't to bad let's save and exit the file
Press: CTRL-X then type Y then hit enter

9. Now we have to prevent locking yourself out of the server.
Type: pico -w /usr/local/bfd/ignore.hosts

10. Add any IP address that you want to be ignored from the rules. If your server provider is doing monitoring add their IP(s) here. Since you need these IPs open in APF as well you can copy the IPs you used in APF.
Type: pico -w /etc/apf/allow_hosts.rules
Then scroll down to the bottom and copy those IPs (drag mouse over that's it)
Press: CTRL-X
Type: pico -w /usr/local/bfd/ignore.hosts
Paste those IPs to the bottom. You should also add your home IP if you hadn't done so before. If your home IP is dynamic this is not a good idea, and you should get a static IP.
Press: CTRL-X then Y to save then enter.

11. Now lets run BDF!!!
Type: /usr/local/sbin/bfd -s

ismile
2004-11-06, 06:48 PM
用 iptables -I INPUT -s 61.175.128.31 -j DROP 加入後,只要 iptable 重開,或是主機重開,設定就沒了。

裝 APF 或 Kiss, 比用 iptables 指令快多了 ...

哈啦
2004-12-20, 09:03 PM
Dec 20 20:07:48 jjj sshd(pam_unix)[3279]: authentication failure; logname= uid=0 euid=0 tty=NODEVssh ruser= rhost=211.63.239.11
Dec 20 20:07:52 jjj sshd(pam_unix)[3281]: check pass; user unknown
Dec 20 20:07:52 jjj sshd(pam_unix)[3281]: authentication failure; logname= uid=0 euid=0 tty=NODEVssh ruser= rhost=211.63.239.11
Dec 20 20:07:56 jjj sshd(pam_unix)[3283]: check pass; user unknown
Dec 20 20:07:56 jjj sshd(pam_unix)[3283]: authentication failure; logname= uid=0 euid=0 tty=NODEVssh ruser= rhost=211.63.239.11
Dec 20 20:07:59 jjj sshd(pam_unix)[3285]: check pass; user unknown

想再請問一下,我從/var/log/messages裡看到以上的訊息連續一整排,我摘取一小段,請問有誰能解釋一下上面的文字代表什麼意義嗎?我大致猜是有從211.63.239.11 這個IP來的人不斷企圖進入主機,是嗎?那有成功嗎?

請高手指教一下,謝謝先 ~yes

vincentliao
2004-12-20, 09:08 PM
它要破您的 root 帳號密碼 uid=0
failure ==) 沒成功.

哈啦
2004-12-20, 09:13 PM
可惡。
不是系統都有三次失誤的限制嗎?它如何能連續不斷的試?

還有,有無方法ban掉一整個區段的ip?例如我想直接封掉來自韓國的ip?

alextung
2004-12-20, 09:20 PM
很簡單,211.63.239.11的用戶想用ssh登入您的主機,

哈啦有在玩Linux應該知道sshd是幹麻的,
我的作法你可以用用看,
1.
/etc/hosts.deny
加入以下
sshd : ALL : spawn (/bin/echo Security notice from host `/bin/hostname`; \
/bin/echo; /usr/sbin/safe_finger @%h ) | \
/bin/mail -s "%d -%h security" xxx@xxx.xxx.xxx & \
: twist ( /bin/echo -e "\n\nWARNING connectin not allowed. Your attempt has been logged. \n\n\n警告!您尚未允許登入,您的連線將會被紀錄,並且作為以後的參考\n ". )

紅色處填上您的email信箱

2.
開啟/etc/hosts.allow
sshd: 192.168.1.

這裡要注意最後面有一個點

3.以後若是你要使用sshd登入您的server就只能在您的local或者主機登入了,
(若是您的主機使用固定ip,可以採用兩張網卡,或者將網卡設定第二個ip)

4.
最簡單的阻擋某一個特定ip的方法則是在/etc/hosts.deny裡面加上
sshd: xxx.xxx.xxx.xxx(IP)

vincentliao
2004-12-20, 09:20 PM
1.都是用程式在跑的.如果沒破成功就沒關希
2.ip可能是假的.
3.[ban掉一整個區段的ip]比較沒意義
4.用 ghost 將硬碟整顆備份到 DVD-rw,比較可行.
5.....
6.....

哈啦
2004-12-20, 09:25 PM
十分感謝。我會加緊研究一下。
不過我基本上屬於幼稚園程度 ~embarass: ,所以只會用一些基本如httpd.conf的設定等等。其它大概都看嘸。 :nunchuka

alextung
2004-12-20, 09:32 PM
若是大大不用sshd的話,最簡單的方式就關掉它吧!
1.
/etc/rc.d/init.d/sshd stop
或者
service sshd stop

2.
進入setup選單,設定不要一開機就啟動sshd

osmomo
2004-12-21, 02:07 AM
謝謝各位。
我有試了一下iptables的指令(從google上找來的),iptables -I INPUT -s 61.175.128.31 -j DROP,但好像這個ip依然能大量存取我的網站?
後來又找到另一個指令,/sbin/route add -host 61.175.128.31 reject,似乎也沒啥效果?

鳥哥的Linux - 簡易防火牆
http://linux.vbird.org/linux_server/0250simple_firewall.php