事件は起こった
ある日、ブラウザからルータの DHCP で配る DNS を変えようとしたら、IP アドレスを間違えてしまい、それ以降、設定画面から DNS のアドレスを投入してもエラーしか返ってこないようになった。(電源 OFF/ON すると設定画面へアクセスできるようになるが、DNS サーバのアドレスを入力して OK を押すと一切の応答が無くなる)
そしてクライアントは DHCP でネームサーバ (DNS) のアドレスを貰えなくなった。DNS を使わない ping 8.8.8.8 などには応答が返ってくるので DNS だけの問題と判断。間に何か入れて配れば良いよね?ということで Cisco 2901 を挟むことにした。
何故か BFW200 から、OFF にしていた 5GHz の電波が出るようになったが、とりあえず無視。
※間に挟むルータは YAMAHA RTX1500, NEC IX2005 などもあったが、こいつらは 100Mbps インターフェイスしかないため対象外。
構成図
家の LAN は拡張スロットに switch モジュールを入れて繋ぐようにする予定だけど、以下では取り敢えず Gi 0/1 に接続。
条件
BFW200 にはルーティングを書けないので、家の中のネットワークは一つしか駄目。→ Cisco で NAT する。
Wi-Fi のアクセスポイントは DHCP でアドレスを取得するようにしているので、IP アドレスが変わっても変更不要。
設定開始
機器の情報
C2901#show version
Cisco IOS Software, C2900 Software (C2900-UNIVERSALK9-M), Version 15.7(3)M4, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2019 by Cisco Systems, Inc.
Compiled Sat 09-Feb-19 17:16 by prod_rel_team
ROM: System Bootstrap, Version 15.0(1r)M16, RELEASE SOFTWARE (fc1)
C2901 uptime is 1 day, 2 hours, 6 minutes
System returned to ROM by power-on
System restarted at 12:17:48 UTC Mon Mar 8 2021
System image file is "flash0:c2900-universalk9-mz.SPA.157-3.M4.bin"
Last reload type: Normal Reload
Last reload reason: power-on
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
If you require further assistance please contact us by sending email to
export@cisco.com.
Cisco CISCO2901/K9 (revision 1.0) with 483328K/40960K bytes of memory.
Processor board ID FGLxxxxxxxJ
18 Gigabit Ethernet interfaces
1 terminal line
DRAM configuration is 64 bits wide with parity enabled.
255K bytes of non-volatile configuration memory.
250880K bytes of ATA System CompactFlash 0 (Read/Write)
License Info:
License UDI:
-------------------------------------------------
Device# PID SN
-------------------------------------------------
*1 CISCO2901/K9 FGLxxxxxxxJ
Suite License Information for Module:'c2900'
--------------------------------------------------------------------------------
Suite Suite Current Type Suite Next reboot
--------------------------------------------------------------------------------
FoundationSuiteK9 None None None
securityk9
datak9
AdvUCSuiteK9 None None None
uck9
cme-srst
cube
Technology Package License Information for Module:'c2900'
------------------------------------------------------------------------
Technology Technology-package Technology-package
Current Type Next reboot
------------------------------------------------------------------------
ipbase ipbasek9 Permanent ipbasek9
security None None None
uc None None None
data None None None
Configuration register is 0x2102
2台で 5000円 (本体 3500円 + 送料1500円) だったけど、2019年と結構新しそうな IOS が入ってますね。さすがにライセンスは何もなし。
インターフェイスの設定
int Gi0/0
ip addr dhcp
duplex auto
speed auto
no shut
int Gi0/1
ip addr 192.168.100.254 255.255.255.0
duplex auto
speed auto
no shut
Gi 0/0 は DHCP で IP アドレスを取得、Gi 0/1 手動で IP を設定。PC 側の NIC が AUTO だと通信速度は auto にしないとリンクが落ちたので、auto にしておく。
ルーティングの追加
Cisco はインターネットがどちら側か分からないので教えてやる。
ip route 0.0.0.0 0.0.0.0 192.168.0.254
DNS サーバ (ネームサーバ) になる
DNS Proxy になって、DHCP クライアントからの問い合わせをインターネットへ取り次ぐ。
ip name-server 203.202.223.217
ip name-server 203.133.238.132
ip name-server 1.1.1.1
ip dns server
203.~~ はプロバイダの DNS サーバ。1.1.1.1 (Cloudflare社) は念のために追加。
OCN とか、フィルタ入りの dns を運用してくれています。
OCN じゃない人でそういうのが良いなら Quad9 9.9.9.9, 149.112.112.112, 2620:fe::fe, 2620:fe::9 を使うのも手です。
オープンアクセスの DNS は↓みたいなのがあるみたいですね。
dns.google
dns.quad9.net、dns9.quad9.net、dns10.quad9.net、dns11.quad9.net
dns.cloudflare.com
doh.dns.sb
dns.nextdns.io
dns.cleanbrowsing.org
doh.securedns.eu
DHCP サーバになる
クライアントに DNS の問い合わせは Cisco 送るように伝える。Cisco が答えなかったら 1.1.1.1 へ聞きに行けと。
要らない気はするが、クライアントのデフォルトルートはこの Cisco。
DHCP アドレスのリース期間は 1時間
lease <日> <時間> <分>
lease 5 4 3
とすると、5日と 4時間 3分。滞在時間の短いお店とかだと 30分とか、家なら 1日とか、環境に合わせて。
ip dhcp pool 192-168-100-pool
network 192.168.100.0 255.255.255.0
dns-server 192.168.100.254 1.1.1.1
default-router 192.168.100.254
lease 0 1 0
NAT を掛ける
Linux や、NEC の IX ルータで言うところの NAPT ですね。
access-list 100 permit ip 192.168.100.0 0.0.0.255 any
ip nat inside source list 100 interface GigabitEthernet0/0 overload
interface GigabitEthernet0/0
ip nat outside
interface GigabitEthernet0/1
ip nat inside
構成図のように EWHIC のスイッチモジュールに家庭内 LAN をぶら下げるには VLAN を作って、 access vlan を設定してやれば良いのかな。
今から、Cisco の PoE 対応電源へ交換 & PoEスイッチモジュールの挿入をして、gi0/1 の設定を gi0/1/x の設定に書き換えます。
おまけ
ssh 接続の設定
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname C2901
C2901(config)#ip domain name my.home
C2901(config)#aaa new-model
C2901(config)#crypto key gen rsa
The name for the keys will be: C2901.my.home
Choose the size of the key modulus in the range of 360 to 4096 for your
General Purpose Keys. Choosing a key modulus greater than 512 may take
a few minutes.
How many bits in the modulus [512]: 4096
% Generating 4096 bit RSA keys, keys will be non-exportable...
[OK] (elapsed time was 128 seconds)
Mar 9 13:35:07.023: %SSH-5-ENABLED: SSH 1.99 has been enabled
C2901(config)#ip ssh version 2
C2901(config)#ip ssh time-out 120
C2901(config)#ip ssh authentication-retries 5
C2901(config)#
C2901(config)#enable secret Cisco123
C2901(config)#username cisco password Cisco123
C2901(config)#
C2901(config)#line vty 0 15
C2901(config-line)#exec-timeout 0 0
C2901(config-line)#length 0
C2901(config-line)#transport input telnet ssh
C2901(config-line)#logging synchronous
C2901(config-line)#end
C2901#
Mar 9 13:38:32.392: %SYS-5-CONFIG_I: Configured from console by console
- conf t
- コンフィグレーションモードに入る
- hostname C2901
ip domain name my.home - ドメイン名とホスト名を設定 (設定しないと key を作成できません)
- crypto key generate rsa
- ssh のサーバの鍵 (RSA暗号鍵) を作成。2048 bit 以上にしましょう。
- ip ssh version 2
- ssh v1 は使ってはいけません ssh v2 にしましょう
- ip ssh time-out 120
- [デフォルト 120sec: 1-120] パスワード入力のタイムアウト (ログイン後のアイドルタイマーは vty の設定で行う)
- ip ssh authentication-retries 5
- [デフォルト3 : 0-5] パスワードを間違えたときの再入力回数
- aaa new-model
- なんでしょうねぇ?これが無いとログインできません。
- enable secret Cisco123
- enable するときのパスワードを設定します。これが無いと、ログインした後に enable でコンフィグレーションモードに入ることができません。
- username cisco password Cisco123
- ユーザ名とパスワードの組を定義します。 (Cisco2901 では、特に指定しないと ssh, telnet のログイン用に使われます。バージョンに依って line vty の中で指定が必要なものもある)
- line vty 0 15
- 以下で vty (telnet や、ssh などの仮想端末) 0番 ~ 15番 (=16回線) の設定をする
- exec-timeout 0 0
- アイドルタイマーを 0 に。自動ログアウトしなくなるので本番環境で設定しちゃダメ
- length 0
- ter len 0 がデフォルトになります。
- transport input telnet ssh
- telnet と ssh を許可します。ssh だけなら telnet は書いちゃダメ。同時接続数を減らしたければ line vty 0 15 を適当に調整
- logging synchronous
- コマンドを入力中にログが出力されると画面が見づらくなるが、ログが出力された場合、改行して入力中の文字を改めて表示する。
- monitor
- 通常コンソールで接続した時のみ、リアルタイムでログが表示されるが、telnet, ssh でもリアルタイムで表示するようにする。
コンソールの速度を変更する
conf t
line console
speed 115200
これは config なので、保存したら電源を切っても記憶されているので注意。
職場など、複数人で触る可能性がある場合はやらない方が吉。
ログの設定
clock timezone JST 9 0
service timestamps debug datetime msec localtime show-timezone
service timestamps log datetime msec localtime show-timezone
service sequence-numbers
logging buffered 512000
logging host <syslog サーバ>
logging trap informational
logging facility local5