VyOS 网络操作系统部署教程
VyOS 是一款基于 Debian GNU/Linux 的开源网络操作系统,提供企业级的路由和防火墙功能。它使用类似 Juniper JunOS 的命令行配置界面,支持 BGP、OSPF、IS-IS 等路由协议。VyOS 既可以安装在物理硬件上作为软路由使用,也可以部署在虚拟机或 VPS 中。本文介绍如何在搬瓦工 VPS 环境中安装和配置 VyOS。
一、VyOS 版本说明
- Rolling Release:社区版,持续更新,免费下载 ISO 镜像。
- LTS(Long Term Support):商业版,提供长期支持和稳定更新,需要订阅许可。
本文使用社区版的 Rolling Release 进行演示。
二、安装 VyOS
2.1 下载镜像
# 从官方仓库下载 Rolling Release
wget https://github.com/vyos/vyos-rolling-nightly-builds/releases/download/1.5-rolling-202603280217/vyos-1.5-rolling-202603280217-amd64.iso
2.2 安装到磁盘
从 ISO 镜像启动后,使用默认用户 vyos 密码 vyos 登录,然后执行安装命令:
install image
安装向导会引导你完成磁盘分区、系统镜像复制和初始配置。
三、基本网络配置
# 进入配置模式
configure
# 配置接口 IP 地址
set interfaces ethernet eth0 address '10.0.0.2/24'
set interfaces ethernet eth1 address '192.168.1.1/24'
# 配置默认路由
set protocols static route 0.0.0.0/0 next-hop '10.0.0.1'
# 配置 DNS
set system name-server '8.8.8.8'
set system name-server '1.1.1.1'
# 设置主机名
set system host-name 'vyos-router'
# 提交并保存
commit
save
四、防火墙配置
# 创建防火墙规则集
set firewall ipv4 name WAN-LOCAL default-action 'drop'
set firewall ipv4 name WAN-LOCAL rule 10 action 'accept'
set firewall ipv4 name WAN-LOCAL rule 10 state established
set firewall ipv4 name WAN-LOCAL rule 10 state related
set firewall ipv4 name WAN-LOCAL rule 20 action 'accept'
set firewall ipv4 name WAN-LOCAL rule 20 protocol 'icmp'
set firewall ipv4 name WAN-LOCAL rule 30 action 'accept'
set firewall ipv4 name WAN-LOCAL rule 30 destination port '22'
set firewall ipv4 name WAN-LOCAL rule 30 protocol 'tcp'
# 应用到接口
set firewall interface eth0 in ipv4 name 'WAN-LOCAL'
commit
save
五、NAT 配置
# 配置源 NAT(SNAT)
set nat source rule 100 outbound-interface name 'eth0'
set nat source rule 100 source address '192.168.1.0/24'
set nat source rule 100 translation address 'masquerade'
# 配置目的 NAT(端口转发)
set nat destination rule 10 destination port '8080'
set nat destination rule 10 inbound-interface name 'eth0'
set nat destination rule 10 protocol 'tcp'
set nat destination rule 10 translation address '192.168.1.100'
set nat destination rule 10 translation port '80'
commit
save
六、路由协议配置
6.1 OSPF 配置
set protocols ospf area 0 network '10.0.0.0/24'
set protocols ospf area 0 network '192.168.1.0/24'
set protocols ospf parameters router-id '10.0.0.2'
commit
6.2 BGP 配置
set protocols bgp system-as '65001'
set protocols bgp neighbor 10.0.0.1 remote-as '65000'
set protocols bgp neighbor 10.0.0.1 address-family ipv4-unicast
set protocols bgp address-family ipv4-unicast network '192.168.1.0/24'
commit
七、DHCP 服务
set service dhcp-server shared-network-name LAN subnet 192.168.1.0/24 range 0 start '192.168.1.100'
set service dhcp-server shared-network-name LAN subnet 192.168.1.0/24 range 0 stop '192.168.1.200'
set service dhcp-server shared-network-name LAN subnet 192.168.1.0/24 default-router '192.168.1.1'
set service dhcp-server shared-network-name LAN subnet 192.168.1.0/24 dns-server '8.8.8.8'
commit
save
九、系统维护
# 查看系统信息
show version
show interfaces
show ip route
# 备份配置
save /config/backup-config.boot
# 比较配置差异
compare
总结
VyOS 是功能最全面的开源网络操作系统之一,其 JunOS 风格的命令行和丰富的协议支持使其成为学习和部署企业网络的理想选择。配合 GNS3 可以搭建复杂的网络实验环境。选购搬瓦工 VPS 请参考 全部方案,购买时使用优惠码 NODESEEK2026 可享受 6.77% 的优惠,通过 bwh81.net 进入官网购买。