vyOSのインストール

投稿者: | 5月 23, 2020

前回vyOSのコンパイル方法を書いたが、今回は使う方法。

メディアはRolling Releaseをダウンロードするかコンパイルする。

Rolling Release https://www.vyos.io/rolling-release/

コンパイルするなら https://www.blog.slow-fire.net/2020/02/14/vyosリリース版インストール/

そんなに難しくない。いや難しい方法はやらない。。。というか必要になったら調べればいい。使ったことないけど、たくさんの機能がある。だいたい、vyOSかEdgerouterがあれば、あとはストレージとハイパーバイザーがあれば、ラボとしては必要になるであろう機能が全て揃う。vyOSのいいところは、ルーターだけではなく、ちょいちょいのサービスが付いているのが地味に便利。Ciscoのルーターが単体のiSCSIストレージと例えるならば、vyOSやEdgerouterは、マルチプロトコル(SMB/NFS/iSCSI)のNASに近い。

仮想マシン構築
Compatibilityは最新のプラットフォーム vSphere 6.7 U2
OSの設定はDebian GNU/Linux 10 (64bit) (最低でもDebian GNU/Linux 8 (64bit以上)

以下の設定を変更、設定する
CPU: 1
Mem: 512MB
HDD: 2GB (Thin Provisioning)以上あればいい。
Network: vmxnet3
    外部ネットワーク:1番目(eth0)
    内側ネットワーク:2番目(eth1)
にする。ちなみにvSphere 6.7は、eth9まで(10NIC)指定できる。
CD-ROMにvyOSのISO Imageを指定

9FBE6B4A 8D17 44EA BE3D EF640272F019

275AB1C0 796D 4C85 A20D B73F2549F592

TIPSだが、接続するvSphereのVM NetworkのVLAN IDを4095にしておくとvyOS側でVLAN作り放題。何も考えないでVLAN ID 4095にしておくことをおすすめしておく。通常の利用でも何も考える必要はない。

インストール

起動したら以下でログイン
ユーザ名 vyos
パスワード vyos
ログイン後、以下を実行

vyos@vyos:~$ install image

Welcome to the VyOS install program. This script
will walk you through the process of installing the
VyOS image to a local hard drive.
Would you like to continue? (Yes/No) [Yes]: [return]
Probing drives: OK
Looking for pre-existing RAID groups…none found.
The VyOS image will require a minimum 2000MB root.
Would you like me to try to partition a drive automatically
or would you rather partition it manually with parted? If
you have already setup your partitions, you may skip this step
Partition (Auto/Parted/Skip) [Auto]: [return]
I found the following drives on your system:
sda 2147MB
Install the image on? [sda]: [return]
This will destroy all data on /dev/sda.
Continue? (Yes/No) [No]: Yes
How big of a root partition should I create? (2000MB – 2147MB) [2147]MB: [return]
Creating filesystem on /dev/sda1: OK
Done!
Mounting /dev/sda1…
What would you like to name this image? [1.2.4]: [return]
OK. This image will be named: 1.2.4
Copying squashfs image…
Copying kernel and initrd images…
Done!
I found the following configuration files:
/opt/vyatta/etc/config/config.boot
/opt/vyatta/etc/config.boot.default
Which one should I copy to sda? [/opt/vyatta/etc/config/config.boot]: [return]
Copying /config/config.boot to sda.
Enter password for administrator account
Enter password for user ‘vyos’: [パスワードを入力]
Retype password for user ‘vyos’: [もう1度パスワードを入力]
I need to install the GRUB boot loader.
I found the following drives on your system:
sda 2147MB
Which drive should GRUB modify the boot partition on? [sda]: [return]
Setting up grub: OK
Done!

CDーROMをアンマウントしたいので電源を一度オフ。

vyos@vyos:~$ poweroff
Are you sure you want to power off this system? [y/N]] y
停止にしばらく時間がかかる
ISOをアンマウント

ちなみにインストールが終了すると勝手にOpen-VM-Toolsが有効になる。最近コンパイルしたものであれば。。。

電源をオンにして再度コンソールログイン
ユーザ名 vyos
パスワード <install imageで指定したもの>

以下コンソールでの作業
以下のコマンドを実行して、インストール確認
vyos@vyos:~$ show version
Version:          VyOS 1.2.4
Built by:         root@example.com
Built on:         Mon 06 Jan 2020 04:15 UTC
Build UUID:       ccf17895-423c-406e-adc3-60217c768519
Build Commit ID:  31284f0759884f

Architecture:     x86_64
Boot via:         installed image
System type:      bare metal

Hardware vendor:  VMware, Inc.
Hardware model:   VMware Virtual Platform
Hardware S/N:     VMware-42 25 3c d3 c6 35 a7 4b-8f 1b 27 68 7a b1 40 29
Hardware UUID:    d33c2542-35c6-4ba7-8f1b-27687ab14029

Copyright:        VyOS maintainers and contributors

