因为我家里有一台服务器,所以打算利用闲置资源开 VPS 进行出租。考虑到安全问题,我需要禁止虚拟机访问物理机所在的网段,同时还需要禁止虚拟机之间互相访问,防止一台虚拟机中毒感染其他虚拟机。
简略网络架构图

- 虚拟机网段:192.168.122.xxx
- 物理机网段:192.168.3.xxx
目前有以下需求:
- 虚拟机之间不允许互相访问
- 虚拟机可以访问 192.168.122.1 网关
- 虚拟机不允许访问 192.168.3.xxx 网段,192.168.3.181 除外。
我尝试过 Libvirt 自带的 nwfilter 功能,我用了下面这个配置,但是会导致虚拟机不能上网
<filter name='deny-lan' chain='ipv4' priority='-700'>
<uuid>fce8ae34-e69e-83bf-262e-30786c1f8079</uuid>
<rule action='drop' direction='inout' priority='205'>
<ip dstipaddr='192.168.122.0' dstipmask='24'/>
</rule>
<rule action='accept' direction='inout' priority='204'>
<ip dstipaddr='192.168.122.1' dstipmask='32'/>
</rule>
<rule action='drop' direction='inout' priority='205'>
<ip dstipaddr='192.168.3.0' dstipmask='24'/>
</rule>
<rule action='accept' direction='inout' priority='204'>
<ip dstipaddr='192.168.3.181' dstipmask='32'/>
</rule>
</filter>
具体我是参考这篇文章的: https://www.so-cools.com/?p=1087
搞了很久也没搞定这个问题,只能来求助万能的 V2EX 了……
可以用 iptables 或者其他东西,只要能实现上面三个需求就行,付费也可以(