企业级开源路由系统VyOS-构建和使用

本文最后更新于 2024年4月10日 下午

介绍

VyOS是一个基于Linux的企业级路由器操作系统,被许多公司和个人用来驱动物理网络设备,如路由器和防火墙。它有一个统一的命令行界面来管理其所有的网络相关功能(和Juniper Junos操作很像)。VyOS使用Debian GNU/Linux作为其基础,并添加了FRR,一个强大的开源路由套件,以及开源的VPN技术OpenVPN和IPSec在内的多种工具来增强其功能。它非常适合用来虚拟化网络环境,经常被运用在云环境和大型数据中心。与商业产品相比,VyOS的一大优点是它完全免费,开源,并且拥有一个活跃的社区来贡献和维护。

官方:https://vyos.io

本文介绍了构建Vyos LTS版本的ISO、还有基础安装和使用。

网络系列文章:https://songxwn.com/categories/network/

特性

路由协议

BGP,EVPN-VxLAN, MPLS , L3VPN, RPKI, ISIS,OSPF (V2 & V3), Babel , RIP, RIPng, BFD, BFD Monitoring, Policy Based Routing (PBR), Multicast (MLD, IGMP proxy v2 & v3, PIM-SM), Failover routes.Segment Routing

支持网卡

Up to 100 Gbps interfaces, 802.1q VLAN, 802.1ad QinQ, 802.3ad and other bonding protocols, Software Bridging, Paravirtualized NIC (vmxnet3 & virtio), Virtual Ethernet(veth), Wireless (WiFi & CellularNetworks)

防火墙

Stateful Connection Tracking, Zone Based Firewall, GeoIP matching,Address/ports/network groups , interfaces / mac-address groups ,Domains groups, Firewall bridge and Flowtables.NAT Source and Destination NAT (One to-One, Many to-Many, One to many),Balancing, Masquerade, Network prefix Translation , NAT66

隧道

Wireguard ,OpenConnect ,OpenVPN(P2P, Client & Server), OpenVPN&DCO, GRE, IPIP, SIT, IP6IP6, L2TPv3, VXLAN, SSTP (ClientServer),GENEVE, PPPoE (Client &Server), IPoE Server.

应用服务

DNS Forwarding, Dynamic DNS, mDNS Repeater, DHCP Server and Relay, IPv6 Router Advertisements, NTP (Client & Server), LLDP (Client& Server), TFTP Server, Web Proxy Server) , Event Handler, LLDP,Integration IDS/IPS (Suricata), Reverse-proxy and load-balancer .

QoS

Traffic Shaping and Matching, Rate Limiting, Rate Control (TBF), Traffic Queues (Drop-Tail FIFO, Fair Queue (SFQ), FQ CoDel, Round Robin(DRR), Random Early Detection (RED/WRED))Management ;

监控管理

SSH, HTTP API, SNMP (V2 & V3), NetFlow, sFlow, Telegraf, Prometheus-client, Zabbix-agent, Syslog High Availability VRRP, WAN Load Balancing, Connection State Synchronization,Conntrack Synchronization, Virtual-server load-balancing Supported Automation

工具

Ansible, SaltStack, Cloud init, Terraform

Additional Features Intel QuickAssist Cryptographic Hardware Acceleration (QAT),TACACS+, RADIUS, DDoS Protection Integration with FastNetMon

介绍PDF:https://vyos.io/files/vyos-datasheet-v3.pdf

构建1.4稳定版ISO

官方为了盈利需求,是不提供稳定版的ISO和OVA的。

使用Debian 12 并安装Docker 搭建构建环境。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
apt install docker.io git -y
sudo apt-get install ca-certificates curl gnupg
# 安装环境所需包
docker pull vyos/vyos-build:sagitta
# 下载构建相关的1.4.x版本的容器镜像。
git clone -b sagitta --single-branch https://github.com/vyos/vyos-build
# 下载最新的源码
cd vyos-build
# 进入构建目录
docker run --rm -it --privileged -v $(pwd):/vyos -w /vyos vyos/vyos-build:sagitta bash
# 运行并进入构建容器。
root@70cec64467db:/vyos# VYOS_VERSION="1.4.0-epa2"
# 配置构建的指定版本,此为最新的LTS版本
root@70cec64467db:/vyos# ./build-vyos-image iso --architecture amd64 --build-type release --version $

# 开始构建ISO

root@70cec64467db:/vyos# exit

# 退出容器

# find . -name *.iso

# 查找ISO路径,名字应该是vyos-1.4.0-epa2-amd64.iso

1.4.0-epa2 是一个1.4 LTS的版本号,这种版本号可以去官方博客查找。

生成好的ISO下载

https://github.com/Songxwn/build-vyos-lts/releases (分支于https://github.com/zengkid/build-vyos-lts

也可以自己用GitHub Actions 构建ISO。

将项目分支后,选择Actions > Workflows > Build Release > Run workflow

在The tag version you want to build 下添加指定版本的标签,如1.4.0-epa2。

然后执行Run workflow,等待半小时后,可以在你的分支项目的Releases 下载。

ISO安装指南

基础镜像为Debian 12,所以虚拟机兼容性也选择Debian 12。

物理机安装,推荐使用Rufus写入U盘。

启动ISO后登录安装账号,账号vyos,密码vyos。

然后输入install image ,一路选择 Y即可。

  1. 输入install image

  2. 询问是否继续安装到你的硬盘,输入 Y继续

  3. 询问是否是此版本,回车继续。

  4. 询问是否修改vyos账号密码,回车继续

  5. 询问console控制台显示方法,回车继续。(可选择COM输出)

  6. 询问选择的安装硬盘,确认后回车继续。

  7. 询问是否清理所选硬盘的所有数据,输入 Y继续。

  8. 询问是否安装系统到硬盘,输入Y继续。

  9. 询问是否使用硬盘全部空间,输入Y继续。

  10. 安装完成之后,输入reboot重启即可。

