IKEv1 で証明書認証を使う【Cisco IOS】
IKEv1 で認証に証明書を使用する設定を検証しました。
環境
site-a-rtr と site-b-rtr の間で Static VTI を利用して IPSec Tunnel を確立させます。IPSec SA を確立するための IKEv1 で証明書認証を設定しました。
site-a-rtr を例に設定を解説していきますが site-b-rtr の設定もほぼ同じです。異なるパラメータを設定する必要がある場合は別途記載します。
また、上記とは別に Ubuntu 20.04 にプライベート CA を構築しました。
root@77db231258fe:~# lsb_release -d Description: Ubuntu 20.04.3 LTS root@77db231258fe:~#
ルーターから CA への疎通性ありません。証明書のやり取りはコピー&ペーストで行いました。
証明書登録作業
プライベート CA の構築とルーターに証明書を登録します。
プライベート CA の構築
CA.pl
を利用することで簡易なプライベート CA を構築することができます。
root@77db231258fe:~# /usr/lib/ssl/misc/CA.pl -newca CA certificate filename (or enter to create) Making CA certificate ... ==== openssl req -new -keyout ./demoCA/private/cakey.pem -out ./demoCA/careq.pem Generating a RSA private key ...................+++++ ................................+++++ writing new private key to './demoCA/private/cakey.pem' Enter PEM pass phrase: Verifying - Enter PEM pass phrase: ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:JP State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []:myrootca.example.co.jp Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: ==> 0 ==== ==== openssl ca -create_serial -out ./demoCA/cacert.pem -days 1095 -batch -keyfile ./demoCA/private/cakey.pem -selfsign -extensions v3_ca -infiles ./demoCA/careq.pem Using configuration from /usr/lib/ssl/openssl.cnf Enter pass phrase for ./demoCA/private/cakey.pem: Check that the request matches the signature Signature ok Certificate Details: Serial Number: 7d:3c:cf:bf:4c:52:4f:13:ae:05:d0:7b:8b:90:7d:62:7e:85:54:22 Validity Not Before: Dec 27 14:00:07 2021 GMT Not After : Dec 26 14:00:07 2024 GMT Subject: countryName = JP stateOrProvinceName = Some-State organizationName = Internet Widgits Pty Ltd commonName = myrootca.example.co.jp X509v3 extensions: X509v3 Subject Key Identifier: 08:CA:D1:7C:6E:A5:2F:8A:FD:80:82:9C:DD:13:15:FE:44:C5:AA:B7 X509v3 Authority Key Identifier: keyid:08:CA:D1:7C:6E:A5:2F:8A:FD:80:82:9C:DD:13:15:FE:44:C5:AA:B7 X509v3 Basic Constraints: critical CA:TRUE Certificate is to be certified until Dec 26 14:00:07 2024 GMT (1095 days) Write out database with 1 new entries Data Base Updated ==> 0 ==== CA certificate is in ./demoCA/cacert.pem root@77db231258fe:~#
CA に必要なファイル群が./demoCA
に配置されます。
root@77db231258fe:~# tree . `-- demoCA |-- cacert.pem |-- careq.pem |-- certs |-- crl |-- crlnumber |-- index.txt |-- index.txt.attr |-- index.txt.old |-- newcerts | `-- 7D3CCFBF4C524F13AE05D07B8B907D627E855422.pem |-- private | `-- cakey.pem `-- serial 5 directories, 9 files root@77db231258fe:~#
./demoCA/cacert.pem
が今回構築したCAの証明書になります。
プライベートCAの証明書をルーターに登録
プライベート CA の証明書をルーターに登録するために CA の証明書をメモしておきます。
root@77db231258fe:~# openssl x509 -in demoCA/cacert.pem -----BEGIN CERTIFICATE----- MIIDrTCCApWgAwIBAgIUfTzPv0xSTxOuBdB7i5B9Yn6FVCIwDQYJKoZIhvcNAQEL ** 省略 ** JcuITZvnfwU8Ye7iDcT2KTUd6RzGhFTR2AyQf+o5Pt6o -----END CERTIFICATE----- root@77db231258fe:~#
ルーターに trustpoint
を作成してプライベート CA の証明書を登録します。
site-a-rtr(config)# site-a-rtr(config)# site-a-rtr(config)#crypto pki trustpoint mytp site-a-rtr(ca-trustpoint)# site-a-rtr(ca-trustpoint)#enrollment terminal pem site-a-rtr(ca-trustpoint)# site-a-rtr(ca-trustpoint)#crypto pki authenticate mytp Enter the base 64 encoded CA certificate. End with a blank line or the word "quit" on a line by itself -----BEGIN CERTIFICATE----- MIIDrTCCApWgAwIBAgIUfTzPv0xSTxOuBdB7i5B9Yn6FVCIwDQYJKoZIhvcNAQEL ** 省略 ** JcuITZvnfwU8Ye7iDcT2KTUd6RzGhFTR2AyQf+o5Pt6o -----END CERTIFICATE----- quit Certificate has the following attributes: Fingerprint MD5: 754A6222 8E1B5196 BECFCDB2 6A04D0B4 Fingerprint SHA1: 37D5FBD8 69A755C9 51184215 13318A3A 9386BC01 % Do you accept this certificate? [yes/no]: yes Trustpoint CA certificate accepted. % Certificate successfully imported site-a-rtr(config)# site-a-rtr(config)#
ルーターで証明書署名要求(CSR) を生成
ルーターの証明書をプライベート CA に署名してもらうために、CSR を生成します。
証明書に使う rsa keypair
を生成します。
site-a-rtr(config)#ip domain name example.co.jp site-a-rtr(config)#crypto key generate rsa signature label mytp-rsa-key The name for the keys will be: mytp-rsa-key Choose the size of the key modulus in the range of 360 to 4096 for your Signature Keys. Choosing a key modulus greater than 512 may take a few minutes. How many bits in the modulus [512]: 1024 % Generating 1024 bit RSA keys, keys will be non-exportable... [OK] (elapsed time was 1 seconds) site-a-rtr(config)#
CSR を出力します。
site-b-rtr では CN=site-b-rtr.example.co.jp
とします。
site-a-rtr(config)#crypto pki trustpoint mytp site-a-rtr(ca-trustpoint)#subject-name CN=site-a-rtr.example.co.jp site-a-rtr(ca-trustpoint)#revocation-check none site-a-rtr(ca-trustpoint)#rsakeypair mytp-rsa-key site-a-rtr(ca-trustpoint)#crypto pki enroll mytp % Start certificate enrollment .. % The subject name in the certificate will include: CN=site-a-rtr.example.co.jp % The subject name in the certificate will include: site-a-rtr.example.co.jp % Include the router serial number in the subject name? [yes/no]: no % Include an IP address in the subject name? [no]: no Display Certificate Request to terminal? [yes/no]: yes Certificate Request follows: -----BEGIN CERTIFICATE REQUEST----- MIIBrTCCARYCAQAwTDEhMB8GA1UEAxMYc2l0ZS1hLXJ0ci5leGFtcGxlLmNvLmpw ** 省略 ** Km1r+edxafhgYgdXhKpVB//EQXSF41V6WFJAgwM/zb1UkctkKyO0dnnII/05tH8Q Qg== -----END CERTIFICATE REQUEST----- ---End - This line not part of the certificate request--- Redisplay enrollment request? [yes/no]: no site-a-rtr(config)#
-----BEGIN CERTIFICATE REQUEST-----
から -----END CERTIFICATE REQUEST-----
までが CSR となるのでメモしておきます。
ルーターの証明書を署名
ルーターの CSR をプライベート CA に取り込みます。
root@77db231258fe:~# cat << 'EOF' > site-a-rtr.csr > -----BEGIN CERTIFICATE REQUEST----- > MIIBrTCCARYCAQAwTDEhMB8GA1UEAxMYc2l0ZS1hLXJ0ci5leGFtcGxlLmNvLmpw ** 省略 ** > Km1r+edxafhgYgdXhKpVB//EQXSF41V6WFJAgwM/zb1UkctkKyO0dnnII/05tH8Q > Qg== > -----END CERTIFICATE REQUEST----- > EOF root@77db231258fe:~#
プライベート CA でルーターの証明書を発行します。
root@77db231258fe:~# openssl ca -in site-a-rtr.csr -policy policy_anything -out site-a-rtr.crt Using configuration from /usr/lib/ssl/openssl.cnf Enter pass phrase for ./demoCA/private/cakey.pem: Check that the request matches the signature Signature ok Certificate Details: Serial Number: 7d:3c:cf:bf:4c:52:4f:13:ae:05:d0:7b:8b:90:7d:62:7e:85:54:23 Validity Not Before: Dec 29 00:07:54 2021 GMT Not After : Dec 29 00:07:54 2022 GMT Subject: commonName = site-a-rtr.example.co.jp X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: F9:2B:6B:F6:86:ED:23:8F:42:DF:BE:C6:17:50:5C:CF:0F:F5:E1:3E X509v3 Authority Key Identifier: keyid:08:CA:D1:7C:6E:A5:2F:8A:FD:80:82:9C:DD:13:15:FE:44:C5:AA:B7 Certificate is to be certified until Dec 29 00:07:54 2022 GMT (365 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated root@77db231258fe:~#
発行された証明書を確認します。
root@77db231258fe:~# openssl x509 -in site-a-rtr.crt -----BEGIN CERTIFICATE----- MIIDDjCCAfagAwIBAgIUfTzPv0xSTxOuBdB7i5B9Yn6FVCMwDQYJKoZIhvcNAQEL ** 省略 ** llRtLbuzhfRTYrUY0qHl64Lx -----END CERTIFICATE----- root@77db231258fe:~#
-----BEGIN CERTIFICATE-----
から -----END CERTIFICATE-----
までが site-a-rtr の証明書となるのでメモしておきます。
発行された証明書をルーターに登録
site-a-rtr(config)#crypto pki import mytp certificate Enter the base 64 encoded certificate. End with a blank line or the word "quit" on a line by itself -----BEGIN CERTIFICATE----- MIIDDjCCAfagAwIBAgIUfTzPv0xSTxOuBdB7i5B9Yn6FVCMwDQYJKoZIhvcNAQEL ** 省略 ** llRtLbuzhfRTYrUY0qHl64Lx -----END CERTIFICATE----- quit Received General Purpose certificate for signature keypair Do you wish to accept this certificate? [yes/no]: yes % Router Certificate successfully imported site-a-rtr(config)#
登録内容が正しいことを確認します。
site-a-rtr#show crypto pki certificates Certificate Status: Available Certificate Serial Number (hex): 7D3CCFBF4C524F13AE05D07B8B907D627E855423 Certificate Usage: General Purpose Issuer: cn=myrootca.example.co.jp o=Internet Widgits Pty Ltd st=Some-State c=JP Subject: Name: site-a-rtr.example.co.jp cn=site-a-rtr.example.co.jp Validity Date: start date: 00:07:54 UTC Dec 29 2021 end date: 00:07:54 UTC Dec 29 2022 Associated Trustpoints: mytp CA Certificate Status: Available Certificate Serial Number (hex): 7D3CCFBF4C524F13AE05D07B8B907D627E855422 Certificate Usage: General Purpose Issuer: cn=myrootca.example.co.jp o=Internet Widgits Pty Ltd st=Some-State c=JP Subject: cn=myrootca.example.co.jp o=Internet Widgits Pty Ltd st=Some-State c=JP Validity Date: start date: 14:00:07 UTC Dec 27 2021 end date: 14:00:07 UTC Dec 26 2024 Associated Trustpoints: mytp site-a-rtr#
これで証明書の登録は完了です。
IKEv1 の設定
証明書登録作業はインタラクティブな設定が多いので configuration mode の出力を掲載していましたが、これ以降は config をそのまま掲載します。
ISAKMP profile
isakmp profile
に証明書を登録した trustpoint
を紐付けます。site-a-rtr の設定では、 match identity
に site-b-rtr の FQDN である site-b-rtr.example.co.jp
を指定します。site-b-rtr の match identity
には site-a-rtr の FQDN を指定します。
crypto isakmp profile isakmp-profile1 self-identity fqdn ca trust-point mytp match identity host site-b-rtr.example.co.jp
IPsec profile / IPsec transform-set
ipsec profile
に先に作成した isakmp profile
を紐付けます。
crypto ipsec transform-set ESP-AES-SHA esp-aes esp-sha-hmac mode tunnel crypto ipsec profile ipsec-profile1 set transform-set ESP-AES-SHA set isakmp-profile isakmp-profile1
show crypto ipsec profile <profile name>
で設定内容を確認できます。
site-a-rtr#show crypto ipsec profile ipsec-profile1 IPSEC profile ipsec-profile1 ISAKMP Profile: isakmp-profile1 Security association lifetime: 4608000 kilobytes/3600 seconds Responder-Only (Y/N): N PFS (Y/N): N Mixed-mode : Disabled Transform sets={ ESP-AES-SHA: { esp-aes esp-sha-hmac } , } site-a-rtr#
interface Tunnel0
Tunnel
インターフェースに ipsec profile
を紐付けます。
interface Tunnel0 ip address 10.0.0.0 255.255.255.254 tunnel source GigabitEthernet0/0 tunnel mode ipsec ipv4 tunnel destination 203.0.113.1 tunnel protection ipsec profile ipsec-profile1 end
tunnel0
を no shut
すると IKEv1 のセッションが開始されます。Protocol up になっていれば IPSec トンネルが確立できています。
site-a-rtr#show ip int brief tu 0 Interface IP-Address OK? Method Status Protocol Tunnel0 10.0.0.0 YES manual up up site-a-rtr#
疎通確認
IKEv1 SA
認証方式 (Auth) が証明書 (sig) の IKEv1 セッションが確立できていることが確認できました。
site-a-rtr#show crypto isakmp sa detail Codes: C - IKE configuration mode, D - Dead Peer Detection K - Keepalives, N - NAT-traversal T - cTCP encapsulation, X - IKE Extended Authentication psk - Preshared key, rsig - RSA signature renc - RSA encryption IPv4 Crypto ISAKMP SA C-id Local Remote I-VRF Status Encr Hash Auth DH Lifetime Cap. 1019 203.0.113.0 203.0.113.1 ACTIVE aes sha rsig 5 23:55:16 Engine-id:Conn-id = SW:19 1020 203.0.113.0 203.0.113.1 ACTIVE aes sha rsig 5 23:55:16 Engine-id:Conn-id = SW:20 IPv6 Crypto ISAKMP SA site-a-rtr#
client1 と client2 の通信
client1 と client2 で通信を行い、パケットが暗号化できていることを確認します。
site-a-rtr から 172.16.0.0/24 への static route を設定します。
site-a-rtr#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks C 10.0.0.0/31 is directly connected, Tunnel0 L 10.0.0.0/32 is directly connected, Tunnel0 172.16.0.0/24 is subnetted, 1 subnets S 172.16.0.0 [1/0] via 10.0.0.1 192.168.0.0/24 is variably subnetted, 2 subnets, 2 masks C 192.168.0.0/24 is directly connected, GigabitEthernet0/1 L 192.168.0.254/32 is directly connected, GigabitEthernet0/1 203.0.113.0/24 is variably subnetted, 2 subnets, 2 masks C 203.0.113.0/31 is directly connected, GigabitEthernet0/0 L 203.0.113.0/32 is directly connected, GigabitEthernet0/0 site-a-rtr#
site-b-rtr でも同様に 192.168.0.0/24 の static route を設定します。
site-b-rtr#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks C 10.0.0.0/31 is directly connected, Tunnel0 L 10.0.0.1/32 is directly connected, Tunnel0 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks C 172.16.0.0/24 is directly connected, GigabitEthernet0/1 L 172.16.0.254/32 is directly connected, GigabitEthernet0/1 S 192.168.0.0/24 [1/0] via 10.0.0.0 203.0.113.0/24 is variably subnetted, 2 subnets, 2 masks C 203.0.113.0/31 is directly connected, GigabitEthernet0/0 L 203.0.113.1/32 is directly connected, GigabitEthernet0/0 site-b-rtr#
site-a-rtr gi 0/0 のパケットキャプチャを有効にした状態で client1 から client2 に ping します。
cisco@client1:~$ ip -4 a show dev ens2 2: ens2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 inet 192.168.0.1/24 brd 192.168.0.255 scope global ens2 valid_lft forever preferred_lft forever cisco@client1:~$ cisco@client1:~$ ping -c 3 172.16.0.1 PING 172.16.0.1 (172.16.0.1) 56(84) bytes of data. 64 bytes from 172.16.0.1: icmp_seq=1 ttl=62 time=4.92 ms 64 bytes from 172.16.0.1: icmp_seq=2 ttl=62 time=5.27 ms 64 bytes from 172.16.0.1: icmp_seq=3 ttl=62 time=14.3 ms --- 172.16.0.1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 4.921/8.154/14.269/4.325 ms cisco@client1:~$
パケットが暗号化されて転送されていることが確認できました。暗号化されているので ICMP のパケットを観測することはできませんが、ESP ヘッダーの Security Parameter Index (SPI) が show crypto ipsec sa
で出力される値と一致していることが確認できます。
site-a-rtr#show crypto ipsec sa interface tu 0 interface: Tunnel0 Crypto map tag: Tunnel0-head-0, local addr 203.0.113.0 protected vrf: (none) local ident (addr/mask/prot/port): (0.0.0.0/0.0.0.0/0/0) remote ident (addr/mask/prot/port): (0.0.0.0/0.0.0.0/0/0) current_peer 203.0.113.1 port 500 <-- snip --> inbound esp sas: spi: 0xBB80036A(3145728874) ※ここ transform: esp-aes esp-sha-hmac , <-- snip --> outbound esp sas: spi: 0xF07EC953(4034840915) ※ここ transform: esp-aes esp-sha-hmac , <-- snip --> site-a-rtr#
フレッツ光のサービス情報サイトに IPv4 で接続するためにIOSで PPPoE マルチセッションを設定する
フレッツ光のサービス情報サイトに IPv4 で接続するために、Cisco 891FJ に PPPoE マルチセッションの設定を行いました。
NGN とは
NTT が電話やインターネットサービスを提供するために構築しているネットワーク基盤です。フレッツ光では、契約情報や工事情報などの各種サポート情報を提供するためのサイトを NGN 内のサーバーで提供しています。
サービス情報サイト接続方法|サービス情報サイト(NGN IPv4)|フレッツ光公式|NTT東日本|インターネット接続ならフレッツ光
IPv4 でインターネットに接続している場合、NGN に直接アクセスすることは出来ません。IPv4 でサービス情報サイトに接続するためには、PPPoE でセッションを貼る必要があります。
本記事では以下の設定を IOS (Cisco 891FJ) に対して行います。
ブロードバンドルーター接続方法|サービス情報サイト(IPv4)|フレッツ公式|NTT東日本
Cisco 891FJ の設定
必要な設定
- PPPoE のための Dialer Interface の作成
- 物理インターフェースに作成した Dial を割り当て
- static route の設定
- サービス情報サイトでは次のアドレスを使用しているため、static routeを設定する必要があります。
- 220.210.194.0/25
- 123.107.190.0/24
- 220.210.198.0/26
- サービス情報サイトでは次のアドレスを使用しているため、static routeを設定する必要があります。
- NATの設定
設定を抜粋して掲載します。
! ONU に接続しているインターフェース interface GigabitEthernet8 description To-ONU ! 今回設定した PPPoE セッション pppoe-client dial-pool-number 2 ! ISP に接続するための PPPoE セッション ! インターネットに接続する際はこちらから出ていく。 pppoe-client dial-pool-number 1 ! フレッツ光に接続するための Dialer Interface の作成 interface Dialer2 description NGN_IPv4 mtu 1454 ip address negotiated ip nat outside ip virtual-reassembly in encapsulation ppp ip tcp adjust-mss 1414 dialer pool 2 dialer idle-timeout 0 dialer-group 2 ppp authentication chap callin ppp chap hostname guest@v4flets-east.jp ppp chap password 0 guest ! ip を許可 dialer-list 2 protocol ip permit ! インターネットへの接続では Dialer1 で PAT を行い、フレッツ光情報サイトへの接続では Dialer2 で PAT をする ip nat inside source route-map EXCLUDE_NGN_IPv4_FOR_PAT interface Dialer1 overload ip nat inside source route-map TO_ONLY_NGN_IPv4_FOR_PAT interface Dialer2 overload ip access-list extended EXCLUDE_NGN_IPv4 deny ip any 123.107.190.0 0.0.0.255 deny ip any 220.210.194.0 0.0.0.127 deny ip any 220.210.198.0 0.0.0.63 permit ip any any ip access-list extended TO_ONLY_NGN_IPv4 permit ip any 123.107.190.0 0.0.0.255 permit ip any 220.210.194.0 0.0.0.127 permit ip any 220.210.198.0 0.0.0.63 route-map EXCLUDE_NGN_IPv4_FOR_PAT permit 10 match ip address EXCLUDE_NGN_IPv4 route-map TO_ONLY_NGN_IPv4_FOR_PAT permit 10 match ip address TO_ONLY_NGN_IPv4 ! フレッツ光情報サイトへの static route ip route 123.107.190.0 255.255.255.0 Dialer2 ip route 220.210.194.0 255.255.255.128 Dialer2 ip route 220.210.198.0 255.255.255.192 Dialer2
DNS の設定
Router で上記の設定を行えばIPでの疎通が出来るようになります。
ただし、サービス情報サイトを閲覧するためには*.v4flets-east.jp
を名前解決できる必要があります。*.v4flets-east.jp
を名前解決するには、フレッツのDNSサーバーに問い合わせる必要があります。
public dns で名前解決しようとしても失敗します。
# Google DNS サーバー ubuntu@unbound:~$ dig @8.8.8.8 v4flets-east.jp ns +short ubuntu@unbound:~$ # フレッツのDNS サーバー ubuntu@unbound:~$ dig @220.210.194.67 v4flets-east.jp ns +short ns1.v4flets-east.jp. ns2.v4flets-east.jp. ubuntu@unbound:~$
私の環境ではDNSキャッシュサーバーとして unbound を使ってるので、*.v4flets-east.jp
はフレッツ光のDNSサーバーに問い合わせるように設定しました。
ubuntu@unbound:~$ cat /etc/unbound/unbound.conf.d/zone.conf stub-zone: name: "v4flets-east.jp." stub-addr: 220.210.194.67 stub-addr: 220.210.194.68 forward-zone: name: "." forward-addr: 8.8.8.8 ubuntu@unbound:~$
【Go】channel の状態と操作の対応
Go言語による並行処理 | Katherine Cox-Buday, 山口 能迪 |本 | 通販 | Amazon を読んで goroutine と channel ついて1から勉強してる。
すぐ忘れるので channel の状態と操作の対応を自分用にメモ。
操作 | 状態 | 結果 |
---|---|---|
read | nil | ブロック |
Open で空ではない | (値, true) | |
Open で空 | ブロック | |
Close | (デフォルト値, false) | |
書き込み専用 | コンパイルエラー | |
write | nil | ブロック |
Open で空ではない | 値を書き込む | |
Open で空 | ブロック | |
Close | panic 発生 | |
読み込み専用 | コンパイルエラー | |
close | nil | panic 発生 |
Open で空ではない | チャネルを閉じる。 読み込みはチャネルが空になるまでは成功する。 |
|
Open で空 | チャネルを閉じる。 | |
Close | panic 発生 | |
読み込み専用 | コンパイルエラー |
CML 2.0 に起動したノードのコンソールにターミナルソフトからアクセスする
CML 2.0 に起動したノードのコンソールにターミナルソフトからアクセスするためには、Breout Tool を介して telnet 接続する必要があります。この Breakout Tool は CML 2.0 とは別に用意する必要があります。
Virl 1.x では Virl サーバーに直接 telnet することでノードのコンソールにアクセスすることが出来ました。しかし、CML 2.0 (Virl2.0) ではこの方法でのアクセスは出来なくなっています。CML 2.0 は Virl 1.x に比べるとかなり使いやすくなっていますが、デフォルトだとブラウザ経由でしかコンソールアクセスが出来ません。
Cisco Modeling Labs 2.0 Release Notes - Cisco Modeling Labs 2.0 [Cisco Modeling Labs] - Cisco
本記事ではローカルの Mac 上で Breakout Tool を起動し、CML 2.0 に起動したノードにターミナルソフトからコンソール接続する方法を紹介します。
CML 2.0 Lab
接続対象として、以下のような Lab を作成しておきます。
Breakout Tool
Breakout Tool のダウンロード
CML のトップページから Tools -> Breakout を選択します。
ページの下部にダウンロードリンクがあります。
今回は Mac で Breakout Tool を動かすので breakout-macos-x86_amd64
をローカルマシンにダウンロードします。
適当なディレクトリを作成し、ダウンロードしたbreakout-macos-x86_amd64
を配置します。今回はホームディレクトリの直下にbreakout
ディレクトリを作成しました。
nozawana44@MacBookPro ~% mkdir ~/breakout nozawana44@MacBookPro ~% cp Downloads/breakout-macos-x86_amd64 ~/breakout
Breakout Tool の起動
ターミナルから実行権限を付与し、ui
オプションを付けて起動します。
nozawana44@MacBookPro breakout % chmod +x breakout-macos-x86_amd64 nozawana44@MacBookPro breakout % ./breakout-macos-x86_amd64 ui Starting up... W0527 21:45:12.920949 71142 run.go:238] open labs.yaml: no such file or directory Running... Serving UI/API on http://[::1]:8080, Ctrl-C to stop.
Breakout Tool に接続
http://localhost:8080 に接続して Configuration ページに移動します。
以下のように設定して Save します。
Labs タブで更新のボタンをクリックして CML 2.0 で作成した Lab が表示されれば、Breakout tools の設定は完了です。
ノードのコンソールに接続
接続したい Lab の Status を On にして、Lab 名をクリックします。
Links にかかれているアドレスに telnet することで CML 2.0 で起動したノードのコンソールにアクセスできます。
nozawana44@MacBookPro ~ % telnet localhost 9000 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. ************************************************************************** * IOSv is strictly limited to use for evaluation, demonstration and IOS * * education. IOSv is provided as-is and is not supported by Cisco's * * Technical Advisory Center. Any use or disclosure, in whole or in part, * * of the IOSv Software or Documentation to any third party for any * * purposes is expressly prohibited except as otherwise authorized by * * Cisco in writing. * ************************************************************************** inserthostname_here> inserthostname_here>
Telnet URL スキームを iTerm2 で開くように設定しておけば、Breakout Tool のリンクをクリックするだけで Telnet することもできます。
私は以下のページを参考に設定しました。
macOS Catalinaでtelnet URLスキームを手軽に扱う | ネットワークとともに
まとめ
CML 2.0 に起動したノードのコンソールに Mac のターミナルソフトからアクセスする方法をまとめました。
CML 2.0 を利用してみた感想としては、かなり使いやすいので検証や学習におすすめです。年間 $199 のライセンス料はかかりますが払う価値はあると思います。
Mac で IP を手動設定するときは必ず DNS を指定する
Mac ではインターフェイスに DNS の指定をしないと、インターフェイスに設定したデフォルトルートが有効になりません。
IPの疎通確認をする際に同セグメントには通信できるが、別セグメントには通信できないという事象が発生します。
検証
以下の環境で解説します。
~ % sw_vers ProductName: Mac OS X ProductVersion: 10.15.4 BuildVersion: 19E287 ~ %
次のように IP, Default GW, DNS を手動設定します。
Mac のデフォルトルートを確認します。
~ % route -n get default route to: default destination: default mask: default gateway: 192.168.1.254 interface: en0 flags: <UP,GATEWAY,DONE,STATIC,PRCLONING> recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 0 0 0 0 0 0 1500 0 ~ %
設定したデフォルトルートがMac に反映されていることがわかります。
続いてDNSの設定を削除して、デフォルトルートを確認してみます。
~ % route -n get default route: writing to routing socket: not in table ~ %
設定は行っているのにも関わらず、デフォルトルートが Mac に反映されていません。この状態から ping を実行してみます。
~ % ping -c 1 1.1.1.1 PING 1.1.1.1 (1.1.1.1): 56 data bytes ping: sendto: No route to host ^C --- 1.1.1.1 ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss ~ %
ping: sendto: No route to host
:宛先へのルートがないことを示すメッセージが表示されました。
まとめ
Mac で IP を手動設定する際の注意点についてまとめました。Mac をネットワークの検証に使用するときは、DNS の指定を忘れないようにしましょう。
補足
GNS3 on GCP を構築してGNS3のネットワークにローカルPCからアクセスする
構築した環境
GCP Compute Engine に GNS3 と OpenVPN をデプロイして、GNS3 のネットワークにローカルから接続できるようにしました。
GNS3 on GCP のメリット
GCP の準備
プロジェクトの作成
新しくプロジェクトを作成(GNS3)し、その中で作業を進めます。リージョンは asia-northeast1 (東京) 、ゾーンは asia-northeast1-b を使います。
カスタムブートイメージの作成
Ubuntu 18.04 をベースに、Nested KVM を有効にしたカスタムブートイメージを作成します。作成のためには Cloud API を操作する必要があるので Cloud Shell を使用しました。
gcpuser1@cloudshell:~$ gcloud projects list
PROJECT_ID NAME PROJECT_NUMBER
gns3-2xxxx1 GNS3 328517071241
gcpuser1@cloudshell:~$ gcloud config set project gns3-2xxxx1 # 操作対象の Project を選択
Updated property [core/project].
gcpuser1@cloudshell:~ (gns3-2xxxx1)$
gcpuser1@cloudshell:~ (gns3-2xxxx1)$ gcloud compute disks create disk1 --image-project ubuntu-os-cloud --image-family ubuntu-1804-lts --zone asia-northeast1-b
Created [https://www.googleapis.com/compute/v1/projects/gns3-2xxxx1/zones/asia-northeast1-b/disks/disk1].
NAME ZONE SIZE_GB TYPE STATUS
disk1 asia-northeast1-b 10 pd-standard READY
gcpuser1@cloudshell:~ (gns3-2xxxx1)$
gcpuser1@cloudshell:~ (gns3-2xxxx1)$ gcloud compute images create nested-vm-image \
> --source-disk disk1 --source-disk-zone asia-northeast1-b \
> --licenses "https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx" # Nested KVM の有効化
Created [https://www.googleapis.com/compute/v1/projects/gns3-2xxxx1/global/images/nested-vm-image].
NAME PROJECT FAMILY DEPRECATED STATUS
nested-vm-image gns3-2xxxx1 READY
gcpuser1@cloudshell:~ (gns3-2xxxx1)$
Nested KVM を有効にしたイメージ nested-vm-image
が作成されました。
インスタンス起動
作成したイメージからインスタンスを起動します。ブートディスクに作成したカスタムブートイメージを指定しています。マシンタイプは余裕をもって n1-standard-2 を選択していますが n1-standard-1 でも重いシミュレーションを動かさなければ十分動作しました。
インスタンスの起動が完了すると、エフェメラル IP が振られます。エフェメラル IP はインスタンスが停止すると変更される可能性があるので、常用の検証環境として起動・停止を繰り返す環境であれば、静的 IP を設定しておく必要があります。(参考:公式ドキュメント)今回はエフェメラル IP のまま進めます。
GNS3 と OpenVPN のインストール
起動したインスタンスに SSH ログインをして設定を行っていきます。公式レポジトリから GNS3 と Open VPN をインストールして再起動します。
root@gns3-server:~# apt-get update
root@gns3-server:~# apt-get -y upgrade
root@gns3-server:~# cd /tmp
root@gns3-server:/tmp# curl -s https://raw.githubusercontent.com/GNS3/gns3-server/master/scripts/remote-install.sh > gns3-remote-install.sh
root@gns3-server:/tmp# bash gns3-remote-install.sh --with-openvpn --with-iou --with-i386-repository
root@gns3-server:~# reboot
GNS3 から外部に接続するための linux-bridge の設定します。
root@gns3vm:~# cd /etc/netplan/
root@gns3vm:/etc/netplan# vim 99-gns3br0.yaml
root@gns3vm:/etc/netplan# cat /etc/netplan/99-gns3br0.yaml
network:
version: 2
renderer: networkd
bridges:
gns3br0:
addresses:
- 172.16.0.1/24
root@gns3vm:/etc/netplan# netplan apply
OpenVPN のインストールが完了すると、/root
に OpenVPN のクライアント用設定ファイルが作成されます。ローカルから疎通性をもたせる GNS3 のネットワーク(gns3br0 : 172.16.0.0/24
)へのルートを設定ファイルに追加します。
root@gns3vm:~# ls
client.ovpn
root@gns3vm:~# echo "route 172.16.0.0 255.255.255.0" >> client.ovpn
root@gns3vm:~#
OpenVPN の通信は UDP 1194 ポートを使用します。この通信を許可するファイアウォールルールを GCP VPC 追加します。
OpenVPN で GCP インスタンスに接続
OpenVPN Client ソフトウェアをローカルにインストールします。今回は MacOS で接続を行うので Tunnelblick を利用します。
GCP インスタンスから設定ファイル(client.ovpn
)をローカルにダウンロードし、Tunnelblick にインポートして VPN 接続します。ローカルPC から、GCPインスタンスの gns3br0
へ ping が通れば VPN 接続は完了です。
user1@local ~ % ping -c 1 172.16.0.1
PING 172.16.0.1 (172.16.0.1): 56 data bytes
64 bytes from 172.16.0.1: icmp_seq=0 ttl=64 time=28.248 ms
--- 172.16.0.1 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 28.248/28.248/28.248/0.000 ms
user1@local ~ %
GNS3 の設定
GNS3 Client をローカルで起動して、サーバーに GCP インスタンスを指定します。
GNS3 -> Preferences -> Server
動作確認
次のようなトポロジーを作成し、vEOS の Management1 にローカルからアクセス出来るようにします。 Cloud1 の Ethernet Interfaces の設定で、作成した gns3br0
を追加します。gns3br0
を追加するためには Show special Ethernet Interfaces にチェックを入れる必要があります。
vEOS のコンソールから、最低限の設定を行います。(Management interface 、デフォルトルート、admin ユーザー)
vEOS-1
localhost login: admin
localhost>
localhost>en
localhost#conf t
localhost(config)#hostname vEOS-1
vEOS-1(config)#int management 1
vEOS-1(config-if-Ma1)#ip address 172.16.0.101/24
vEOS-1(config-if-Ma1)#exit
vEOS-1(config)#ip route 0.0.0.0/0 172.16.0.1
vEOS-1(config)#
vEOS-1(config)#username admin secret password
vEOS-2
localhost login: admin
localhost>en
localhost#conf t
localhost(config)#hostname vEOS-2
vEOS-2(config)#int management 1
vEOS-2(config-if-Ma1)#ip address 172.16.0.102/24
vEOS-2(config-if-Ma1)#exit
vEOS-2(config)#ip route 0.0.0.0/0 172.16.0.1
vEOS-2(config)#
vEOS-2(config)#username admin secret password
ローカルPC から GCP で動いている GNS3上の仮想スイッチに対して直接アクセスする準備が整いました。ローカルから仮想スイッチに対して ssh 接続してみます。
ローカルPC -> vEOS-1
user1@local ~ % ssh admin@172.16.0.101
Password:
Last login: Sat Nov 2 05:04:29 2019 from 172.16.253.6
vEOS-1>en
vEOS-1#show ip int brief
Interface IP Address Status Protocol MTU
Management1 172.16.0.101/24 up up 1500
vEOS-1#
ローカルPC -> vEOS-2
user1@local ~ % ssh admin@172.16.0.102
Password:
vEOS-2>en
vEOS-2#show ip int brief
Interface IP Address Status Protocol MTU
Management1 172.16.0.102/24 up up 1500
vEOS-2#
ローカルPC から GNS3 on GCP の仮想ネットワークに直接アクセスできることを確認できました。