VIRL にはデフォルトで Ubuntu のイメージが登録されています。VIRL 1.0.26 だと Ubuntu 14.04.2 LTS が登録されていました。
cisco@server-1:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.2 LTS Release: 14.04 Codename: trusty
今回は VIRL 上で Ubuntu を使ってみます。
検証環境
Router1 のコンフィグ
hostname Router1 ! interface GigabitEthernet0/1 ip address 192.168.1.1 255.255.255.0 no shutdown ! interface GigabitEthernet0/2 ip address 192.168.2.1 255.255.255.0 no shutdown ! end
Router2 のコンフィグ
hostname Router2 ! interface GigabitEthernet0/1 ip address 192.168.2.2 255.255.255.0 no shutdown ! ip route 0.0.0.0 0.0.0.0 192.168.2.1 ! end
Ubuntu を cloud-init で設定する
Ubuntu は cloud-init で設定します。ほぼデフォルトのままですが、構成に合わせてネットワーク設定を修正しています。
#cloud-config bootcmd: - ln -s -t /etc/rc.d /etc/rc.local hostname: server-1 manage_etc_hosts: true runcmd: - start ttyS0 - systemctl start getty@ttyS0.service - systemctl start rc-local - sed -i '/^\s*PasswordAuthentication\s\+no/d' /etc/ssh/sshd_config - echo "UseDNS no" >> /etc/ssh/sshd_config - service ssh restart - service sshd restart users: - default - gecos: User configured by VIRL Configuration Engine 0.21.6 lock-passwd: false name: cisco plain-text-passwd: cisco shell: /bin/bash ssh-authorized-keys: - VIRL-USER-SSH-PUBLIC-KEY sudo: ALL=(ALL) ALL write_files: - path: /etc/init/ttyS0.conf owner: root:root content: | # ttyS0 - getty # This service maintains a getty on ttyS0 from the point the system is # started until it is shut down again. start on stopped rc or RUNLEVEL=[12345] stop on runlevel [!12345] respawn exec /sbin/getty -L 115200 ttyS0 vt102 permissions: '0644' - path: /etc/systemd/system/dhclient@.service content: | [Unit] Description=Run dhclient on %i interface After=network.target [Service] Type=oneshot ExecStart=/sbin/dhclient %i -pf /var/run/dhclient.%i.pid -lf /var/lib/dhclient/dhclient.%i.lease RemainAfterExit=yes owner: root:root permissions: '0644' - path: /etc/rc.local owner: root:root permissions: '0755' content: |- #!/bin/sh ifconfig eth0 up 10.100.100.100 netmask 255.255.0.0 ifconfig eth1 up 192.168.1.100 netmask 255.255.255.0 route add -net 0.0.0.0/0 gw 10.100.254.254 dev eth0 route add -net 192.168.2.0/24 gw 192.168.1.1 dev eth1 exit 0
通信確認
Ubuntu のルーティングテーブルを確認すると、cloud-init で設定した経路が反映されています。
cisco@server-1:~$ ip route default via 10.100.254.254 dev eth0 10.100.0.0/16 dev eth0 proto kernel scope link src 10.100.100.100 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.100 192.168.2.0/24 via 192.168.1.1 dev eth1
Ubuntu から Router2 まで Ping で疎通性を確認します。
cisco@server-1:~$ ping 192.168.2.2 -c 3 PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data. 64 bytes from 192.168.2.2: icmp_seq=1 ttl=254 time=6.53 ms 64 bytes from 192.168.2.2: icmp_seq=2 ttl=254 time=6.47 ms 64 bytes from 192.168.2.2: icmp_seq=3 ttl=254 time=3.97 ms --- 192.168.2.2 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 3.971/5.662/6.539/1.195 ms
デフォルトでは /run/resolvconf/interface/eth0.dhclient に設定されている内容が resolvconf で反映され、DNS は 8.8.8.8 と 8.8.4.4 を参照するようになっていました。
# cat /run/resolvconf/interface/eth0.dhcl domain openstacklocal nameserver 8.8.4.4 nameserver 8.8.8.8
デフォルトの cloud-init
参考情報としてデフォルトの cloud-init を掲載しておきます。
#cloud-config bootcmd: - ln -s -t /etc/rc.d /etc/rc.local hostname: server-1 manage_etc_hosts: true runcmd: - start ttyS0 - systemctl start getty@ttyS0.service - systemctl start rc-local - sed -i '/^\s*PasswordAuthentication\s\+no/d' /etc/ssh/sshd_config - echo "UseDNS no" >> /etc/ssh/sshd_config - service ssh restart - service sshd restart users: - default - gecos: User configured by VIRL Configuration Engine 0.21.6 lock-passwd: false name: cisco plain-text-passwd: cisco shell: /bin/bash ssh-authorized-keys: - VIRL-USER-SSH-PUBLIC-KEY sudo: ALL=(ALL) ALL write_files: - path: /etc/init/ttyS0.conf owner: root:root content: | # ttyS0 - getty # This service maintains a getty on ttyS0 from the point the system is # started until it is shut down again. start on stopped rc or RUNLEVEL=[12345] stop on runlevel [!12345] respawn exec /sbin/getty -L 115200 ttyS0 vt102 permissions: '0644' - path: /etc/systemd/system/dhclient@.service content: | [Unit] Description=Run dhclient on %i interface After=network.target [Service] Type=oneshot ExecStart=/sbin/dhclient %i -pf /var/run/dhclient.%i.pid -lf /var/lib/dhclient/dhclient.%i.lease RemainAfterExit=yes owner: root:root permissions: '0644' - path: /etc/rc.local owner: root:root permissions: '0755' content: |- #!/bin/sh ifconfig eth1 up 10.0.0.6 netmask 255.255.255.252 route add -net 10.0.0.0/8 gw 10.0.0.5 dev eth1 route add -net 192.168.0.0/30 gw 10.0.0.5 dev eth1 exit 0