|  | 
| 原帖kggzs在论坛发布 “在fnOS上安装 KVM 虚拟化,并使用Cockpit网页管理虚拟机”
 地址https://club.fnnas.com/forum.php?mod=viewthread&tid=781&highlight=
 
 该方式有一个问题,宿主机与虚拟机通过宿主机建立的网桥分享网络,配置方便但是FNOS无法识别宿主机网卡状态,会导致FNID无法使用,手机APP无法使用
 
 如果你机器有两张网卡建议一张配置桥接,共享网络给虚拟机,另外一张给FNOS系统识别,正确获取FNID
 
 如果只有1张网卡,可以参考本文 通过nftables 配置网络转发规则 实现虚拟机网络连接。
 
 前面的步骤就不重复,参考原帖 地址https://club.fnnas.com/forum.php?mod=viewthread&tid=781&highlight=
 1.添加虚拟机网络网桥
 cockpit配置页面
 
 
  
 
 2.启用IP转发
 编辑/etc/sysctl.conf文件,启用IP转发。
 sudo vi /etc/sysctl.conf
 找到并取消注释以下行:
 net.ipv4.ip_forward=1保存并退出编辑器。
 然后应用更改:
 sudo sysctl -p
 3.配置 nftables 规则
 我这里本地就一张网卡 接口wol1 已经正常连接路由上网,需要增加虚拟网桥virbr0与物理接口wol1转发规则
 sudo vi /etc/nftables.conf
 
 复制代码table ip nat {
    chain prerouting {
        type nat hook prerouting priority -100; policy accept;
    }
    chain postrouting {
        type nat hook postrouting priority 100; policy accept;
        oifname "wlo1" masquerade
    }
}
table ip filter {
    chain forward {
        type filter hook forward priority 0; policy accept;
        iifname "virbr0" oifname "wlo1" accept
        iifname "wlo1" oifname "virbr0" accept
    }
}
重启nftables服务
 sudo systemctl restart nftables
 检查 nftables 规则是否正确加载:
 sudo nft list ruleset
 你应该能看到你定义的规则集
 4.虚拟机网络配置
 cockpit配置页面
 图太大就不放了
 接口类型选 bridge to lan
 源 选 virbr0
 型号选 e100e pci
 
 虚拟机参考虚拟网桥配置IP地址
 
 
 复制代码enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.161  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::c503:a269:eea4:ea24  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:2b:ca:95  txqueuelen 1000  (Ethernet)
        RX packets 2833  bytes 335004 (327.1 KiB)
        RX errors 162  **ped 0  overruns 0  frame 162
        TX packets 2199  bytes 301907 (294.8 KiB)
        TX errors 0  **ped 0 overruns 0  carrier 0  collisions 0
        device interrupt 22  memory 0xfe840000-fe860000
配置完成后虚拟机与宿主机网络全通,但是无法连接外网
 需要增加DNS配置 图形化界面或者nmcli命令都可以
 自此虚拟机网络配置结束
 
 复制代码ing 192.168.122.1
PING 192.168.122.1 (192.168.122.1) 56(84) bytes of data.
64 bytes from 192.168.122.1: icmp_seq=1 ttl=64 time=0.129 ms
64 bytes from 192.168.122.1: icmp_seq=2 ttl=64 time=0.703 ms
64 bytes from 192.168.122.1: icmp_seq=3 ttl=64 time=0.269 ms
64 bytes from 192.168.122.1: icmp_seq=4 ttl=64 time=0.421 ms
ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=63 time=1.59 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=63 time=2.25 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=63 time=2.26 ms
64 bytes from 192.168.0.1: icmp_seq=4 ttl=63 time=2.27 ms
ping www.baidu.com
PING www.a.shifen.com (180.101.50.188) 56(84) bytes of data.
64 bytes from 180.101.50.188 (180.101.50.188): icmp_seq=1 ttl=52 time=15.1 ms
64 bytes from 180.101.50.188 (180.101.50.188): icmp_seq=2 ttl=52 time=17.4 ms
64 bytes from 180.101.50.188 (180.101.50.188): icmp_seq=3 ttl=52 time=18.0 ms
64 bytes from 180.101.50.188 (180.101.50.188): icmp_seq=4 ttl=52 time=15.7 ms
ping 192.168.0.114
PING 192.168.0.114 (192.168.0.114) 56(84) bytes of data.
64 bytes from 192.168.0.114: icmp_seq=1 ttl=63 time=107 ms
64 bytes from 192.168.0.114: icmp_seq=2 ttl=63 time=9.10 ms
64 bytes from 192.168.0.114: icmp_seq=3 ttl=63 time=5.86 ms
64 bytes from 192.168.0.114: icmp_seq=4 ttl=63 time=46.5 ms
windows虚拟机一样的配置
 
 
 | 
 
 
 |