以下のコマンドを実行して、ネットワークインタフェースが2つあるかを確認
vyos@vyos:~$ show interface
Codes: S – State, L – Link, u – Up, D – Down, A – Admin Down
Interface        IP Address                        S/L  Description
———        ———-                        —  ———–
eth0             –                                 u/u
eth1             –                                 u/u
lo               127.0.0.1/8                       u/u
                 ::1/128

 

設定の流れ

設定は、configureモードで設定をして、最後に
commit (適用)
discard (適用中止)
と入力することで適用される
ただし、再起動後も適用させる(/config/config.bootに保存させるためには)
save
と入力する。一時的なテストであればsaveをしないのもあり

一般的なLinuxコマンドを実行する場合は、sudo -i (パスワードは聞かれない)で実行をする。ただし、configure モードのコマンドは使えないことに注意

 

設定例の条件

以下設定について。ある程度例を交えて記載する。ホスト名: vyos-rt
NTP Server   ‘0.jp.pool.ntp.org’
                     ‘1.jp.pool.ntp.org’
                     ‘2.jp.pool.ntp.org’

eth0を外部(WAN)、eth1を内部(LAN)にする。
●外部ネットワーク
外部IP 192.168.10.200/24 
GW IP  192.168.10.1/24
外部DNS 8.8.8.8/8.8.4.4

●内部ネットワーク
Domain名 vyostest.corp
内部IP 192.168.11.1/24

 

実際の設定
最低限コンソールで設定をしなければならないもの(外部IPとGW IP、sshの起動)を設定した上で、sshで設定

1)コンソールから設定
Configureモードに入る(コマンドは全てTAB補完が使える)
vyos@vyos:~$ configure

外部IP(eth0)を設定
DHCPの場合
vyos@vyos:~# set interfaces ethernet eth0 address dhcp
固定IPの場合
vyos@vyos:~# set interfaces ethernet eth0 address ‘192.168.10.200/24’
vyos@vyos:~# set protocols static route 0.0.0.0/0 next-hop ‘192.168.10.1’

SSHの有効化
vyos@vyos:~# set service ssh port ’22’

一旦、設定を反映させて保存
vyos@vyos:~# commit
[edit]
vyos@vyos:~# save
Saving configuration to ‘/config/config.boot’…
Done
[edit]
Configureモードの終了
vyos@vyos:~# exit

 

以下コピペ用にプロンプト(vyos@vyos:~#)を省略
2)sshでの設定
SSHが有効になったので、SSH経由でログインし直す
ssh vyos@IP address
Configureモードに入る
vyos@vyos:~$ configure

