LoginSignup
1
1

More than 1 year has passed since last update.

CiscoスイッチへのTelnet/SSHをFreeRADIUSで認証してログイン直後に自動でPriv15にしてみた

Posted at

はじめに

この記事は、管理しないといけないCiscoスイッチ(Catalyst)がたくさんあって、下記のように考えている人向けです。
・Ciscoスイッチにログインするときに、RADIUSで認証したい
・ログイン後、enableコマンドを打ちたくない
Ciscoスイッチは、RADIUS関連のコマンドが途中で変わったりしているので、少し微妙ですが。

やってみたこと

下の構成図のように構築して、タイトルの内容をやってみた。
0002.png

ログインに成功すると、すぐさまプロンプトが#になる。

User Access Verification

Username: bob
Password:

sw1#

手順

①事前準備

Cisco L2SW、Rocky Linux、PCの初期セットアップとPing疎通確認を行いますが、
詳細は省略します。
Cisco L2SWは、Cisco Modeling LabsIOSvL2を使用しています。

②FreeRADIUSインストール

下記を順番に実行してインストールします。LDAPは今回は不要ですが、インストールしておきます。

$ sudo dnf -y update
$ sudo dnf makecache --refresh
$ sudo dnf -y install freeradius
$ sudo dnf -y install freeradius-ldap
$ sudo dnf -y install freeradius-utils

③FreeRADIUS設定

/etc/raddb/client.confを編集して、Cisco ASAからの認証リクエストを受け付けるようにします。緩めに設定します。

/etc/raddb/client.conf
client test-network {
        ipaddr          = 192.168.0.0/24
        secret          = testing123
}

/etc/raddb/mods-config/files/authorizeを編集して、テストで使用するユーザーbobを追加します。
1行目は、同じ内容が設定ファイルにコメントアウトされて記載されていますので、
近辺に追加します。

bob     Cleartext-Password := "hello"
        Service-Type = Administrative-User,
        Cisco-AVPair = "shell:priv-lvl=15"

④証明書作成

EAP-TLSを実施したいわけではないのですが、作成しないとFreeRADIUSが動かないようなので作成します。
rootユーザになってから実行します。

# cd /etc/raddb/certs/
# make ca.pem
# make server.pem
# make client.pem
# openssl pkcs12 -export -in ca.pem -out ca.p12
# openssl dhparam -out /etc/raddb/certs/dh 2048
# chmod 644 /etc/raddb/certs/client.crt
# chmod 644 /etc/raddb/certs/client.key
# chmod 644 /etc/raddb/certs/server.pem

⑤Rocky LinuxのFirewall設定

初期状態でFirewallが有効になっていると、RADIUSの通信パケットが破棄されますので、破棄されないように許可設定を追加します。

$ sudo firewall-cmd --zone=public --permanent --add-service=radius
$ sudo firewall-cmd --reload

⑥FreeRADIUS起動と確認

FreeRADIUSを起動させます。2行目のコマンドで状態を確認します。

$ sudo systemctl start radiusd
$ sudo systemctl status radiusd

起動している場合、2行目のコマンドの実行結果として、active (running)という表示が見つかると思います。

⑦Cisco L2SWの設定

Interfaceは設定済ということで進めていますが、Interface設定も書いておきます。
下記を設定します。コピペですね。

hostname sw1
enable secret c
username woo password 0 hello
!
aaa new-model
!
aaa group server radius freeradius
 server name freeradius
exit
!
aaa authentication login vty group freeradius local
aaa authorization exec vty group freeradius
!
ip domain-name test.eval
!
interface GigabitEthernet0/0
 switchport access vlan 100
 switchport mode access
 negotiation auto
exit
!
interface Vlan100
 ip address 192.168.0.201 255.255.255.0
 no shutdown
exit
!
ip ssh version 2
!
radius server freeradius
 address ipv4 192.168.0.43 auth-port 1812 acct-port 1813
 key testing123
exit
!
line vty 0 4
 exec-timeout 0 0
 authorization exec vty
 login authentication vty
 transport input telnet ssh
exit

SSH用の証明書を作成します。

sw1(config)#crypto key generate rsa modulus 2024 general-keys

⑧テスト

いきなり、Telnetしてみても動くと思いますが、動かない場合を考慮して動作確認です。下記はCisco L2SW側でのテスト成功例です。

sw1#test aaa group freeradius server 192.168.0.43 auth 1812 acct 1813 bob hello legacy
Attempting authentication test to server-group freeradius using radius
User was successfully authenticated.

sw1#

成功しない場合は、Rocky Linux側で下記を実施してみます。
下記は成功例です。

$ radtest bob hello 192.168.0.43 0 testing123
Sent Access-Request Id 203 from 0.0.0.0:42680 to 192.168.0.43:1812 length 73
        User-Name = "bob"
        User-Password = "hello"
        NAS-IP-Address = 127.0.0.1
        NAS-Port = 0
        Message-Authenticator = 0x00
        Cleartext-Password = "hello"
Received Access-Accept Id 203 from 192.168.0.43:1812 to 192.168.0.43:42680 length 51
        Service-Type = Administrative-User
        Cisco-AVPair = "shell:priv-lvl=15"
$

③で設定したkeyが違う場合は、RADIUS Serverが応答しませんので、応答がないという表示がでます。ユーザー名/パスワードが違う場合は、応答として、Access-Rejectを受け取ります。

やってみた

Cisco L2SWにTelnetを実行してみます。下記のようにログインできて、プロンプトがsw1#となっていれば、成功です。

User Access Verification

Username: bob
Password:

sw1#

補足

Rocky Linuxを再起動した場合に、FreeRADIUSを自動起動させるには、下記を実行する必要があります。

$ sudo systemctl enable radiusd

SSHについて書いていませんが、ASAについては下記をどうぞ。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1