ユーザーガイド
このユーザーガイドは、VyOSのインストール、設定、操作について一般的な内容を提供します。
はじめに
VyOSは、ソフトウエアベースでルーティング、ファイアウォール、VPN機能等を提供するLinuxベースのネットワーク・オペレーティング・システムです。
VyOSプロジェクトは、Vyattaのコミュニティ版開発中止決定を受け、フリーかつオープンソースのネットワーク・オペレーティング・システムを維持することを目標とし、Vyatta Core 6.6R1のGPL部分の派生として、2013年後半に開始されました。
VyOSは主に、Debian GNU/LinuxとQuaggaルーティングエンジンを土台としています。 設定構文とコマンドライン・インターフェースは、Vyattaが最初にベースで利用したルーティングエンジンであるXORP projectによって、多くの部分で Juniper社のJUNOSから派生しています。 Vyattaは、4.0リリース時にQuaggaへルーティングエンジンが変更されました。
インストール
VyOSの最新版ISOイメージは、www.vyos.netからダウンロード出来ます。
システムの推奨動作環境として、512MBのメモリと2 GBのストレージを用意してください。
VyOSのISOは、Live CDでVyOSの機能がブートするイメージとなっています。システムへログインするにはデフォルトのユーザ名、パスワードとしてvyos:vyosを利用してください。
Linux vyatta 3.3.8-1-amd64-vyatta #1 SMP Wed Oct 30 22:54:40 CET 2013 x86_64 Welcome to VyOS. This system is open-source software. The exact distribution terms for each module comprising the full system are described in the individual files in /usr/share/doc/*/copyright. Last login: Wed Dec 11 17:33:09 2013 [email protected]:~$
システムインストール(install system)とイメージインストール(install image)の2つのインストールオプションがあります。
システムインストール(install system)は、従来通りのLinuxインストールの様に、選択したストレージデバイス上へVyOSをインストールします。
イメージインストール(install image)は、VyOSで推奨されるインストール方法で、イメージベースのインストールを利用し、各VyOSのリリースが自己完結可能な状態で選択したストレージディバイス上のディレクトリに保持されます。 複数のOSイメージを同一のシステム上にインストールする事が可能で、起動時に選択する事で、新しいリリースへのアップグレードと簡単なロールバックを実現します。
いずれかのコマンドを入力すると、選択したインストーラを開始します。
[email protected]:~$ 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 1000MB 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? (1000MB - 2147MB) [2147]MB: [return] Creating filesystem on /dev/sda1: OK Done! Mounting /dev/sda1... What would you like to name this image? [VyOS_999.hydrogen.11291501]: OK. This image will be named: VyOS_999.hydrogen.11291501 Copying squashfs image... Copying kernel and initrd images... Done! I found the following configuration files: /config/config.boot /opt/vyatta/etc/config.boot.default Which one should I copy to sda? [/config/config.boot]: [return] Copying /config/config.boot to sda. Enter password for administrator account Enter password for user 'vyos': <removed> Retype password for user 'vyos': <removed> 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! [email protected]:~$
インストールが完了したら、Live CDを取り出し、システムを再起動します。
[email protected]:~$ reboot Proceed with reboot? (Yes/No) [No] Yes [email protected]:~$
コマンドライン・インターフェースの使用
VyOSのコマンドライン・インターフェース(CLI)は操作モード(operational mode)と設定モード(configuration mode)から構成されています。
操作モードは、システムタスク、ビューシステム、サービスステータスのコマンドが許可されており、さらに設定モードでは、システム設定の変更が出来ます。
CLIは組み込みのヘルプシステムを提供しています。CLIは[?]キーで、使用可能なコマンドを表示します。[tab]キーは、自動補完コマンドとして利用され、引数や入力値に応じヘルプシステムを提示します。
例えば、shとタイピングし、続いて[tab]キーを入力するとshowと補完されます。次に[tab]を押すとshowコマンドで利用可能なサブコマンドが提示されます。
[email protected]:~$ s[tab] set show [email protected]:~$
showコマンドで利用可能なサブコマンドを提示させた例です。
[email protected]:~$ show [tab] Possible completions: arp Show Address Resolution Protocol (ARP) information bridge Show bridging information cluster Show clustering information configuration Show running configuration conntrack Show conntrack entries in the conntrack table conntrack-sync Show connection syncing information date Show system date and time dhcp Show Dynamic Host Configuration Protocol (DHCP) information dhcpv6 Show status related to DHCPv6 disk Show status of disk device dns Show Domain Name Server (DNS) information file Show files for a particular image firewall Show firewall information flow-accounting Show flow accounting statistics hardware Show system hardware details history show command history host Show host information incoming Show ethernet input-policy information : q [email protected]:~$
コマンドの出力結果が端末画面の行数を超えてしまう場合は、: プロンプトが現れ、出力をページ毎に分割したページモードで表示されます。
ページモードで表示している時は、次のコマンドが使用可能です。
- [q] 出力をキャンセルして終了します
- [space] 1ページ下にスクロールします
- [b] 1ページ上にスクロールします
- [return] 1行下にスクロールします
- [↑up-arrow] と [↓down-arrow] は、それぞれ上下に1行ずつスクロールします
- [←left-arrow] と [→right-arrow] は、出力が端末サイズを超える列を持っている際にそれぞれ左右に1列づつスクロールします
設定モードに入るには、 configureコマンドを使用します。
[email protected]:~$ configure [edit] [email protected]:~#
プロンプトが$から#に変更される事に注目してください。 exitと入力すると設定モードを終了します。
[email protected]:~# exit exit [email protected]:~$
設定モードの詳細については、この文書の設定例の項目を参照してください。
クイックスタートガイド
以下は、2つのインターフェースを持つディバイス向けにNATゲートウエイを提供する非常に基本的な設定例です。
設定モードを開始します。
[email protected]$ configure [email protected]#
ネットワーク・インターフェースを設定します。
set interfaces ethernet eth0 address dhcp set interfaces ethernet eth0 description 'OUTSIDE' set interfaces ethernet eth1 address '192.168.0.1/24' set interfaces ethernet eth1 description 'INSIDE'
リモート管理用にSSHを有効にします。
set service ssh port '22'
「内部」ネットワークに対して送信元NATを設定します。
set nat source rule 100 outbound-interface 'eth0' set nat source rule 100 source address '192.168.0.0/24' set nat source rule 100 translation address masquerade
DHCPサーバを設定します。
set service dhcp-server disabled 'false' set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 default-router '192.168.0.1' set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 dns-server '192.168.0.1' set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 domain-name 'internal-network' set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 lease '86400' set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 start 192.168.0.9 stop '192.168.0.254'
DNSフォワーダーも設定します。
set service dns forwarding cache-size '0' set service dns forwarding listen-on 'eth1' set service dns forwarding name-server '8.8.8.8' set service dns forwarding name-server '8.8.4.4'
「外部」インターフェースに対して、ファイアウォールポリシーセットを追加します。
set firewall name OUTSIDE-IN default-action 'drop' set firewall name OUTSIDE-IN rule 10 action 'accept' set firewall name OUTSIDE-IN rule 10 state established 'enable' set firewall name OUTSIDE-IN rule 10 state related 'enable' set firewall name OUTSIDE-LOCAL default-action 'drop' set firewall name OUTSIDE-LOCAL rule 10 action 'accept' set firewall name OUTSIDE-LOCAL rule 10 state established 'enable' set firewall name OUTSIDE-LOCAL rule 10 state related 'enable' set firewall name OUTSIDE-LOCAL rule 20 action 'accept' set firewall name OUTSIDE-LOCAL rule 20 icmp type-name 'echo-request' set firewall name OUTSIDE-LOCAL rule 20 protocol 'icmp' set firewall name OUTSIDE-LOCAL rule 20 state new 'enable' set firewall name OUTSIDE-LOCAL rule 30 action 'drop' set firewall name OUTSIDE-LOCAL rule 30 destination port '22' set firewall name OUTSIDE-LOCAL rule 30 protocol 'tcp' set firewall name OUTSIDE-LOCAL rule 30 recent count '4' set firewall name OUTSIDE-LOCAL rule 30 recent time '60' set firewall name OUTSIDE-LOCAL rule 30 state new 'enable' set firewall name OUTSIDE-LOCAL rule 31 action 'accept' set firewall name OUTSIDE-LOCAL rule 31 destination port '22' set firewall name OUTSIDE-LOCAL rule 31 protocol 'tcp' set firewall name OUTSIDE-LOCAL rule 31 state new 'enable'
ファイアウォールポリシーを適用します
set interfaces ethernet eth0 firewall in name 'OUTSIDE-IN' set interfaces ethernet eth0 firewall local name 'OUTSIDE-LOCAL'
変更のコミットおよび設定保存後、設定モードを終了します。
[email protected]# commit [email protected]# save Saving configuration to '/config/config.boot'... Done [email protected]# exit [email protected]$
設定例
VyOSは、すべてのシステム設定のために、統一された設定ファイルconfig.bootを利用します。これにより簡単なテンプレートの作成、バックアップ、システム設定の複製を可能としています。
現在の設定はshow configurationコマンドで表示出来ます。
[email protected]:~$ show configuration interfaces { ethernet eth0 { address dhcp hw-id 00:0c:29:44:3b:0f } loopback lo { } } service { ssh { port 22 } } system { config-management { commit-revisions 20 } console { device ttyS0 { speed 9600 } } login { user vyos { authentication { encrypted-password **************** } level admin } } ntp { server 0.pool.ntp.org { } server 1.pool.ntp.org { } server 2.pool.ntp.org { } } package { repository community { components main distribution stable url http://packages.vyos.net/vyos } } syslog { global { facility all { level notice } facility protocols { level debug } } } } [email protected]:~$
設定変更は、setとdeleteコマンドを用いて行います。 現在の設定はshow configuration commandsコマンドでも表示する事が出来ます。
[email protected]:~$ show configuration commands set interfaces ethernet eth0 address 'dhcp' set interfaces ethernet eth0 hw-id '00:0c:29:44:3b:0f' set interfaces loopback 'lo' set service ssh port '22' set system config-management commit-revisions '20' set system console device ttyS0 speed '9600' set system login user vyos authentication encrypted-password '<removed>' 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 package repository community components 'main' set system package repository community distribution 'stable' set system package repository community url 'http://packages.vyos.net/vyos' set system syslog global facility all level 'notice' set system syslog global facility protocols level 'debug' [email protected]:~$
コミットされるまで行われた設定変更は、設定モードで commitコマンドを実行しない限り有効になりません。
[email protected]# commit [edit] [email protected]# exit Warning: configuration changes have not been saved. exit [email protected]:~$
再起動時も設定変更を保存するためには、設定を保存する必要があります。
設定の保存は、設定モードで'saveコマンドを実行すると行われます。
[email protected]# save Saving configuration to '/config/config.boot'... Done [edit] [email protected]#
設定モード中のshowコマンドでは、現在の設定へ追加された設定行に+、削除された設定行に-を表示します。
[email protected]:~$ configure [edit] [email protected]# show interfaces ethernet eth0 { address dhcp hw-id 00:0c:29:44:3b:0f } loopback lo { } [edit] [email protected]# set interfaces ethernet eth0 description 'OUTSIDE' [edit] [email protected]# show interfaces ethernet eth0 { address dhcp + description OUTSIDE hw-id 00:0c:29:44:3b:0f } loopback lo { } [edit] [email protected]#
コミットされていない設定変更が存在している場合、設定モードを終了することが出来ません。設定変更を有効化せずに設定モードを終了するには、exit discardコマンドを実行します。
[email protected]# exit Cannot exit: configuration modified. Use 'exit discard' to discard the changes and exit. [edit] [email protected]# exit discard exit [email protected]:~$
VyOSは、以前の設定についてバックアップを保持しています。以前の設定と変更箇所を比較するには、設定モードでcompareコマンドを実行します。
[email protected]# compare [tab] Possible completions: <Enter> Compare working & active configurations saved Compare working & saved configurations <N> Compare working with revision N <N> <M> Compare revision N with M Revisions: 0 2013-12-17 20:01:37 root by boot-config-loader 1 2013-12-13 15:59:31 root by boot-config-loader 2 2013-12-12 21:56:22 vyos by cli 3 2013-12-12 21:55:11 vyos by cli 4 2013-12-12 21:27:54 vyos by cli 5 2013-12-12 21:23:29 vyos by cli 6 2013-12-12 21:13:59 root by boot-config-loader 7 2013-12-12 16:25:19 vyos by cli 8 2013-12-12 15:44:36 vyos by cli 9 2013-12-12 15:42:07 root by boot-config-loader 10 2013-12-12 15:42:06 root by init [edit] [email protected]#
rollbackコマンドを用いて設定のロールバックを行えますが、コマンド実行後、システム再起動が必要です。
[email protected]# compare 1 [edit system] >host-name vyos-1 [edit] [email protected]# rollback 1 Proceed with reboot? [confirm][y] Broadcast message from [email protected] (pts/0) (Tue Dec 17 21:07:45 2013): The system is going down for reboot NOW! [edit] [email protected]#
VyOSは、設定をリモートSCP、FTP、またはTFTPを使用して保存、読み込みする事をサポートしています。
[email protected]# save [tab] Possible completions: <Enter> Save to system config file <file> Save to file on local machine scp://<user>:<passwd>@<host>/<file> Save to file on remote machine ftp://<user>:<passwd>@<host>/<file> Save to file on remote machine tftp://<host>/<file> Save to file on remote machine
[email protected]# save tftp://192.168.0.100/vyos-test.config.boot Saving configuration to 'tftp://192.168.0.100/vyos-test.config.boot'... ######################################################################## 100.0% Done
Network Interfaces
VyOS上で設定されたインタフェースは、show interfacesコマンドを実行すると表示出来ます。
[email protected]:~$ show interfaces Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 172.16.51.129/24 u/u OUTSIDE eth1 192.168.0.1/24 u/u INSIDE lo 127.0.0.1/8 u/u ::1/128 [email protected]:~$
show interfaces <type> <name>コマンドで指定インターフェースについてのみ表示する事が出来ます。
[email protected]:~$ show interfaces ethernet eth0 eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:44:3b:0f brd ff:ff:ff:ff:ff:ff inet 172.16.51.129/24 brd 172.16.51.255 scope global eth0 inet6 fe80::20c:29ff:fe44:3b0f/64 scope link valid_lft forever preferred_lft forever Description: OUTSIDE RX: bytes packets errors dropped overrun mcast 274397 3064 0 0 0 0 TX: bytes packets errors dropped carrier collisions 257276 1890 0 0 0 0 [email protected]:~$
各インターフェースには説明やアドレスを設定する事が出来ます。
set interfaces ethernet eth0 description 'OUTSIDE' set interfaces ethernet eth0 address 'dhcp'
異なるネットワークインターフェイスは、タイプ固有の設定が提供されます。例えばイーサネットインターフェイスでは、速度やデュプレックスの設定が可能です。
多くのサービスで、このようなネットワークルーティング、ファイアウォール、およびトラフィックポリシーのようなインターフェイス固有の設定を維持します。詳細については、それぞれの項目で説明します。
Physical Ethernet Interfaces
イーサネットインターフェイスは、速度、デュプレックス、およびハードウエアID(MACアドレス)といった設定が可能です。 設定例は以下のとおりです。
set interfaces ethernet eth1 address '192.168.0.1/24' set interfaces ethernet eth1 description 'INSIDE' set interfaces ethernet eth1 duplex 'auto' set interfaces ethernet eth1 speed 'auto'
Resulting in:
ethernet eth1 { address 192.168.0.1/24 description INSIDE duplex auto hw-id 00:0c:29:44:3b:19 smp_affinity auto speed auto }
また、イーサネットインターフェイスはshow interfaces ethernet <name> physical と show interfaces ethernet <name> statisticsという拡張設定コマンドを提供しています。
利用可能な統計情報は、ドライバに依存しています。
[email protected]:~$ show interfaces ethernet eth0 physical Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: Unknown Supports Wake-on: d Wake-on: d Current message level: 0x00000007 (7) Link detected: yes driver: e1000 version: 7.3.21-k8-NAPI firmware-version: bus-info: 0000:02:01.0 [email protected]:~$ [email protected]:~$ show interfaces ethernet eth0 statistics NIC statistics: rx_packets: 3530 tx_packets: 2179 [...]
802.1Q VLAN Interfaces
802.1Q VLANインターフェイスは、VyOSの仮想サブインターフェイスvifとして表されます。 タグ付けされたサブインターフェイスの設定は、設定コマンドset interfaces ethernet <name> vif <vlan-id>実行して行います。
set interfaces ethernet eth1 vif 100 description 'VLAN 100' set interfaces ethernet eth1 vif 100 address '192.168.100.1/24'
Resulting:
ethernet eth1 { address 192.168.0.1/24 description INSIDE duplex auto hw-id 00:0c:29:44:3b:19 smp_affinity auto speed auto vif 100 { address 192.168.100.1/24 description "VLAN 100" } }
VLANインターフェースは<name>.<vlan-id>の様に表示されます。例)eth1.100
[email protected]:~$ show interfaces Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down Interface IP Address S/L Description --------- ---------- --- ----------- eth0 172.16.51.129/24 u/u OUTSIDE eth1 192.168.0.1/24 u/u INSIDE eth1.100 192.168.100.1/24 u/u VLAN 100 lo 127.0.0.1/8 u/u ::1/128 [email protected]:~$
Bridging
VyOSのインターフェイスは、レイヤ2トラフィックのソフトスイッチングを提供するために、連携してブリッジすることができる。
ブリッジインタフェースが定義されている場合においてブリッジが作成されます。
以下の例では、VLAN 100のブリッジを作成され、ブリッジにVIFを割り当てています。
set interfaces bridge 'br100' set interfaces ethernet eth1 vif 100 bridge-group bridge br100
ブリッジグループに割り当てられたインターフェイスはアドレスの設定がありませんが、通常インターフェイスと同様に、ブリッジインタフェース自体にIPアドレスを割り当てることが出来ます。
set interfaces bridge br100 address '192.168.100.1/24'
設定例
bridge br100 { address 192.168.100.1/24 } [...] ethernet eth1 { [...] vif 100 { bridge-group { bridge br100 } } }
通常のIPインターフェイス設定の他に、ブリッジインターフェイスは、スパニングツリープロトコル(STP)をサポートしています。 STPはデフォルトで無効になっています。
注意: STPはトポロジの変更につながる可能性があるため、既存ネットワーク上でSTPを導入する際は十分に注意して使用してください。
スパニングツリーを有効にするには、set interfaces bridge <name> stp trueコマンドを実行します。
set interfaces bridge br100 stp true
STPのpriority, forwarding-delay, hello-time, max-ageでは、ブリッジグループを設定することができます。 MACエージング時間もagingディレクティブを使用して設定できます。
メンバーインターフェイスは、ブリッジグループのpriorityとcostに設定できます。
show bridge コマンドは、ブリッジ構成を表示する際に実行します。
[email protected]:~$ show bridge bridge name bridge id STP enabled interfaces br100 0000.000c29443b19 yes eth1.100 [email protected]:~$
スパニングツリーが有効になっている場合、show bridge <name> spanning-treeコマンドは、STP設定を表示する際に実行します。
[email protected]:~$ show bridge br100 spanning-tree br100 bridge id 0000.000c29443b19 designated root 0000.000c29443b19 root port 0 path cost 0 max age 20.00 bridge max age 20.00 hello time 2.00 bridge hello time 2.00 forward delay 15.00 bridge forward delay 15.00 ageing time 300.00 hello timer 0.47 tcn timer 0.00 topology change timer 0.00 gc timer 64.63 flags eth1.100 (1) port id 8001 state forwarding designated root 0000.000c29443b19 path cost 4 designated bridge 0000.000c29443b19 message age timer 0.00 designated port 8001 forward delay timer 0.00 designated cost 0 hold timer 0.00 flags [email protected]:~$
ブリッジのMACアドレステーブルは、 show bridge <name> macsコマンドを実行して表示します。
[email protected]:~$ show bridge br100 macs port no mac addr is local? ageing timer 1 00:0c:29:44:3b:19 yes 0.00 [email protected]:~$
Bonding
Tunnel Interfaces
Routing
ルーティングとは、ネットワークから別のネットワークにパケットを送信する事です。
Static
スタティックルートは、手動でネットワークルートを設定出来ます。 スタティックルートの一般的な用途は、DHCPまたはダイナミックルーティングプロトコルを利用していないシステムのための静的デフォルトルートの設定です。
set protocols static route 0.0.0.0/0 next-hop 203.0.113.1 distance '1'
設定例
static { route 0.0.0.0/0 { next-hop 203.0.113.1 { distance 1 } } }
その他のよくあるスタティックルートの使い方として、トラフィックのブラックホール(ドロップ)がある。 以下の例では、RFC1918に基づいたプライベートIPネットワーク宛通信はドロップする様に設定されている。 既知のルーティングが常に使用されるため、通信中のセグメント内通信を妨げるものではありません。 ただし、ルータ出て行く未知のプライベートネットワークへのトラフィックを防ぎます。 一般的にこの設定は漏洩を防ぐために使います。
set protocols static route 10.0.0.0/8 blackhole distance '254' set protocols static route 172.16.0.0/12 blackhole distance '254' set protocols static route 192.168.0.0/16 blackhole distance '254'
設定例
route 10.0.0.0/8 { blackhole { distance 254 } } route 172.16.0.0/12 { blackhole { distance 254 } } route 192.168.0.0/16 { blackhole { distance 254 } }
間隔が255のルートは、事実上無効でカーネルにインストールされていない事に注意してください。
RIP
簡単なRIP設定を使用した2ノード間を接続したインターフェイスを設定します。
ノード1:
set interfaces loopback address 1.1.1.1/32 set protocols rip network 192.168.0.0/24 set protocols ospf redistribute connected
ノード2:
set interfaces loopback address 2.2.2.2/32 set protocols rip network 192.168.0.0/24 set protocols ospf redistribute connected
設定例
ノード1:
rip{ network 192.168.1.0/24 redistribute { connected { } } }
ノード2:
rip{ network 192.168.1.0/24 redistribute { connected { } } }
OSPF
A typical configuration using 2 nodes, redistribute loopback address and the node 1 sending the default route:
Node 1:
set interfaces loopback address 1.1.1.1/32 set protocols ospf area 0 network 192.168.0.0/24 set protocols ospf default-information originate always set protocols ospf default-information originate metric 10 set protocols ospf default-information originate metric-type 2 set protocols ospf log-adjacency-changes set protocols ospf parameters router-id 1.1.1.1 set protocols ospf redistribute connected metric-type 2 set protocols ospf route-map CONNECT
set policy route-map CONNECT rule 10 action permit set policy route-map CONNECT rule 10 match interface lo
Node 2:
set interfaces loopback address 2.2.2.2/32 set protocols ospf area 0 network 192.168.0.0/24 set protocols ospf log-adjacency-changes set protocols ospf parameters router-id 2.2.2.2 set protocols ospf redistribute connected metric-type 2 set protocols ospf route-map CONNECT
set policy route-map CONNECT rule 10 action permit set policy route-map CONNECT rule 10 match interface lo
Resulting configuration:
Node 1:
ospf { area 0 { network 192.168.0.0/24 } default-information { originate { always metric 10 metric-type 2 } } log-adjacency-changes { } parameters { router-id 1.1.1.1 } redistribute { connected { metric-type 2 route-map CONNECT } } }
route-map CONNECT { rule 10 { action permit match { interface lo } } }
Node 2:
ospf { area 0 { network 192.168.0.0/24 } log-adjacency-changes { } parameters { router-id 2.2.2.2 } redistribute { connected { metric-type 2 route-map CONNECT } } }
route-map CONNECT { rule 10 { action permit match { interface lo } } }
BGP
A simple eBGP configuration:
Node 1:
set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop '2' set protocols bgp 65536 neighbor 192.168.0.2 remote-as '65537' set protocols bgp 65536 neighbor 192.168.0.2 update-source ‘192.168.0.1 set protocols bgp 65536 network '1.0.0.0/16' set protocols bgp 65536 parameters router-id ‘192.168.0.1
Node 2:
set protocols bgp 65537 neighbor 192.168.0.1 ebgp-multihop '2' set protocols bgp 65537 neighbor 192.168.0.1 remote-as '65536’ set protocols bgp 65537 neighbor 192.168.0.1 update-source ‘192.168.0.2 set protocols bgp 65537 network 2.0.0.0/16' set protocols bgp 65537 parameters router-id ‘192.168.0.2
Don’t forget, the CIDR declared in the network statement MUST exist in your routing table (dynamic or static), the best way to make sure that is true is creating a static route:
Node 1:
set protocols static route 1.0.0.0/16 blackhole distance '254'
Node 2:
set protocols static route 2.0.0.0/16 blackhole distance '254'
Resulting configuration:
Node 1:
bgp 65536 { neighbor 192.168.0.2 { ebgp-multihop 2 remote-as 65537 update-source 192.168.0.1 } network 1.0.0.0/16 { } parameters { router-id 192.168.0.1 } }
static { route 1.0.0.0/16 { blackhole { distance 254 } }
Node 2:
bgp 65537 { neighbor 192.168.0.1 { ebgp-multihop 2 remote-as 65536 update-source 192.168.0.2 } network 2.0.0.0/16 { } parameters { router-id 192.168.0.2 } }
static { route 2.0.0.0/16 { blackhole { distance 254 } }
Route Redistribution and Policy Engine
Firewall
NAT
Source NAT
Source NAT is typically referred to simply as NAT. To be more correct, what most people refer to as NAT is actually the process of Port Address Translation (PAT), or NAT Overload: The process of having many internal host systems communicate to the Internet using a single or subset of IP addresses.
To setup SNAT, we need to know:
- The internal IP addresses we want to translate
- The outgoing interface to perform the translation on
- The external IP address to translate to
In the example used for the Quick Start configuration above, we demonstrate the following configuration:
set nat source rule 100 outbound-interface 'eth0' set nat source rule 100 source address '192.168.0.0/24' set nat source rule 100 translation address 'masquerade'
Which generates the following configuration:
rule 100 { outbound-interface eth0 source { address 192.168.0.0/24 } translation { address masquerade } }
In this example, we use masquerade as the translation address instead of an IP address. The masquerade target is effectively an alias to say "use whatever IP address is on the outgoing interface", rather than a statically configured IP address. This is useful if you use DHCP for your outgoing interface and do not know what the external address will be.
When using NAT for a large number of host systems it recommended that a minimum of 1 IP address is used to NAT every 256 host systems. This is due to the limit of 65,000 port numbers available for unique translations and a reserving an average of 200-300 sessions per host system.
Example: For an ~ 8,000 host network a source NAT pool of 32 IP addresses is recommended.
A pool of addresses can be defined by using a - in the set nat source rule [n] translation address statement.
set nat source rule 100 translation address '203.0.113.32-203.0.113.63'
Note: Avoiding NAT breakage in the absence of split-DNS
A typical problem with using NAT and hosting public servers is the ability for internal systems to reach an internal server using it's external IP address. The solution to this is usually the use of split-DNS to correctly point host systems to the internal address when requests are made internally. Because many smaller networks lack DNS infrastructure, a work-around is commonly deployed to facilitate the traffic by NATing the request from internal hosts to the source address of the internal interface on the firewall. This technique is commonly reffered to as NAT Reflection, or Hairpin NAT.
In this example, we will be using the example Quick Start configuration above as a starting point.
To setup a NAT reflection rule, we need to create a rule to NAT connections from the internal network to the same internal network to use the source address of the internal interface.
set nat source rule 110 description 'NAT Reflection: INSIDE' set nat source rule 110 destination address '192.168.0.0/24' set nat source rule 110 outbound-interface 'eth1' set nat source rule 110 source address '192.168.0.0/24' set nat source rule 110 translation address 'masquerade'
Which results in a configuration of:
rule 110 { description "NAT Reflection: INSIDE" destination { address 192.168.0.0/24 } outbound-interface eth1 source { address 192.168.0.0/24 } translation { address masquerade } }
Destination NAT
DNAT is typically referred to as a Port Forward. When using VyOS as a NAT router and firewall, a common configuration task is to redirect incoming traffic to a system behind the firewall.
In this example, we will be using the example Quick Start configuration above as a starting point.
To setup a destination NAT rule we need to gather:
- The interface traffic will be coming in on
- The protocol and port we wish to forward
- The IP address of the internal system we wish to forward traffic to
In our example, we will be forwarding web server traffic to an internal web server on 192.168.0.100.
HTTP traffic makes use of the TCP protocol on port 80.
For other common port numbers, see: [1]
Our configuration commands would be:
set nat destination rule 10 description 'Port Forward: HTTP to 192.168.0.100' set nat destination rule 10 destination port '80' set nat destination rule 10 inbound-interface 'eth0' set nat destination rule 10 protocol 'tcp' set nat destination rule 10 translation address '192.168.0.100'
Which would generate the following NAT destination configuration:
nat { destination { rule 10 { description "Port Forward: HTTP to 192.168.0.100" destination { port 80 } inbound-interface eth0 protocol tcp translation { address 192.168.0.100 } } } }
Note that if forwarding traffic to a different port than it is arriving on, you may also configure the translation port using set nat destination rule [n] translation port.
This establishes our Port Forward rule, but if we created a firewall policy it will likely block the traffic.
It is important to note that when creating firewall rules that the DNAT translation occurs before traffic traverses the firewall. In other words, the destination address has already been translated to 192.168.0.100.
So in our firewall policy, we want to allow traffic coming in on the outside interface, destined for TCP port 80 and the IP address of 192.168.0.100.
set firewall name OUTSIDE-IN rule 20 action 'accept' set firewall name OUTSIDE-IN rule 20 destination address '192.168.0.100' set firewall name OUTSIDE-IN rule 20 destination port '80' set firewall name OUTSIDE-IN rule 20 protocol 'tcp' set firewall name OUTSIDE-IN rule 20 state new 'enable'
This would generate the following configuration:
rule 20 { action accept destination { address 192.168.0.100 port 80 } protocol tcp state { new enable } }
Another term often used for DNAT is 1-to-1 NAT.
For a 1-to-1 NAT configuration, both DNAT and SNAT are used to NAT all traffic from an external IP address to an internal IP address and vice-versa.
Typically, a 1-to-1 NAT rule omits the destination port (all ports) and replaces the protocol with either all or ip.
Then a corresponding SNAT rule is created to NAT outgoing traffic for the internal IP to a reserved external IP. This dedicates an external IP address to an internal IP address and is useful for protocols which don't have the notion of ports, such as GRE.
VPN
Example for configuring a simple L2TP over IPsec VPN for remote access (works with native Windows and Mac VPN clients):
set vpn ipsec ipsec-interfaces interface eth0 set vpn ipsec nat-traversal enable set vpn ipsec nat-networks allowed-network 0.0.0.0/0 set vpn l2tp remote-access outside-address 203.0.113.2 set vpn l2tp remote-access client-ip-pool start 192.168.255.1 set vpn l2tp remote-access client-ip-pool stop 192.168.255.255 set vpn l2tp remote-access ipsec-settings authentication mode pre-shared-secret set vpn l2tp remote-access ipsec-settings authentication pre-shared-secret <secret> set vpn l2tp remote-access authentication mode local set vpn l2tp remote-access authentication local-users username <username> password <password>
In the example above an external IP of 203.0.113.2 is assumed.
If a local firewall policy is in place on your external interface you will need to open:
- UDP port 500 (IKE)
- IP protocol number 50 (ESP)
- UDP port 1701 for IPsec
In addition when NAT is detected by the VPN client ESP is encapsulated in UDP for NAT-traversal:
- UDP port 4500 (NAT-T)
Example:
set firewall name OUTSIDE-LOCAL rule 40 action 'accept' set firewall name OUTSIDE-LOCAL rule 40 protocol 'esp' set firewall name OUTSIDE-LOCAL rule 41 action 'accept' set firewall name OUTSIDE-LOCAL rule 41 destination port '500' set firewall name OUTSIDE-LOCAL rule 41 protocol 'udp' set firewall name OUTSIDE-LOCAL rule 42 action 'accept' set firewall name OUTSIDE-LOCAL rule 42 destination port '4500' set firewall name OUTSIDE-LOCAL rule 42 protocol 'udp' set firewall name OUTSIDE-LOCAL rule 43 action 'accept' set firewall name OUTSIDE-LOCAL rule 43 destination port '1701' set firewall name OUTSIDE-LOCAL rule 43 ipsec 'match-ipsec' set firewall name OUTSIDE-LOCAL rule 43 protocol 'udp'
Also note that if you wish to allow the VPN to be used for external access you will need to add the appropriate source NAT rules to your configuration.
set nat source rule 110 outbound-interface 'eth0' set nat source rule 110 source address '192.168.255.0/24' set nat source rule 110 translation address masquerade
Established sessions can be viewed using the show vpn remote-access operational command.
[email protected]:~$ show vpn remote-access Active remote access VPN sessions: User Proto Iface Tunnel IP TX byte RX byte Time ---- ----- ----- --------- ------- ------- ---- vyos L2TP l2tp0 192.168.255.1 3.2K 8.0K 00h06m13s
Traffic Policy
The traffic policy subsystem provides an interface to Linux traffic control.
One common use of traffic policy is to limit bandwidth for an interface. In the example below we limit bandwidth for our LAN connection to 200M download and out WAN connection to 50M upload:
set traffic-policy shaper WAN-OUT bandwidth '50Mbit' set traffic-policy shaper WAN-OUT default bandwidth '50%' set traffic-policy shaper WAN-OUT default ceiling '100%' set traffic-policy shaper WAN-OUT default queue-type 'fair-queue' set traffic-policy shaper LAN-OUT bandwidth '200Mbit' set traffic-policy shaper LAN-OUT default bandwidth '50%' set traffic-policy shaper LAN-OUT default ceiling '100%' set traffic-policy shaper LAN-OUT default queue-type 'fair-queue'
Resulting in the following configuration:
traffic-policy { shaper WAN-OUT { bandwidth 50Mbit default { bandwidth 50% ceiling 100% queue-type fair-queue } } shaper LAN-OUT { bandwidth 200Mbit default { bandwidth 50% ceiling 100% queue-type fair-queue } } }
Once defined, a traffic policy can be applied to each interface using the interface-level traffic-policy directive:
set interfaces ethernet eth0 traffic-policy out 'WAN-OUT' set interfaces ethernet eth1 traffic-policy out 'LAN-OUT'
Note that a traffic policy can also be defined to match specific traffic flows using class statements.
DHCP Server
DHCP Relay
DNS Forwarder
System Configuration
System Users
VyOS supports two levels of users: admin and operator.
The operator level restricts a user to operational commands and prevents changes to system configuration. This is useful for gathering information about the state of the system (dhcp leases, vpn connections, routing tables, etc...) and for manipulating state of the system, such as resetting connections, clearing counters and bringing up and taking down connection oriented interfaces.
The admin level has all of the capabilities of the operator level, plus the ability to change system configuration. The admin level also enables a user to use the sudo command, which essentially means the user has root access to the system.
System Image Management
The VyOS image-based installation is implemented by creating a directory for each image on the storage device selected during the install process.
The directory structure of the boot device:
/ /boot /boot/grub /boot/VyOS_999.hydrogen.11291501
The image directory contains the system kernel, a compressed image of the root filesystem for the OS, and a directory for persistent storage, such as configuration.
On boot, the system will extract the OS image into memory and mount the appropriate live-rw sub-directories to provide persistent storage system configuration.
This process allows for a system to always boot to a known working state, as the OS image is fixed and non-persistent. It also allows for multiple releases of VyOS to be installed on the same storage device.
The image can be selected manually at boot if needed, but the system will otherwise boot the image configured to be the default.
The default boot image can be set using the set system image default-boot command in operational mode.
A list of available images can be shown using the show system image command in operational mode.
[email protected]:~$ show system image The system currently has the following image(s) installed: 1: 999.hydrogen.12130649 (default boot) (running image) 2: 999.hydrogen.12100644 [email protected]:~$
Images no longer needed can be removed using the delete system image command.
Finally, new system images can be added using the add system image command. The add image command will extract the image from the release ISO (either on the local filesystem or remotely if a URL is provided). The image install process will prompt you to use the current system configuration and SSH security keys, allowing for the new image to boot using the current configuration.
Note that configuration is associated to each image, and each image has a unique copy of its configuration. This is different than a traditional network router where the configuration is shared across all images.