search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

Juniper Junos限制遠端存取SSH、Telnet權限(ACL) – KerKer 的模組世界

邊做邊學,順便留個筆記,若有錯誤請不吝指教。

Junos基本操作及root密碼設定可參考我之前的文章:Juniper Junos基本操作、root密碼設定

所有Juniper相關文章列表:Juniper JunOS 系列文章列表

之前我們幫Switch開啟了SSH及Telnet遠端管理的功能,但是如果網際網路上的所有IP都能夠遠端管理,就有可能造成資安上的風險。

Juniper的遠端管理功能邏輯上都是透過Loopback介面進行存取,因此我們需要透過在Loopback介面(lo0)上套用filter來限制遠端管理的來源IP。

這邊的設定我們使用上次vlan基本設定的範例來進行實作,限制僅vlan200(即192.168.200.0/24網段)可對sw1做telnet、ssh的遠端管理。

首先我們要實做一個等等要套用的filter,在設定模式下使用下列指令建立Filter:

    KerKer@sw1# set firewall family inet filter Remote_ACL term 1 from source-address 192.168.200.0/24
    KerKer@sw1# set firewall family inet filter Remote_ACL term 1 from destination-port telnet
    KerKer@sw1# set firewall family inet filter Remote_ACL term 1 from destination-port ssh
    KerKer@sw1# set firewall family inet filter Remote_ACL term 1 then accept
    KerKer@sw1# set firewall family inet filter Remote_ACL term 2 from destination-port telnet
    KerKer@sw1# set firewall family inet filter Remote_ACL term 2 from destination-port ssh
    KerKer@sw1# set firewall family inet filter Remote_ACL term 2 then reject
    KerKer@sw1# set firewall family inet filter Remote_ACL term 3 then accept

Remote_ACL是我們給這個filter定義的名稱,也可以換成任意其他名稱,我們可以在設定模式下用show指令來查看Filter設定:

    KerKer@sw1# show firewall family inet filter Remote_ACL                       
    term 1 {
        from {
            source-address {
                192.168.200.0/24;
            }
            destination-port [ telnet ssh ];
        }
        then accept;
    }
    term 2 {
        from {
            destination-port [ telnet ssh ];
        }
        then {
            reject;
        }
    }
    term 3 {
        then accept;
    }

首先在 term 1 先允許192.168.200.0/24的telnet、ssh請求,並在 term 2 阻擋來自其他所有IP的telnet、ssh請求,最後再用 term 3 允許其它非telnet、ssh封包。

這裡比較需要注意的是term後面接的數字為term的名稱,也可以使用任意字串命名。

term的優先序以排列順序為主,from後面接的是條件,then後面接的是動作。

destination-port可以填常用的協定,效果其實等同這填寫這些協定預設的port,所以這邊填 [ 22 23 ] 也能起到相同的效果。

若要改變排列順序可以使在設定模式下用 insert term 2 before term 1 的指令把 term 2 排到 term 1 前面。

完成filter設定後我們須將其套用至介面上,套用方如下:

KerKer@sw1# set interfaces lo0 unit 0 family inet filter input Remote_ACL

這樣就完成所有的設定了, 設定完成記得要commit才會生效,更多關於commit指令的內容可以參考:Juniper Junos提交設定(commit)

我們分別在vlan100及vlan200上接電腦對sw1進行ping及telnet/ssh測試。

當我們使用192.168.100.1時可正常ping到sw1但無法ssh、telnet。

    [C:\~]$ ipconfig

    Windows IP 設定

    乙太網路卡 乙太網路 9:

       連線特定 DNS 尾碼 . . . . . . . . : 
       IPv4 位址 . . . . . . . . . . . . : 192.168.100.1
       子網路遮罩 . . . . . . . . . . . .: 255.255.255.0
       預設閘道 . . . . . . . . . . . . .: 192.168.100.254

    [C:\~]$ ping 10.0.0.1

    Ping 10.0.0.1 (使用 32 位元組的資料):
    回覆自 10.0.0.1: 位元組=32 時間=3ms TTL=64
    回覆自 10.0.0.1: 位元組=32 時間=5ms TTL=64
    回覆自 10.0.0.1: 位元組=32 時間=4ms TTL=64
    回覆自 10.0.0.1: 位元組=32 時間=10ms TTL=64

    10.0.0.1 的 Ping 統計資料:
        封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),
    大約的來回時間 (毫秒):
        最小值 = 3ms,最大值 = 10ms,平均 = 5ms

    [C:\~]$ telnet 10.0.0.1

    Connecting to 10.0.0.1:23...
    Could not connect to '10.0.0.1' (port 23): Connection failed.

    [C:\~]$ ssh 10.0.0.1

    Connecting to 10.0.0.1:22...
    Could not connect to '10.0.0.1' (port 22): Connection failed.

當我們改使用192.168.200.1時則ping、ssh、telnet都可以正常存取。

    [C:\~]$ ipconfig

    Windows IP 設定

    乙太網路卡 乙太網路 9:

       連線特定 DNS 尾碼 . . . . . . . . : 
       IPv4 位址 . . . . . . . . . . . . : 192.168.200.1
       子網路遮罩 . . . . . . . . . . . .: 255.255.255.0
       預設閘道 . . . . . . . . . . . . .: 192.168.200.254

    [C:\~]$ ping 10.0.0.1

    Ping 10.0.0.1 (使用 32 位元組的資料):
    回覆自 10.0.0.1: 位元組=32 時間=12ms TTL=64
    回覆自 10.0.0.1: 位元組=32 時間=12ms TTL=64
    回覆自 10.0.0.1: 位元組=32 時間=7ms TTL=64
    回覆自 10.0.0.1: 位元組=32 時間=10ms TTL=64

    10.0.0.1 的 Ping 統計資料:
        封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),
    大約的來回時間 (毫秒):
        最小值 = 7ms,最大值 = 12ms,平均 = 10ms

    [C:\~]$ telnet 10.0.0.1

    Connecting to 10.0.0.1:23...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.

    [C:\~]$ ssh 10.0.0.1

    Connecting to 10.0.0.1:22...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.  

如此一來就能夠確認所有設定都已生效,已經能夠限制特定來源對Switch進行存取了!



熱門推薦

本文由 KerKerwebsite 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