vyos有两个网卡,分别是eth0和eth1,IP分别是10.1.1.175和10.222.222.1(掩码都是/24),分别用于连接外网和内网。
需求:配置nat,使内网客户端可以上网。
配置前网关可达,公网不可达。
![](https://danteng.org/wp-content/uploads/2020/05/1588988730230.png)
设置nat出接口
set nat source rule 100 outbound-interface eth0
设置要nat的网段
set nat source rule 100 source address 10.222.222.0/24
设置masquerade方式进行转换,这种方式将会在出接口随机选择一个IP地址进行转换
set nat source rule 100 translation address masquerade
提交并保存
commit
save
配置后公网可达
![](https://danteng.org/wp-content/uploads/2020/05/1588988730238.png)
如需转换成某个固定出口IP,可用下列指令
set nat source rule 100 translation address 10.1.1.175
如需转换成某个固定出口IP段,可用下列指令,这种方式适合具有多个出口IP且内网有大量主机时使用
set nat source rule 100 translation address 10.1.1.5-10.1.1.55
如需地址段转换,可用下列指令,这种方法需要指定空闲的地址段,不能含有接口IP等已经使用的地址
set nat source rule 100 translation address 10.1.2.0/24