cht電腦資訊Linux
adm Find login register

ssh 限制 IP login 登入

eliu

joined: 2007-08-09
posted: 11468
promoted: 617
bookmarked: 187
新竹, 台灣
1subject: ssh 限制 IP login 登入Promote 0 Bookmark 02010-03-26quote  

用 shorewall

shorewall 是 iptables 比較容易使用的介面

# cd /etc/shorewall

修改 rules,加入底下一行,111. or 222. 是你要的 IP

/etc/shorewall/rules
ACCEPT net:111.111.111.111,222.222.222.222    fw    tcp    22    -

# make 

等於執行 shorewall -restart

用 xinetd 限制

先用 mcc 等系統工具把 firewall sshd port 22 的 access 打開

修改 /etc/xinetd.d/sshd-xinetd

/etc/xinetd.d/sshd-xinetd
service ssh
{
    disable    = no
    socket_type        = stream
    wait            = no
    user            = root
    server            = /usr/sbin/sshd
    server_args        = -i
    log_on_success        += DURATION USERID
    log_on_failure        += USERID
    nice            = 10
    only_from        = 111.111.111.111 222.222.222.222
}

# chkconfig --del sshd

# service sshd stop

# service xinetd restart

xinetd 不太好用,會先 reverse DNS,有時候會造成 block 等很久才能登入的情形。

edited: 4
tinmean

joined: 2009-09-17
posted: 553
promoted: 27
bookmarked: 7
2subject: Promote 0 Bookmark 02010-03-27quote  

有個笨問題請教一下:p

用Tcp wrapper會比較不好嗎?

eliu

joined: 2007-08-09
posted: 11468
promoted: 617
bookmarked: 187
新竹, 台灣
3subject: Promote 0 Bookmark 02010-03-27quote  

tcp wrapper 應該也是可以,不過我沒試過是不是與 xinetd 有同樣 reverse DNS 的問題。xinetd 好像也有用 tcp wrapper

用 iptables 等於在最前面就把 connection 擋住了,用 tcp wrapper or xinetd 則是 connection 已建立後才過濾連線。我們可以看到 iptables 對不想要的 IP 是完全拒絕沒反應,用 xinetd 的方式會出現 'Remote connection closed'

理論上 iptables 的方式會更安全。

edited: 1

cht電腦資訊Linux
adm Find login register
views:9313