基础操作

登录并进入配置模式

进入系统后,输入默认账号vyos,默认密码vyos进行登录。然后就进入Linux 的 shell界面(操作模式)。

vyos的命令模式和Juniper很像。

文档:https://docs.vyos.io/en/sagitta/

CLI 基础

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
configure
# 操作切换到配置模式,退出输入exit。
set service ssh port 22
# 增加配置,开启ssh服务并指定监听端口。
delete service ssh port 22
# 删除配置
compare
# 查看未提交的配置更改。
commit-confirm 10
# 提交并配置自动回退,提交当前配置,但若10分钟内不执行confirm
commit
# 提交配置,vyos的配置并不是实时生效的,需要提交才能生效。
save
# 提交完成之后可以保存配置到硬盘。这点和juniper不一样。
rollback 1
# 回退到指定提交点的配置,但会重启系统。

查看配置和接口

1
2
3
4
5
6
7
8
9
10
11
12
show configuration
# 在操作模式
show configuration commands
# 在
show | commands
# 在配置模式下查看所有配置,指定以命令显示。
show interfaces | commands
# 在配置模式下查看接口,指定以命令显示。
show interface
# 在操作模式查看所有接口,也可以确认以太网接口名称。
run show interfaces
# 在配置模式执行操作模式命令

基础配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
set system host-name vy01
# 配置主机名
set system login user vyos authentication plaintext-password ABC@123123
# 配置vyos用户密码。
set service ssh port 22
# 增加配置,开启ssh服务并指定监听端口。
set interfaces ethernet eth0 address 1.1.1.1/24
# 为接口配置IP
set protocols static route 0.0.0.0/0 next-hop 1.1.1.2
# 配置静态路由
show ip route
# 查看当前路由表

set system name-server 176.9.37.132

# 配置系统自用的DNS服务器

OSPFv2配置

1
2
3
4
5
6
7
8
9
10
11
12
set interfaces ethernet eth0 address '10.0.0.1/24'
set interfaces ethernet eth1 ip ospf network point-to-point
# 配置接口地址、OSPF网络模式
set interfaces loopback lo address '192.168.0.1/32'
# 配置lookback0
set protocols ospf area 0.0.0.0 network '192.168.0.1/32'
set protocols ospf area 0.0.0.0 network '10.0.0.0/24'
# 宣告接口
set protocols ospf parameters router-id '192.168.0.1'
# 配置ospf的路由ID
set protocols ospf redistribute connected
# 重分布直连路由到OSPF

SNAT配置实例

1
2
3
4
5
6
7
8
9
10


set nat source rule 10 source address '192.168.1.0/24'
set nat source rule 10 outbound-interface name 'eth0'
set nat source rule 10 translation address 'masquerade'


#配置公网出口接口为eth0,配置基于接口的源NAT,配置下联地址段 192.168.1.0/24 会被源NAT。


DSNAT 端口映射

1
2
3
4
5
6
7
8


set nat destination rule 10 description 'Port Forward: HTTP to 192.168.1.100'
set nat destination rule 10 destination port '80'
set nat destination rule 10 inbound-interface 'eth1'
set nat destination rule 10 protocol 'tcp'
set nat destination rule 10 translation address '192.168.1.100'

升级或降级系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

add system image /root/vyos.1.5.iso

# 增加新的启动镜像并配置为默认

show system image

# 查看当前启动镜像和默认启动镜像

show version

# 查看版本

set system image default-boot 1.4.0-epa2

# 设置下次启动镜像

reboot

# 重启

时区和NTP配置

1
2
3
4
5
6
7
8

set system time-zone Asia/Shanghai

set service ntp server ntp.aliyun.com


date

SNMPv2 配置

1
2
3
4
5
6
7
8
9
set service snmp community songxwn.com authorization ro

# 配置团体名,并配置为只读权限

set service snmp community songxwn.com network 192.0.2.0/24

# 配置访问IP访问。


VLAN三层子接口

1
2
3
4
5

set interfaces ethernet eth0 vif 10 address 192.0.2.1/24
set interfaces ethernet eth0 vif 10 address 2001:db8::1/64
set interfaces ethernet eth0 vif 10 address dhcp
set interfaces ethernet eth0 vif 10 address dhcpv6

VRF 简单配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

set vrf name songxwn.com table 100

set interfaces ethernet eth0 vif 10


BGP: set vrf name <name> protocols bgp ...

IS-IS: set vrf name <name> protocols isis ...

OSPF: set vrf name <name> protocols ospf ...

OSPFv3 (IPv6): set vrf name <name> protocols ospfv3 ...

Static: set vrf name <name> protocols static ...

接口流量查看

monitor bandwidth interface eth0

BGP 配置

1
2
3
4
5
6
7
8


set protocols bgp neighbor 172.18.221.2 address-family ipv4-unicast
set protocols bgp neighbor 172.18.221.2 remote-as 100
set protocols bgp neighbor 172.18.221.2 update-source '172.18.221.1'
set protocols bgp system-as '1456'


参考:https://support.vyos.io/support/solutions/articles/103000096333-nat-principles

参考文档:

https://docs.vyos.io/en/latest/contributing/build-vyos.html (构建)

操作文档

https://docs.vyos.io/en/sagitta/

性能表现

可接收全网90+W条公网BGP路由。

show ip route  summary


企业级开源路由系统VyOS-构建和使用
https://songxwn.com/Vyos/
作者
Song
发布于
2024年4月7日
更新于
2024年4月10日
许可协议