以下コピペ用にプロンプト(vyos@vyos:~#)を省略
残りの設定を開始

●システム基本設定
ホスト名(vyos-rt)やNTP(hoge.pool.ntp.org)、DNSなどの本体設定
set system host-name ‘vyos-rt’
set system name-server ‘8.8.8.8’
set system name-server ‘8.8.4.4’
set system ntp server ‘0.jp.pool.ntp.org’
set system ntp server ‘1.jp.pool.ntp.org’
set system ntp server ‘2.jp.pool.ntp.org’
デフォルトタイムゾーンがUTCなので日本にするならば
set system time-zone ‘Asia/Tokyo’

vyosユーザのパスワード変更(したいのであれば)
set system login user vyos authentication plaintext-password hogepass

vyOS以外のユーザーにする場合は、以下を実行
ユーザー名 hogehoge
パスワード hogepass
set system login user hogehoge full-name “hoge hoge”
set system login user hogehoge authentication plaintext-password hogepass
set system login user hogehoge level admin

vyosユーザの削除(したい場合)
delete system login user vyos

sshキーの練りこみ
キーを持つ端末で
$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3Nz….

vyosユーザにキーを入れる場合
set system login user ‘vyos’ authentication public-keys ‘admin’ key ‘AAAAB3Nz….’
set system login user ‘vyos’ authentication public-keys ‘admin’ type ‘ssh-rsa’

user@service:~$ cat .ssh/id_rsa.pub
ssh-rsa AAAA略AAAAAAAAuser1@local.example.com
最後のユーザ名@ホスト名は付けない。

set system login user ‘vyos’ authentication public-keys ‘admin’ key ‘AAAA略AAAAAAAA’
set system login user ‘vyos’ authentication public-keys ‘admin’ type ‘ssh-rsa’

●基本ネットワーク設定
eth0のコメントを設定
set interfaces ethernet eth0 description ‘OUTSIDE’

内部IP(eth1)を設定
set interfaces ethernet eth1 address ‘192.168.11.1/24’
set interfaces ethernet eth1 description ‘INSIDE’

NATの設定
set nat source rule 1 outbound-interface ‘eth0’
set nat source rule 1 source address ‘192.168.11.0/24’
set nat source rule 1 translation address ‘masquerade’
set service dns forwarding allow-from ‘192.168.0.0/16’
set service dns forwarding allow-from ‘172.16.0.0/12’
set service dns forwarding allow-from ‘10.0.0.0/8’
set service dns forwarding allow-from ‘100.64.0.0/10’
set service dns forwarding listen-address ‘192.168.11.1’
set service dns forwarding name-server ‘8.8.8.8’
set service dns forwarding name-server ‘8.8.4.4’

DHCPサーバの設定 (192.168.11.100-199をDHCPリースさせる)
ドメイン名 vyostest.corp (.localなんて使わないように。。。事件が起きて楽しい人以外はw)
set service dhcp-server shared-network-name INTERNAL1 subnet 192.168.11.0/24 default-router ‘192.168.11.1’
set service dhcp-server shared-network-name INTERNAL1 subnet 192.168.11.0/24 dns-server ‘192.168.11.1’
set service dhcp-server shared-network-name INTERNAL1 subnet 192.168.11.0/24 domain-name ‘vyostest.corp’
set service dhcp-server shared-network-name INTERNAL1 subnet 192.168.11.0/24 range 0 start ‘192.168.11.100’
set service dhcp-server shared-network-name INTERNAL1 subnet 192.168.11.0/24 range 0 stop ‘192.168.11.199’

●追加の設定 (必要であれば)
DNSフォワードの設定 (vyostest.corpドメインのDNSサーバやADサーバが192.168.11.2の場合)
set service dns forwarding domain vyostest.corp server 192.168.11.2

簡易DNSサーバでのホスト名を追加する設定 (host1.vyostest.internalを192.168.11.3として登録する場合
set system static-host-mapping host-name host1.vyostest.internal alias ‘host1’
set system static-host-mapping host-name host1.vyostest.internal inet ‘192.168.11.3’

ポートフォーワーディングの設定 (host1:192.168.11.3にRDP(tcp/udp:3389)で接続できるようにする。外部IP:4389で接続可能)
set nat destination rule 100 description ‘host1’
set nat destination rule 100 destination port ‘4389’
set nat destination rule 100 inbound-interface ‘eth0’
set nat destination rule 100 protocol ’any’
set nat destination rule 100 translation address ‘192.168.11.3’
set nat destination rule 100 translation port ‘3389’

ポートフォーワーディングの設定 (host1:192.168.11.4にtcp 80/443で接続できるようにする。外部IP:80/443で接続可能)
set nat destination rule 900 description ‘http’
set nat destination rule 900 destination port ’80’
set nat destination rule 900 inbound-interface ‘eth0’
set nat destination rule 900 protocol ‘tcp’
set nat destination rule 900 translation address ‘192.168.11.4’
set nat destination rule 900 translation port ’80’
set nat destination rule 901 description ‘https’
set nat destination rule 901 destination port ‘443’
set nat destination rule 901 inbound-interface ‘eth0’
set nat destination rule 901 protocol ‘tcp’
set nat destination rule 901 translation address ‘192.168.11.4’
set nat destination rule 901 translation port ‘443’

Proxyの設定 (192.168.11.1:3128でSquidにアクセスができるようになる。)
set service webproxy listen-address 192.168.11.1 port 3128

3)設定の反映
vyos@vyos:~# commit
[edit]
エラーがなければ、保存。保存しない場合は、再起動すると設定がなくなる。
vyos@vyos:~# save
Saving configuration to ‘/config/config.boot’…
Done
[edit]
Configureモードから抜ける
vyos@vyos:~# exit
ホスト名を適用するために再起動
vyos@vyos:~$ reboot

再起動後インタフェースを確認
vyos@vyos-rt:~$ show interface
Codes: S – State, L – Link, u – Up, D – Down, A – Admin Down
Interface IP Address S/L Description
——— ———- — ———–
eth0 192.168.10.200/24 u/u OUTSIDE
eth1 192.168.11.1/24 u/u INSIDE
lo 127.0.0.1/8 u/u
::1/128

設定のエクスポート
設定がおわったら以下で設定を確認
vyos@vyos-rt:~$ show configuration
設定をコマンドを保存するなら(しておいたほうがいい)以下の出力をテキストファイルに保存
vyos@vyos-rt:~$ show configuration commands

DHCPとSSHだけ有効にした場合の設定
set interfaces ethernet eth0 address ‘dhcp’
set interfaces ethernet eth0 duplex ‘auto’
set interfaces ethernet eth0 hw-id ’00:50:56:b0:00:3a’
set interfaces ethernet eth0 smp-affinity ‘auto’
set interfaces ethernet eth0 speed ‘auto’
set interfaces ethernet eth1 hw-id ’00:50:56:b0:36:f0′
set interfaces loopback lo
set service ssh port ’22’
set system config-management commit-revisions ‘100’
set system console device ttyS0 speed ‘115200’
set system host-name ‘vyos’
set system login user vyos authentication encrypted-password ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’
set system login user vyos authentication plaintext-password ”
set system login user vyos level ‘admin’
set system ntp server 0.pool.ntp.org
set system ntp server 1.pool.ntp.org
set system ntp server 2.pool.ntp.org
set system syslog global facility all level ‘info’
set system syslog global facility protocols level ‘debug’
set system time-zone ‘UTC’

設定自体は、/config/config.bootに入っている。
/configをバックアップしておくのもあり。

設定のインポート
/configの内容を上書きするか/config/config.bootを上書きでリストアするか、その後再起動
あるいは、show configuration commandsの内容をコピペして、commitしてsave

コメントを残す