VyOS 1.3 の基本的な設定例を紹介します。 VyOSはバージョンによって設定方法が変更されているケースがあるので、記事を参考する際はバージョンを確認してから記事をご確認をお願いします。
下記の記事はVyOS1.1での設定例になります。
検証環境
- VyOS 1.3.0-epa1
検証構成
VyOSのホスト名設定 VyOSの設定反映(commit) および 保存 (save) 手順
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
vyos@vyos:~$ configure [edit] vyos@vyos# set system host-name vyos-1 [edit] vyos@vyos# commit [edit] vyos@vyos# save Saving configuration to '/config/config.boot'... Done [edit] vyos@vyos# exit exit vyos@vyos:~$ exit logout Welcome to VyOS - vyos-1 ttyS0 vyos-1 login: vyos Password: Linux vyos-1 5.4.149-amd64-vyos #1 SMP Mon Sep 27 17:44:04 UTC 2021 x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. vyos@vyos-1:~$ |
各コマンド解説
ログインした直後はoperationモードどなっていて、プロンプトが$の状態となっています。VyOSの設定変更のモードであるConfigurationモードには下記コマンドで変更します。Configurationモードはプロンプトが #に変更されます。
1 |
configure |
Configurationモードの状態で下記コマンドでホスト名(vyos-1)の設定を実施します。ただし、この状態では設定変更は反映されていません。
1 |
set system host-name vyos-1 |
設定変更を適用するには下記コマンドで反映します。
1 |
commit |
commitコマンドで設定反映されますが、下記コマンドで永続的に保存(再起動後も同じ設定を反映)することができます。
1 |
save |
interfaceの各種設定
interfaceの無効化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
vyos@vyos-1:~$ show interfaces Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 - u/u vyos@vyos-1:~$ configure [edit] vyos@vyos-1# set interfaces ethernet eth0 disable [edit] vyos@vyos-1# commit [edit] vyos@vyos-1# save Saving configuration to '/config/config.boot'... Done [edit] vyos@vyos-1# exit exit vyos@vyos-1:~$ show interfaces Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 - A/D lo 127.0.0.1/8 u/u ::1/128 vyos@vyos-1:~$ |
show interface でルータ内のinterfaceを表示されます。上記例では eth0 が一つあることがわかります。 eth0 が u/u で State/Link がUp/Up状態を表しています。
set interfaces ethernet eth0 disable
にてeth0をdisable(無効化)になります。設定を反映後再度 show interface すると eth0 が A/D 表示になり Admin Down / Down となり無効化に成功したことがわかります。
interfaceの有効化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
vyos@vyos-1:~$ configure [edit] vyos@vyos-1# delete interfaces ethernet eth0 disable [edit] vyos@vyos-1# commit [edit] vyos@vyos-1# save Saving configuration to '/config/config.boot'... Done [edit] vyos@vyos-1# exit exit vyos@vyos-1:~$ show interface Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 - u/u lo 127.0.0.1/8 u/u ::1/128 vyos@vyos-1:~$ |
先ほど設定した disable を削除することでinterfaceが有効の状態になり、 eth0 が u/u Up/Up となります。
interfaceのIPv4アドレス設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
vyos@vyos-1:~$ show interfaces Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 - u/u lo 127.0.0.1/8 u/u ::1/128 vyos@vyos-1:~$ configure [edit] vyos@vyos-1# set interfaces ethernet eth0 address 192.168.0.1/24 [edit] vyos@vyos-1# commit [edit] vyos@vyos-1# save Saving configuration to '/config/config.boot'... Done [edit] vyos@vyos-1# exit exit vyos@vyos-1:~$ show interface Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 192.168.0.1/24 u/u lo 127.0.0.1/8 u/u ::1/128 vyos@vyos-1:~$ |
set interfaces ethernet eth0 address 192.168.0.1/24 にてeth0にIPv4アドレスの設定します。設定反映後、show interface にてeth0に 192.168.0.1/24 が表示されている。
interfaceのIPv6アドレス設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
vyos@vyos-1:~$ show interfaces Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 192.168.0.1/24 u/u lo 127.0.0.1/8 u/u ::1/128 vyos@vyos-1:~$ configure [edit] vyos@vyos-1# set interfaces ethernet eth0 address 2001:db8::1/64 [edit] vyos@vyos-1# commit [edit] vyos@vyos-1# save Saving configuration to '/config/config.boot'... Done [edit] vyos@vyos-1# exit exit vyos@vyos-1:~$ show interfaces Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 192.168.0.1/24 u/u 2001:db8::1/64 lo 127.0.0.1/8 u/u ::1/128 vyos@vyos-1:~$ |
set interfaces ethernet eth0 address 2001:db8::1/64 にて eth0にIPv6のアドレスを設定しします。 設定反映後、show interface にて eth0 に 2001:db8::1/64 が表示されます。
IPv4 デフォルトルート static route 設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
vyos@vyos-1:~$ show ip route Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup C>* 192.168.0.0/24 is directly connected, eth0, 00:08:23 vyos@vyos-1:~$ configure [edit] vyos@vyos-1# set protocols static route 0.0.0.0/0 Possible completions: > blackhole Silently discard pkts when matched dhcp-interface DHCP interface supplying next-hop IP address +> next-hop Next-hop router [edit] vyos@vyos-1# set protocols static route 0.0.0.0/0 next-hop 192.168.0.2 [edit] vyos@vyos-1# commit [edit] vyos@vyos-1# save Saving configuration to '/config/config.boot'... Done [edit] vyos@vyos-1# exit exit vyos@vyos-1:~$ show ip route Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup S>* 0.0.0.0/0 [1/0] via 192.168.0.2, eth0, weight 1, 00:00:07 C>* 192.168.0.0/24 is directly connected, eth0, 00:08:56 vyos@vyos-1:~$ |
IPv4のデフォルトルートをvyos-2のinterfaceのIP(192.168.0.2)向けの設定になります。 show ip route で 0.0.0.0/0 が 192.168.0.2 へのルーティングテーブルが追加されます。
IPv6 デフォルトルート static route 設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
vyos@vyos-1:~$ show ipv6 route Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup C>* 2001:db8::/64 is directly connected, eth0, 00:07:26 C * fe80::/64 is directly connected, eth0, 00:23:39 C>* fe80::/64 is directly connected, lo, 02w2d11h vyos@vyos-1:~$ configure [edit] vyos@vyos-1# set protocols static route6 ::/0 next-hop 2001:db8::2 [edit] vyos@vyos-1# commit [edit] vyos@vyos-1# save Saving configuration to '/config/config.boot'... Done [edit] vyos@vyos-1# exit exit vyos@vyos-1:~$ show ipv6 route Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup S>* ::/0 [1/0] via 2001:db8::2, eth0, weight 1, 00:00:08 C>* 2001:db8::/64 is directly connected, eth0, 00:08:22 C * fe80::/64 is directly connected, eth0, 00:24:35 C>* fe80::/64 is directly connected, lo, 02w2d11h vyos@vyos-1:~$ |
IPv6のデフォルトルートをvyos-2のinterfaceのIPv6(2001:db8::2)向けの設定になります。 show ip route で ::/0 が 2001:db8::2 へのルーティングテーブルが追加されます。
vyos-2 の設定
構成図をもとに vyos-2 にアドレス設定になります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
vyos@vyos:~$ show interfaces 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 vyos@vyos:~$ configure [edit] vyos@vyos# set system host-name vyos-2 [edit] vyos@vyos# set interfaces ethernet eth0 address 192.168.0.2/24 [edit] vyos@vyos# set interfaces ethernet eth0 address 2001:db8::2/64 [edit] vyos@vyos# set interfaces ethernet eth1 address 192.168.1.2/24 [edit] vyos@vyos# set interfaces ethernet eth1 address 2001:db8:1::2/64 [edit] vyos@vyos# commit [edit] vyos@vyos# save Saving configuration to '/config/config.boot'... Done [edit] vyos@vyos# exit exit vyos@vyos:~$ show interfaces Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 192.168.0.2/24 u/u 2001:db8::2/64 eth1 192.168.1.2/24 u/u 2001:db8:1::2/64 lo 127.0.0.1/8 u/u ::1/128 vyos@vyos:~$ show ip route Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup C>* 192.168.0.0/24 is directly connected, eth0, 00:00:14 C>* 192.168.1.0/24 is directly connected, eth1, 00:00:14 vyos@vyos:~$ show ipv6 route Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup C>* 2001:db8::/64 is directly connected, eth0, 00:05:11 C>* 2001:db8:1::/64 is directly connected, eth1, 00:05:10 C * fe80::/64 is directly connected, eth0, 02w2d05h C * fe80::/64 is directly connected, eth1, 02w2d05h C>* fe80::/64 is directly connected, lo, 02w2d05h vyos@vyos:~$ |
vyos-3 の設定
構成図をもとに vyos-2 にアドレス設定になります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
vyos@vyos:~$ show interfaces Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 - u/u lo 127.0.0.1/8 u/u ::1/128 vyos@vyos:~$ show ip route vyos@vyos:~$ configure [edit] vyos@vyos# set system host-name vyos-3 [edit] vyos@vyos# set interfaces ethernet eth0 address 192.168.1.3/24 [edit] vyos@vyos# set interfaces ethernet eth0 address 2001:db8:1::3/64 [edit] vyos@vyos# set protocols static route 192.168.0.0/24 next-hop 192.168.1.2 [edit] vyos@vyos# set protocols static route6 2001:db8::/64 next-hop 2001:db8:1::2 [edit] vyos@vyos# commit [edit] vyos@vyos# save Saving configuration to '/config/config.boot'... Done [edit] vyos@vyos# exit exit vyos@vyos:~$ show interfaces Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 192.168.1.3/24 u/u 2001:db8:1::3/64 lo 127.0.0.1/8 u/u ::1/128 vyos@vyos:~$ show ip route Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup S>* 192.168.0.0/24 [1/0] via 192.168.1.2, eth0, weight 1, 00:00:13 C>* 192.168.1.0/24 is directly connected, eth0, 00:00:14 vyos@vyos:~$ show ipv6 route Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup S>* 2001:db8::/64 [1/0] via 2001:db8:1::2, eth0, weight 1, 00:00:24 C>* 2001:db8:1::/64 is directly connected, eth0, 00:00:24 C * fe80::/64 is directly connected, eth0, 02w2d05h C>* fe80::/64 is directly connected, lo, 02w2d05h vyos@vyos:~$ |
Pingよる設定確認
vyos-1から vyos03のeth0 interfaceのアドレスにPingすることで設定を確認します。 pingコマンドを発行するとPingを実行が継続されます。 Ctrl + C をすることでPingを停止することができます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
vyos@vyos-1:~$ ping 192.168.1.3 PING 192.168.1.3 (192.168.1.3) 56(84) bytes of data. 64 bytes from 192.168.1.3: icmp_seq=1 ttl=63 time=2.38 ms 64 bytes from 192.168.1.3: icmp_seq=2 ttl=63 time=2.28 ms 64 bytes from 192.168.1.3: icmp_seq=3 ttl=63 time=2.27 ms 64 bytes from 192.168.1.3: icmp_seq=4 ttl=63 time=2.25 ms ^C --- 192.168.1.3 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 8ms rtt min/avg/max/mdev = 2.246/2.293/2.380/0.070 ms vyos@vyos-1:~$ ping 2001:db8:1::3 PING 2001:db8:1::3(2001:db8:1::3) 56 data bytes 64 bytes from 2001:db8:1::3: icmp_seq=1 ttl=63 time=5.36 ms 64 bytes from 2001:db8:1::3: icmp_seq=2 ttl=63 time=2.41 ms 64 bytes from 2001:db8:1::3: icmp_seq=3 ttl=63 time=2.25 ms 64 bytes from 2001:db8:1::3: icmp_seq=4 ttl=63 time=2.36 ms ^C --- 2001:db8:1::3 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 8ms rtt min/avg/max/mdev = 2.248/3.095/5.363/1.311 ms vyos@vyos-1:~$ |
Config確認方法
オペレーションモード時に show configuration で設定を階層で確認することができます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
vyos@vyos-1:~$ show configuration interfaces { ethernet eth0 { address 192.168.0.1/24 address 2001:db8::1/64 hw-id 52:54:00:66:8d:2a } loopback lo { } } protocols { static { route 0.0.0.0/0 { next-hop 192.168.0.2 { } } route6 ::/0 { next-hop 2001:db8::2 { } } } } system { config-management { commit-revisions 100 } conntrack { modules { ftp h323 nfs pptp sip sqlnet tftp } } console { device ttyS0 { speed 115200 } } host-name vyos-1 login { user vyos { authentication { encrypted-password **************** plaintext-password **************** } } } ntp { server time1.vyos.net { } server time2.vyos.net { } server time3.vyos.net { } } syslog { global { facility all { level info } facility protocols { level debug } } } } vyos@vyos-1:~$ |
階層化モードは人間には理解しやすい形で表示がされますが、この表示結果ではConfigurationモード時ではそのまま設定することできません。Configurationモードで設定できる形式のshow configuration commandsで表示することができます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
vyos@vyos-1:~$ show configuration commands set interfaces ethernet eth0 address '192.168.0.1/24' set interfaces ethernet eth0 address '2001:db8::1/64' set interfaces ethernet eth0 hw-id '52:54:00:66:8d:2a' set interfaces loopback lo set protocols static route 0.0.0.0/0 next-hop 192.168.0.2 set protocols static route6 ::/0 next-hop 2001:db8::2 set system config-management commit-revisions '100' set system conntrack modules ftp set system conntrack modules h323 set system conntrack modules nfs set system conntrack modules pptp set system conntrack modules sip set system conntrack modules sqlnet set system conntrack modules tftp set system console device ttyS0 speed '115200' set system host-name 'vyos-1' set system login user vyos authentication encrypted-password '$6$zOvUb2L.$Zk7VmpGvk7QqnQBXb9ppeyCVJ84zubYKAyK8knA./4VaPVx4dSAEZSWMd2lF9mAgnAQoyWlcROQMym0NNdgIc/' set system login user vyos authentication plaintext-password '' set system ntp server time1.vyos.net set system ntp server time2.vyos.net set system ntp server time3.vyos.net set system syslog global facility all level 'info' set system syslog global facility protocols level 'debug' vyos@vyos-1:~$ |